[antlr-interest] Tree Rewriting problem - RewriteEmptyStreamException at runtime

Grzegorz Cieslewski cieslewski at hcs.ufl.edu
Tue Feb 5 07:49:06 PST 2008


I am using the 3.1b1 version of antlr so I could do some tree
rewriting.  I found a good set of examples in the
TestTreeGrammarRewriteAST.java file and decided to start
experimenting.  Unfortunately I have run in to a problem with my
program throwing an exception.
My Grammar is:
grammar T;
options {output=AST;}
tokens
{
	EXPR;
}
a : type ID INT -> ^(EXPR type ID INT);
type	:	'int'
	|	'char';
ID : 'a'..'z'+ ;
INT : '0'..'9'+;
WS : (' '|'\n') {$channel=HIDDEN;} ;

and the tree grammar:

tree grammar TP;
options {
	output=AST;
	ASTLabelType=CommonTree;
	tokenVocab=T;}
	
a	: ^(EXPR type ID INT) -> ^(EXPR type INT ID)
	;

type	:	'int'
	|	'char';

f
Everything compiles but I get following error during runtime (with
input "int abc 123"):

Exception in thread "main"
org.antlr.runtime.tree.RewriteEmptyStreamException: rule type
        at org.antlr.runtime.tree.RewriteRuleElementStream._next(RewriteRuleElementStream.java:158)
        at org.antlr.runtime.tree.RewriteRuleElementStream.nextTree(RewriteRuleElementStream.java:145)
        at simpleCrw.declaration(simpleCrw.java:182)
        at simpleCrw.file(simpleCrw.java:92)
        at Main2.main(Main2.java:41)

I have noticed that if I change the rule type in the tree grammar as
follows the problem does not occur:

tree grammar TP;
options {
	output=AST;
	ASTLabelType=CommonTree;
	tokenVocab=T;}
	
a	: ^(EXPR type ID INT) -> ^(EXPR type INT ID)
	;

type	:	'int';

I have tracked this a little further.  When I remove the rewrite rule
from the tree grammar :

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

type	:	'int'
	|	'char';

The output tree I get after the LexerParser is
EXPR
|-int
|-abc
|-123

but after the tree grammar I get the tree missing the int node
EXPR
|-abc
|-123

Does any one have any idea as to what is going on?

P.S. I attached my whole setup


-- 
=====================================================
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
=====================================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: treerw.tgz
Type: application/x-gzip
Size: 2321 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080205/b9a4a374/attachment.tgz 


More information about the antlr-interest mailing list