At 11:20 23/11/2009, Vipul Delwadia wrote: >x : STRING+; > >fragment BACKSLASH > : '\\'; > >NOTA: BACKSLASH A; > >A : 'a'; > >STRING > : (~(A)|NOTA)+; [...] > This works for the most part except when I try and match > just "\a", at which point I get a MismatchTokenException > (or sometimes a NoViableAltException).
The input "\a" by itself will produce a NOTA token, since that's the best-fit non-fragment rule. Your parser is however not expecting that. Almost certainly, both A and NOTA should be fragment rules. (In general, you be suspicious any time a non-fragment lexer rule refers to any other non-fragment lexer rule. It's not illegal, and sometimes it's essential, but unless you're really careful it's easy to break things by doing so.) Also, as Kirby said, inside the STRING rule itself you have one alt which is a subset of the other. Whenever you do this you should normally list the most general alt last, so NOTA should come before ~A. List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=.
