[antlr-interest] languages without reserved words

Michael Brade brade at informatik.uni-muenchen.de
Sun Mar 5 07:48:33 PST 2006

On Friday 03 March 2006 16:52, Martin Probst wrote:
> > As a rift on stateful lexing, perhaps using two lexers 
> > (ala java and javadoc) would allow easier partitioning of the
> > problem...
> I don't really see the difference between multiple Lexers and States -
> with both cases you have to do a { switchLexer(); } or
> { switchState(); } in the right places. I think that's pretty much the
> same after all.
Ok, this lead me to an idea that would theoretically work and that is easy and 
beautiful. When you said to put the complexity into the lexer I pretty much 
gave up on that idea, I would have to replicate the parser in the lexer.

But this would be all I need:

identifier { lexer.testLiterals = false; } 
    : NCNAME 
     { lexer.testLiterals = true; }  // should be an "exit-action"

An init-action that switches off literals, then match NCNAME, then an 
exit-action that switches literals back on.

The problem is now that the init-action is not adhered to in rules where 
identifier is used with other alternatives, there the code immediately tests 
'if (LA(1)==NCNAME)' :-(

Furthermore, there is no such thing as an exit-action AFAIK.

Does anyone have an idea of how to do the above in ANTLR? Not possible...?

Michael Brade;                 KDE Developer, Student of Computer Science
  |-mail: echo brade !#|tr -d "c oh"|s\e\d 's/e/\@/2;s/$/.org/;s/bra/k/2'
  °--web: http://www.kde.org/people/michaelb.html

KDE 4: Beyond Your Expectations
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20060305/8eaafca6/attachment.bin

More information about the antlr-interest mailing list