[antlr-interest] ClassCastException in TreeParser grammar

John B. Brodie jbb at acm.org
Tue May 25 06:27:20 PDT 2010


Hello :-

This grammar still has the same compilation problem as the one that you
posted yesterday..... did you change anything?

I fixed the STRING_LITERAL rule as you suggested in a private e-mail to
me (please keep all messages on this list).

I then did not get any ClassCastException. But got runtime complaints
from the tree walker that it got a VARIABLE token when expecting DOWN
(or maybe it was the other way around, can not remember)

Need to add a ^ to the VAR rule in the tree walker.

On Tue, 2010-05-25 at 10:44 +0400, Ламер wrote:
> Hi, can you help me to write Tree grammar.
> ClassCastException is thrown while my Test runs.
> Here is the code of Combined grammar and Tree grammar that doesn't work.

.....snipped......
> 
> STRING_LITERAL
> 	:	'"'
> 		{ StringBuilder b = new StringBuilder(); }
> 		(	c=~('"' | '\r' | '\n'/* | VARIABLE*/)	{ b.appendCodePoint(c); }
> 		)*
> 		'"'
> 		{ "\"" +setText(b.toString()) + "\""; }
changed to { setText("\" + b.toString() + "\""); }

btw why do you use StringBuilder here? ANTLR will accumulate the token's
text for you, is it some unicode thing?


.....snipped.....
> variable
> 	:	(VAR VARIABLE)
> 	;

variable : ^(VAR VARIABLE) ;




perhaps there is some problem with your test rig?
(attached please find the Main.java that I used to run your example from
the command line without any problems after applying the 2 fixes
above...)



More information about the antlr-interest mailing list