1

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?

greenoldman
  • 16,895
  • 26
  • 119
  • 185

1 Answers1

1

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?

Community
  • 1
  • 1
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
  • Thank you for the answer, but about my needs I am better informed ;-) I need it because it let me express grammar in more compact way, second when visualizing the grammar trees it is also more compact -- and thus more readable. In design stage it is important (for me). – greenoldman Jul 23 '12 at 15:32
  • @macias, *"but about my needs I am better informed"*, that's true! :) – Bart Kiers Jul 23 '12 at 17:55