[antlr-interest] Weird (to me) grammar problem
Evan Driscoll
driscoll at cs.wisc.edu
Wed Dec 2 00:30:15 PST 2009
I just started work on a grammar to read well, context free grammars,
and am running into a problem. (I'm probably just doing something dumb.)
I've attached my grammar.
The ARROW token (used between the left and right sides of a production)
should recognize either ':' or '->', but the AntlrWorks interpreter only
accepts '->'. If I try to parse the input 'a -> b;', I get the proper
result. If I try to parse 'a : b;', it gives a MismatchedTokenException.
(I am pretty sure I saw the same behavior using the debug option, but I
don't have the JDK on this computer and can't confirm it.)
The rules in question are:
COLON : ':'; // used in multiple places
ARROW
: '->'
| COLON
;
production
: SYMBOL ARROW disjunction SEMICOLON
;
(If you're curious, COLON is used elsewhere so I put it into its own
token. (I saw a couple posts from this mailing list previously
recommending not using string literals in parsing rules.) What I'm
posting is a slightly simplified version where that other use is
removed. It doesn't change the behavior though.)
The parse tree AntlrWork's interpreter shows for 'a->b;' is
rules
|
production
|
+-----+---+-----+----------+
| | | |
a -> disjunction ;
|
termString
|
term
|
atom
|
b
But for 'a: b;' I get
rules
|
production
|
+---------+-----+
| |
a MismatchedTokenException(11!=16)
Can anyone explain what's going on?
Thanks,
Evan
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cfg.g
Url: http://www.antlr.org/pipermail/antlr-interest/attachments/20091202/7f8b87db/attachment.pl
More information about the antlr-interest
mailing list