Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compilers, ast, #13

Open
mulderp opened this issue Feb 3, 2016 · 18 comments
Open

compilers, ast, #13

mulderp opened this issue Feb 3, 2016 · 18 comments

Comments

@mulderp
Copy link
Owner

mulderp commented Feb 3, 2016

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
Copy link
Owner Author

mulderp commented Feb 4, 2016

@mulderp
Copy link
Owner Author

mulderp commented Feb 8, 2016

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

@mulderp
Copy link
Owner Author

mulderp commented Feb 29, 2016

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

@mulderp
Copy link
Owner Author

mulderp commented Feb 29, 2016

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

@mulderp
Copy link
Owner Author

mulderp commented Feb 29, 2016

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
Copy link
Owner Author

mulderp commented Mar 1, 2016

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

@mulderp
Copy link
Owner Author

mulderp commented Mar 1, 2016

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

@embeddednodejs
Copy link

@mulderp
Copy link
Owner Author

mulderp commented Jul 28, 2016

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
Copy link
Owner Author

mulderp commented Aug 14, 2016

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

@mulderp
Copy link
Owner Author

mulderp commented Aug 15, 2016

@mulderp
Copy link
Owner Author

mulderp commented Aug 18, 2016

@mulderp
Copy link
Owner Author

mulderp commented Aug 18, 2016

@mulderp
Copy link
Owner Author

mulderp commented Aug 23, 2016

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
Copy link
Owner Author

mulderp commented Sep 6, 2016

@mulderp
Copy link
Owner Author

mulderp commented Jan 13, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant