[antlr-interest] AST rewrite problem

Grzegorz Cieslewski cieslewski at hcs.ufl.edu
Tue Feb 26 09:17:22 PST 2008


Hello,

I have been playing with the AST rewriting using the tree grammars.
I have encountered a problem where ANTLR change to AST without being
asked to do so.

My Grammar looks like this:

grammar T;
options {output=AST;}
tokens
{
	EXPR;
}
a	:	type b? INT -> ^(EXPR type b? INT)		
	;
	
b	:	ID
	;	
	
type	:	'int'
	|	'char';
	
ID : 'a'..'z'+ ;
INT : '0'..'9'+;
WS : (' '|'\n') {$channel=HIDDEN;} ;

And Tree Grammar:
tree grammar TP;
options {
	output=AST;
	ASTLabelType=CommonTree;
	tokenVocab=T;
	}
	
	
a	: ^(EXPR type? ID INT)
	;

type	:	'int'
	|	'char'
	;

For the input "int abc 123" parser generates the AST:
(EXPR int abc 123)
but after a pass with the tree parser the AST looks like this:
int (EXPR abc 123)

Does any one know the reason for this behaviour?  It seems like a bug to me.

Greg
-- 
=====================================================
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