[antlr-interest] Do I have to use lex state in this case?
Martin Probst
mail at martin-probst.com
Sat Oct 8 08:09:31 PDT 2005
Hi,
I don't think you'll get around a stateful lexer. Those are ugly (I
know!) but they work. But yours should be quite simple:
a := /foo/ --> RegExp
a := foo / bar --> div
You have two states: expecting an operand and expecting and operator. If
your expecting and operator, '/' is the start of a regular expression.
Otherwise (operand) it's a div. Shouldn't be too difficult - it's just
very annoying to put all the state transitions into place.
> For extra credit :-), do you want to match C++ style comments, too?
> from "//" to the end of the line?
Well, just lex & parse it as an empty regular expression and then
optimizie it away ;-)
Martin
More information about the antlr-interest
mailing list