4 ms·
> Not every programming language's grammar maps to an abstract syntax tree Are there some examples of this?
by ffwacom 5y ago
> Not every programming language's grammar maps to an abstract syntax tree
Are there some examples of this?
- simcop2387 5y agoPerl, this is because you can't actually properly parse Perl without also running Perl code at the same time.
- justinator 5y agohttps://metacpan.org/pod/PPI https://metacpan.org/pod/PPI
- simcop2387 5y agoPPI and PPR will parse most perl programs, but the moment you start doing stuff with prototypes or source filters they fail completely.
- rowanG077 5y agoThat 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.
- simcop2387 5y agoPerl 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.
- rurban 5y agoThe 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.
- mumblemumble 5y agoForth. You could certainly define a formal grammar for it and construct an AST, but it would be trivial and not very useful.