mulderp / mulderp.github.com

blog
1 stars 0 forks source link

compilers, ast, #13

Open mulderp opened 8 years ago

mulderp commented 8 years ago

programs are based on interpretations of "abstract syntax tree" by computers.

that might give a good blog post incl references to:

James Halliday - What can you do with an AST? A whole lot Video for What can you do with an AST? A whole lot.▶ 18:52 https://www.youtube.com/watch?v=X8W2Le60up8

Most of the things you can do are terrible hacks but sometimes there is no other way. This talk will cover some ...

let's build a compiler:

http://compilers.iecc.com/crenshaw/

mulderp commented 8 years ago

https://github.com/benjamn/recast

mulderp commented 8 years ago

compilers are also translators from "high-level languages" to bits and bytes

mulderp commented 8 years ago

in python: https://github.com/jayconrod/gypsum - nice examples of using lexers, combinators, ast,

mulderp commented 8 years ago

in js, https://github.com/substack/node-falafel acorn ...

mulderp commented 8 years ago

translation of code is related to recursively walking the abstract syntax tree. in fact recursion happens on a very small scale for expressions for example, the total program is then "combined" results from smaller recursions.

mulderp commented 8 years ago

8cc compiler https://github.com/rui314/8cc and bflisp https://github.com/shinh/bflisp

mulderp commented 8 years ago

if compiler writing is about recursion, the correct syntax is a question where the recursion breaks.

embeddednodejs commented 7 years ago

http://c9x.me/compile/bib/

mulderp commented 7 years ago

some jison tricks:

%lex

%%

(\r\n|\n)+         { print('eol'); return 'EOL'; }
[ \t]+             { print('w'); /* skip whitespace */}
\#[^\r\n]*         { print('c'); /* skip comments */ }

/lex

%%

program
    : lines EOF { }
    ;

lines
    : /* empty */
    | lines lines
    ;

line
    : statement
    | EOL
    ;

statement
    : expr
    ;

expr
    : 1
    ;
mulderp commented 7 years ago

jison parsers from the browser with browserify transform: https://github.com/schmich/jisonify

mulderp commented 7 years ago

lexer question http://stackoverflow.com/questions/37550567/how-to-detect-new-line-in-jison

mulderp commented 7 years ago

arrays with jison http://stackoverflow.com/questions/28511760/making-arrays-in-jison

mulderp commented 7 years ago

floop.l https://gist.github.com/zaach/1659274

mulderp commented 7 years ago

18:26] <> And PEG. :) [18:26] <> it is so cool indeed, it goes you closer to understanding the magic of computers [18:27] <> program: statement | statement program <-- BNF/yacc flavor [18:27] <> program = statement* <-- PEG [18:27] <> ahh, ok [18:27] <> Some of the syntax is nice, too. [18:27] <> i have seen that star in grammars [18:27] <> Though you may find writing your first expression parser... odd. [18:27] <> i was wondering what tool they use

Yes, it's called a Kleene star. https://en.wikipedia.org/wiki/Kleene_star interesting, indeed, with the BNF i had problems scanning for the newlines when i had build a small block statement with inner newlines for example "The" source for all things PEG: http://bford.info/packrat/

Your first attempt may not be too nice, but your second one probably will be. :) http://boost-spirit.com/home/

ah, i found this http://stackoverflow.com/questions/13367545/flex-isnt-generating-the-yyflexlexer-h-header it is a system lib

mulderp commented 7 years ago

https://ruby-hacking-guide.github.io/yacc.html

mulderp commented 7 years ago

http://stackoverflow.com/questions/2644597/how-do-i-implement-if-statement-in-flex-bison https://github.com/rabishah/Mini-C-Compiler-using-Flex-And-Yacc/blob/master/c.y

mulderp commented 4 years ago

https://stackoverflow.com/questions/2245962/is-there-an-alternative-for-flex-bison-that-is-usable-on-8-bit-embedded-systems/2336769#2336769

mulderp commented 4 years ago

https://stackoverflow.com/questions/28530284/generate-an-ast-in-c