Reputation: 21062
I would like to set precedence rules (for example for math operators of multiplication and addition -- i.e. * and +) however in flat manner.
Take a look: http://www.gregbugaj.com/?p=251 (in short it solves above example by stating the expression is addition of mult-expressions).
This does the job at cost of very deep parse tree, because precedence is solved using nesting rules. I would like to have one ("flat") rule for parsing plus declaration of precedence (so, like it was solved in Yacc).
Question: how this (Yacc-like, i.e. flat one) approach can be achieved in ANTLR?
Upvotes: 1
Views: 258
Reputation: 170158
Question: how this (Yacc-like, i.e. flat one) approach can be achieved in ANTLR?
You can't.
If you let the parser create an AST, the "very deep parse tree" does not exist any more. See the following Q&A: How to output the AST built using ANTLR?
Upvotes: 1