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

John Barnette jbarnette at gmail.com
Sat Jul 23 12:04:38 PDT 2005


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!


~ j.


More information about the antlr-interest mailing list