[antlr-interest] Problem writing a Grammar

Johannes Luber jaluber at gmx.de
Fri May 4 05:41:35 PDT 2007


Johannes Luber wrote:
 > Left recursion means that the rule is in referenced in one of its
> productions at the left edge. Look at the following example:
> 
> constructor_modifiers
>    :   constructor_modifier
>    |   constructor_modifiers   constructor_modifier
>    ;
> 
> LL-Parsers like ANTLR end up in an infinite loop because of the way they
> recognize grammars. The solution is to change the grammar. For the example:
> 
> constructor_modifiers
>    :   constructor_modifier*
>    ;

Made a small mistake here. The rewritten rule should be

constructor_modifiers
   :   constructor_modifier+
   ;

Thanks, Micheal, for pointing it out. I actually copied the original
rule and rewrote it on the fly instead looking for my transcription in
the grammar file. The ironic thing is that I make that kind of mistake
every time I post something like that while I managed to avoid it in my
normal grammar file. Lesson learned: Reread grammar snippets. :)

Best regards,
Johannes Luber




More information about the antlr-interest mailing list