[antlr-interest] Java Code Generation Problem with Tree Grammar	outputting AST
    Grzegorz Cieslewski 
    cieslewski at hcs.ufl.edu
       
    Thu Mar 20 12:24:02 PDT 2008
    
    
  
Hello,
I am currently using the antlr-2008-03-13.12 build and I have
encountered a following problem when building a tree rewriter.  It
might be related to the problem from other post but I am not sure of
that.  I constructed a grammar that demonstrates my problem
grammar T;
options {output=AST;}
tokens
{
	EXPR;
}
a	:	type ID INT -> ^(type ID INT)		
	;
		
type	:	'int'
	|	'char';
	
ID : 'a'..'z'+ ;
INT : '0'..'9'+;
WS : (' '|'\n') {$channel=HIDDEN;} ;
tree grammar TP;
options {
	output=AST;
	ASTLabelType=CommonTree;
	tokenVocab=T;
	}
	
	
a	: ^(type ID INT) -> ^(type ID INT)
	;
type	:	'int'
	|	'char'
	;
The tree grammar does not do anything except rewrite the tree in
exactly the same manner.
When I try to compile it I get the following errors:
TP.java:84: ']' expected
            stream_[TP.type,index=2,line=12].add(type1.getTree());
                           ^
TP.java:84: not a statement
            stream_[TP.type,index=2,line=12].add(type1.getTree());
                   ^
TP.java:84: ';' expected
            stream_[TP.type,index=2,line=12].add(type1.getTree());
                                   ^
TP.java:84: ';' expected
            stream_[TP.type,index=2,line=12].add(type1.getTree());
I traced it down to the following line:
stream_[TP.type,index=2,line=12].add(type1.getTree());
It seems that the "stream_[TP.type,index=2,line=12]" shuld be
"stream_type".  Upon performing that correction the grammar works
correctly.
It looks like a bug, could someone verify it.
Thanks,
-- 
=====================================================
Grzegorz Cieslewski
Research Assistant
High-performance Computing & Simulation (HCS) Research Laboratory
University of Florida, Dept. of Electrical and Computer Engineering
330 Benton Hall, Gainesville, FL, 32611-6200
Phone: (352) 392-9041
Email: cieslewski at hcs.ufl.edu
Web: www.hcs.ufl.edu
=====================================================
    
    
More information about the antlr-interest
mailing list