[antlr-interest] Expression grammar issues (typecasts, method calls)

John Barnette jbarnette at gmail.com
Sun Jul 24 17:42:09 PDT 2005


On 7/24/05, Nigel Sheridan-Smith <nbsherid at secsme.org.au> wrote:
> > There are two commented-out lines in the grammar, one in
> > unaryExpression and one in primaryExpression. Grep down for "typecast"
> > to find the first, and "func" to find the second. When either or both
> > of these lines are uncommented, parsing fails with an "unexpected
> > token: null" exception.

(snip)

> It looks to be your actions, although I can't say for sure without further
> testing.
> 
> Firstly, you probably don't need to use '#' in a normal parser, as this sort
> of thing is only needed for tree parsers, so you can remove these. Secondly,
> I'm not sure if you can do a setText() at this point. Try taking out the
> '#', and if that doesn't work, remove the actions temporarily to see if that
> makes any difference.

Thanks, Nigel. I've removed the actions, which seems to have at least
made the typecast statement work. However, I'm still getting an
unexpected token when I uncomment the line that should match function
calls. Here's a minimal testcase in Java that will reproduce the
error:

HippoParser parser = new HippoParser(new HippoLexer(new StringReader("foo")));
parser.expression();

I've placed a slightly-modified grammar (with the misbehaving line
uncommented) at: http://hippo.sourceforge.net/hippo.g. The issue is in
primaryExpression:

primaryExpression
	:	IDENTIFIER
	    (PAREN_LEFT^ argList PAREN_RIGHT!)?
	|	literal
	|	PAREN_LEFT^ expression PAREN_RIGHT!
	;

Any further advice, abuse, or general nattering is much appreciated. :)


~ j.


More information about the antlr-interest mailing list