[antlr-interest] rewrite rule like AST construction operator '^'

Trevor John Thompson tijet at mac.com
Sun Oct 24 02:35:59 PDT 2010


I have a language in which one expression may immediately follow another. I am trying to construct an AST with an imaginary node representing the "concatenation" operator. I want the moral equivalent of
expr: term (SP^ term)*;
except that SP does *not* actually appear in the token stream.
When i try
expr: term (term->(^SP $expr term))*;
i get RewriteEmptyStreamException in that rule on input like
a b c
Here is a tiny grammar that demonstrates the problem:
grammar Test;
options {output=AST;}
prog:	expr NL! EOF!;
expr:	term (term->^(SP $expr term))*;
term:	ID;
fragment
SP	:	' '|'\t';
ID	:	SP*
		('a'..'z'|'A'..'Z'|'_'|'\u0080'..'\uFFFE')
		('0'..'9'|'a'..'z'|'A'..'Z'|'_'|'\u0080'..'\uFFFE')*
	;
NL	:	('\r'|'\n')+;

I would appreciate anyone pointing out what i am doing wrong.
--
Trevor John Thompson    net: tijet at mac.com

Quidquid Latine dictum sit, altum videtur.



More information about the antlr-interest mailing list