Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Not every programming language's grammar maps to an abstract syntax tree

Are there some examples of this?



Perl, this is because you can't actually properly parse Perl without also running Perl code at the same time.


That you can't properly parse Perl without also running Perl doesn't mean it doesn't have an AST. I don't know about Perl so it could very well be that it does not have an AST but your argument doesn't show it does not.


Perl code changes how the parsing will be done, both by adding keywords, changing how many arguments the parser will look for, and even arbitrarily changing the language entirely with a source filter. It's largely that last bit that makes creating a consistent or coherent AST so impractical it may as well be impossible.


The AST contains code, but it's still an AST. Every AST contains code. Perl has a dynamic lexer, but still uses a static YACC grammar.



PPI and PPR will parse most perl programs, but the moment you start doing stuff with prototypes or source filters they fail completely.


Forth. You could certainly define a formal grammar for it and construct an AST, but it would be trivial and not very useful.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: