[antlr-interest] How to come up with catch-all rules?
Randall R Schulz
rschulz at sonic.net
Fri Nov 17 14:12:17 PST 2006
Hi,
On Friday 17 November 2006 13:49, Geoffrey Zhu wrote:
> Thanks for the quick reply, Dave.
>
> This is pretty good but still makes assumptions on the structure of
> the hand-written code. For example, the number of { and } within the
> outmost { and } need to match. It also makes assumptions on the
> syntax of string, comments, and char literals. If I use perl style
> comments in the hand-written code and write:
>
> # This will break ANTLR {{{
>
> It will cause syntax errors in ANTLR.
>
> Is there any even more general ways?
In JavaCC there's something called Lexical States, which essentially
allow wholesale swapping of one lexer for another. The transitions
between which lexer state is in effect are driven by the lexical rules
themselves. (I'm not sure whether or not parser rules can switch the
lexical state.) It's often used to handle C-style comment processing,
e.g. In the beginning (and still now? -- I don' know) there was only
greedy closure in JavaCC regular expression matching. Lexcal states can
be seen as a more generalized form of ANTLR's lexer "fragment" notion.
JavaCC also has something closer to ANTLR's fragments but the fragments
have a context limited to the global rule within which they're nested.
Is there any equivalent or counterpart to in ANTLR?
Randall Schulz
More information about the antlr-interest
mailing list