[antlr-interest] Left-Recursion Removal Help

Kyle Robson kyledr at gmail.com
Tue Feb 23 17:30:59 PST 2010


Hi, I have been reading on the wiki, and I already fixed two of my
larger issues in my grammar (hopefully correctly). Now I've run into a
new set of rules that need fixing, and I would like to verify I'm
going about this correctly. I will take a guess, and can someone tell
me if it's correct?

The problem snippet:

timesExp: (timesExp | divExp | modExp | andExp | factor) '*' factor;
divExp : (timesExp | divExp | modExp | andExp | factor) 'div' factor;
modExp : (timesExp | divExp | modExp | andExp | factor) 'mod' factor;
andExp : (timesExp | divExp | modExp | andExp | factor) 'and' factor;
factor : '#'; // this rule is itself broken, but I will get to this
later, so I'm pretending it's something harmless

My guess is to change them like this, using timesExp as an example

timesExp: ((divExp | modExp | andExp | factor) '*' factor) ('*' factor)*

Is this correct?

Thanks in anticipation,

Kyle Robson


More information about the antlr-interest mailing list