[antlr-interest] automatic token type per literal
Bryan Ewbank
ewbank at gmail.com
Thu Dec 1 09:35:54 PST 2005
ANTLR does all that you ask. Look for "testLiterals" in the
documentation. It requires that you change your tokens section to be
tokens {
FOO="foo";
...
}
Also look at how to import and export token sets; very handy stuff.
Hope this is enough to get you started. I've gotta run...
- Bryan Ewbank
On 12/1/05, Matt Benson <gudnabrsam at yahoo.com> wrote:
> Let's say I have a grammar having stolen the Java
> IDENT lexer rule. In my parser, I have the following:
>
> tokens { FOO; }
>
> somerule
> : f:"foo"^ { #f.setType(FOO); } BAR
> ;
>
> Have I missed a feature by means of which I can (once)
> permanently set the association between ttype FOO and
> the literal "foo"? If not, is there a rationale for
> the absence of such a feature? If the answer to THAT
> is no, might such a feature find its way into ANTLR3?
> ;) I tried overriding the ttype in the IDENT lexer
> rule but the ambiguity issues were (at my level of
> expertise) insurmountable. :) I'm a longtime lurker
> but still fairly green wrt actually making ANTLR do
> anything...
>
> TIA,
> Matt
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>
More information about the antlr-interest
mailing list