[antlr-interest] AST construction problem??

Fan Yang yhhf_dy at yahoo.com
Fri Aug 1 12:34:34 PDT 2003


In order to be familiar with AST construction, I did some small tests 
by usning ANTLR 2.7.2. I realized that ANTLR 2.7.2 can't generate code
(in CPP or Java) correctly, but ANTLR 2.7.1 can. I don't know if I do 
it in a wrong way or ANTLR 2.7.2 has a bug. Would you please point me 
the problem. thanks.

Here is the problem, I modified grammar of exprAST which exists 
in "examples" directory of ANTLR. I use manual tree construction for 
the rule instead of automatic one.

options {

//original one
//expr : 
//	assignExpr EOF! 
//     ; 

expr! : 
	assignExpr EOF! 
	{#expr = #(assignExpr, EOF);}

When I'm trying to comile the generated codes, compiler generate the 
following error:
ExprParser.cpp(55) : error C2065: 'tmp1_AST' : undeclared identifier

after read the generated code and compared with code generated by 
antlr2.7.1, I realized that there are missing line 2 and 3 in the 
code which is generated by antlr2.7.2, temp1_AST is the node to 
represent EOF.  

//snip c++ code generated by antlr2.7.1
1: assignExpr();
3: tmp1_AST = astFactory.create(LT(1));
4: match(ANTLR_USE_NAMESPACE(antlr)Token::EOF_TYPE);


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list