[antlr-interest] Expression grammar issues (typecasts,
method calls)
Nigel Sheridan-Smith
nbsherid at secsme.org.au
Sun Jul 24 16:37:07 PDT 2005
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of John Barnette
> Sent: Sunday, 24 July 2005 5:05 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Expression grammar issues (typecasts, method
> calls)
>
> Hi all,
>
> I'm a brand-new ANTLR user, and I'm still learning the ropes. I've
> been working on a grammar for the expression portion of a scripting
> language, and I'm having some issues supporting typecasts and method
> calls that are driving me slowly insane. I'm certain that they're just
> due to my unfamiliarity with ANTLR, and I'd very much appreciate any
> help.
>
> I didn't want to include the grammar inline and spam everyone, so if
> you're interested in helping bail me out you can find it at
> http://hippo.sourceforge.net/hippo.g
>
> It's only the skeletal expression evaluator at this point, with very
> little tree work done except for a few minor changes to make the
> output of ast.toStringTree() a bit more helpful to me. The expression
> parser is based on the Java 1.5 parser available on antlr.org.
>
> Oh, and if it's at all useful, my implementation language is Java.
>
> 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.
>
> As I said, I'm very new to ANTLR and feeling pretty lost. I assume
> that my problems stem from the fact that both the typecast and the
> function call specs use parenthesis, as do expressions, but I have no
> idea what the real issue is. Any suggestions, whether for these
> specific lines or for basic problems with the expression grammar,
> would be much appreciated.
>
> Thanks!
>
Hi,
It looks to be your actions, although I can't say for sure without further
testing.
unaryExpression
: INC^ unaryExpression
| DEC^ unaryExpression
| BITWISE_NOT^ unaryExpression
| LOGICAL_NOT^ unaryExpression
//| pl:PAREN_LEFT^ builtInType PAREN_RIGHT! unaryExpression
{#pl.setText("typecast");}
| postfixExpression
;
These actions are spread around in a few places; I'm guessing you have just
started adding them in.
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.
Cheers,
Nigel
--
Nigel Sheridan-Smith
PhD research student
Faculty of Engineering
University of Technology, Sydney
Phone: 02 9514 7946
Fax: 02 9514 2435
More information about the antlr-interest
mailing list