[antlr-interest] Overriding rule in imported parser grammar generates a faulty java code with undefined method
Berger, Michael
michael.berger at fokus.fraunhofer.de
Thu Apr 22 06:32:01 PDT 2010
Title:
Overriding rule in imported parser grammar generates a faulty java code
with undefined method
Description:
Simple extended example from the article about the import introduction:
A parser 1 defines a rule that will be override by parser 2 importing
parser 1.
The combined grammar imports the parser 2.
Software:
antlrworks-1.3.1.jar
-------
lexer grammar lex;
IntString : 'int' ;
FloatString : 'float' ;
Semicolon : ';' ;
Equal : '=' ;
ID : 'a'..'z'+ ;
INT : '0'..'9'+ ;
WS : (' '|'\n')+ {skip();} ;
--------
parser grammar par1;
type : IntString ;
decl : type ID Semicolon | type ID init Semicolon ;
init : Equal INT ;
---------
parser grammar par2;
import par1;
prog : decl ;
type : IntString | FloatString ; //override from p1
---------
grammar gram;
import lex, par2;
start : decl | init;
--------
Generated java code (snipped):
public class gramParser extends Parser {
(...)
// delegates
public gram_par2_par1 gpar1;
public gram_par2 gpar2;
// delegators
(...)
// Delegated rules
public void decl() throws RecognitionException { gpar1.decl(); }
public void type() throws RecognitionException { gpar1.type(); } (*)
public void init() throws RecognitionException { gpar1.init(); }
public void prog() throws RecognitionException { gpar2.prog(); }
(...)
}
The part (*) produces the error line:
D:\local\mib\Compiler\de.fraunhofer.fokus.ttcn3.compiler\grammar\gramPar
ser.java:151: cannot find symbol
symbol : method type()
location: class gram_par2_par1
public void type() throws RecognitionException { gpar1.type(); }
Best regards,
Michael Berger
Fraunhofer FOKUS
Kaiserin-Augusta-Allee 31
10589 Berlin
Tel: +49-30-3463-7176
More information about the antlr-interest
mailing list