[antlr-interest] Selectively disabling lexer rules
Martin Traverso
mtraverso at gmail.com
Mon Jan 2 01:41:19 PST 2006
Ter,
Is there a way to selectively disable lexer rules in ANTLR v3? Let me
explain the problem I'm trying to solve. Maybe you have other ideas.
Ruby has a conditional operator like Java:
a ? b : c
But the question mark is also used to represent character literals like so:
?x -> the character 'x'
The character after the ? has to be a printable character, so new lines,
spaces, etc are not allowed (for those, the literal is ?\n, ?\s, etc)
The problem is that in the conditional expression a space is not required
after the ?. Thus, "a ?b : c" is a valid expression. So you see the
conflict. When parsing that expression the lexer cannot decide whether to
match a character literal or the ? operator.
One approach I considered was to use a flag to guard whether the token for
character literals can be matched (via a semantic predicate) and turn it off
and on when appropriate. Is there a better alternative?
Thanks,
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060102/223871aa/attachment.html
More information about the antlr-interest
mailing list