[antlr-interest] Lexer grammar design issue

Jason jasonriz at yahoo.com
Wed Jan 21 08:32:36 PST 2004


Hello,

I"m in the process of converting a large Lex/Yacc pair
of grammars to ANTLR.  I've spent a couple days
playing with ANTLR and the ANTLR documentation.  So
far I like it quite a bit, but I am having some
troubles wrapping my head around the lexer.  The Lex
grammar I'm 'converting' defines about 200 tokens and
makes considerable use of Lex's state mechanism.  For
example, there are over a hundred lines which look
something like the following:

<STATE1, STATE2>mytoken { myMethod( ) // My method may
or may not just return the literal token }

The ANTLR documentation recommends using Semantic
Predicates to simulate DFA based lexical states.  I
would like to do something like this:

MYTOKEN:{this.state == STATE1 || this.state == STATE2}

where MYTOKEN is a rule which matches the literal
'mytoken.'  Unfortunately, it seems that ANTLR doesn't
generate rules corresponding to literals.  I realize I
could push this logic into the Parser but I'd rather
not have to - there is enough going on there already
:)  Is there something I'm missing?  If anyone could
offer any suggestions, I'd really appreciate it.

-jason  


__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/antlr-interest/

To unsubscribe from this group, send an email to:
 antlr-interest-unsubscribe at yahoogroups.com

Your use of Yahoo! Groups is subject to:
 http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list