Using ANTLR with Left-Recursive Rules

Posted by CNevin561 on Stack Overflow See other posts from Stack Overflow or by CNevin561
Published on 2011-11-24T01:45:11Z Indexed on 2011/11/24 1:51 UTC
Read the original article Hit count: 148

Filed under:
|
|

Basically Ive written a Parse for a language with just basic arithmetic operators ( +, -, * / ) etc, but for the minus and plus cases, the Abstract Syntax Tree which is generated has parsed them as right associative when they need to be left associative. Having a googled for a solution, i found a tutorial that suggests rewriting the rule from: Expression ::= Expression <operator> Term | Term as Expression ::= Term <operator> Expression*. However in my head this seems to generate the tree the wrong way round. Any pointers on a way to resolve this issue?

© Stack Overflow or respective owner

Related posts about recursion

Related posts about antlr