[antlr-interest] ANTLRWorks bug: Remove Left Recursion with comments in grammar

The Researcher researcher0x00 at gmail.com
Mon Sep 26 10:51:48 PDT 2011


grammar Ambiguious001;



string      : string Plus string

            | string Minus string

            | Digit

            ;



Digit       : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;

Minus       : '-' ;

Plus        : '+' ;



Remove All Left Recursion or Remove Left Recursion produces

grammar Ambiguious001;



string      : (Digit) (Plus string | Minus string)*

            ;



Digit       : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;

Minus       : '-' ;

Plus        : '+' ;



However

grammar Ambiguious001;



// Parser



string      : string Plus string

            | string Minus string

            | Digit

            ;



// Lexer



Digit       : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;

Minus       : '-' ;

Plus        : '+' ;



Remove All Left Recursion or Remove Left Recursion produces



grammar Ambiguious001;



// Parser



string      : (Digit

            ;) (Plus string | Minus string)*



// Lexer



Digit       : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;

Minus       : '-' ;

Plus        : '+' ;

  It's the first time I have ever had an error wink at me.

Eric


More information about the antlr-interest mailing list