[antlr-interest] ANTLR Grammar error - Illegal token.

John B. Brodie jbb at acm.org
Mon Aug 4 08:19:23 PDT 2008


Greetings!

rkevinburton asked:
>I am checking my grammar and getting the following errors:
>
>[09:11:21] error(100): ECMAScript.g:1530:2: syntax error: antlr: ECMAScript.g:1530:2: unexpected token: :
>[09:11:21] error(100): ECMAScript.g:1548:2: syntax error: antlr: ECMAScript.g:1548:2: unexpected token: :
>[09:11:21] error(100): ECMAScript.g:1555:5: syntax error: antlr: ECMAScript.g:1555:5: unexpected token: scope
>
>When I look at the lines indicated I don't see a problem. Moreover I
>don't see a reference to the token that is "unexpected". Would
>someone with more experience with ANTLR than me please look at the
>attached grammar and see if you can see what is wrong?
>
>...attachment snipped...

I have not actually tried processing your grammar with ANTLR.

But I see that at those three lines referenced in the above error
messages that you are using the phrase `(scope=STATIC)?` at the
beginning of those three rules.

So I believe your local variable reference of `scope` clashes with
ANTLR's notion of a dynamic scope, a mechanism for passing information
amongst rules (see chapt 6 of Dr. Parr's book, TDAR), which uses
`scope` as a reserved word to introduce a block of variable
declarations at the beginning of a rule (must appear before the rule's
`:`).

Try picking another name for your local variable.

Hope this helps...
   -jbb


More information about the antlr-interest mailing list