[antlr-interest] unexpected token @
David Holroyd
dave at badgers-in-foil.co.uk
Wed Dec 5 12:55:50 PST 2007
On Wed, Dec 05, 2007 at 02:46:29PM -0600, Mark Volkmann wrote:
> The tree grammar rule below causes the error "syntax error: antlr:
> MathTree.g:42:1: unexpected token: @", but I don't understand why.
> Polynomial is a Java class in the same package of the classes
> generated from the grammar.
> Do you see anything syntactically wrong with this?
>
> polynomial returns [Polynomial result]
> @scope {
> Polynomial currentPolynomial;
> }
> : ^(POLYNOMIAL term*) {
> $result = currentPolynomial = new Polynomial();
> }
> ;
scope doesn't take an '@' prefix, as far as I remember.
Maybe you want something like,
polynomial returns [Polynomial result]
: ^(POLYNOMIAL term*) {
$result = MyScope::currentPolynomial = new Polynomial();
}
;
with
scope {
Polynomial currentPolynomial;
}
defined at the top of your grammar?
you need to add a,
myrule
scope MyScope;
: ...
;
to a rule if you want to push a new 'scope frame' into the 'scope
stack', or something like that.
helps?
dave
--
http://david.holroyd.me.uk/
More information about the antlr-interest
mailing list