[antlr-interest] Fwd: ANTLRWorks bug: Remove Left Recursion with comments in grammar
The Researcher
researcher0x00 at gmail.com
Mon Sep 26 11:05:33 PDT 2011
I forgot to give credit where credit is due.
This grammar is from
Aho, A. V., Lam, M. S., Sethi, R., & Ullman, J. D. (2007) Compilers:
principles, techniques, & tools (2nd ed.). Boston: Pearson/Addison Wesley.
pg. 47, Example 2.5
---------- Forwarded message ----------
From: The Researcher <researcher0x00 at gmail.com>
Date: Mon, Sep 26, 2011 at 1:51 PM
Subject: ANTLRWorks bug: Remove Left Recursion with comments in grammar
To: antlr-interest at antlr.org
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