[antlr-interest] BUG: Initialization for 3 levels of import
George S. Cowan
cowang at comcast.net
Mon Feb 16 06:47:25 PST 2009
First, I want to thank you again for ANTLR. I can't imagine going back to
hand-coding or using other parser generators. Unfortunately, I have found
another bug in the composite grammar code.
I modified the final example at
http://www.antlr.org/wiki/display/ANTLR3/Composite+Grammars slightly to add
an additional level of grammar import. The generated CParser.java does not
initialize the delegate for the lowest level correctly.
--------- Grammar and Lexer files ------------
lexer grammar L ;
LETTER : 'a'..'z' ;
SPACE : ' ' ;
----------------------------------------------
parser grammar P0 ;
letter : LETTER ;
----------------------------------------------
parser grammar P1 ;
import P0 ;
// letter : LETTER ;
spaces : SPACE+ ;
----------------------------------------------
parser grammar P2 ;
import P1 ;
letters : letter+ ;
----------------------------------------------
grammar C ;
import L, P2 ;
stuff : ( letters spaces )+ ;
LETTER: 'a'..'z' | 'A'..'Z' ;
------- End of Grammar and Lexer files -------
Here is the delegation code generated for the CParser.java. Note that in the
CParser constructor gP0 and gP1 are initialized in the wrong order. If those
last two lines are swapped, my tests work fine.
--------------- CParser.java -----------------
// delegates
public C_P2_P1_P0 gP0;
public C_P2_P1 gP1;
public C_P2 gP2;
// delegators
public CParser(TokenStream input) {
this(input, new RecognizerSharedState());
}
public CParser(TokenStream input, RecognizerSharedState state) {
super(input, state);
gP2 = new C_P2(input, state, this);
gP0 = gP1.gP0;
gP1 = gP2.gP1;
}
------- End extract from CParser.java --------
Regards,
George
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090216/4a19f57c/attachment.html
More information about the antlr-interest
mailing list