[antlr-interest] Gated semantic predicates without lookahead?
Andreas Meyer
andreas.meyer at smartshift.de
Tue Feb 17 10:34:46 PST 2009
Hi!
Is it possible to have a gated semantic predicate, that somehow "hides"
the tokens behind it, so that the prediction _only_ uses the predicate?
Currently, gated semantic predicates take into account _both_ the input
that follows _and_ the predicate:
int LA = input.LA(...);
if( LA == .. _and_ semanticPredicate() ) { alternative = ... }
What I would like to be generated:
if( semanticPredicate() ) { alternative = ... }
Let's say I have 600 keywords that I want to recognize as something like
an identifier, but in other places, I really want different tokens.
Currently, I have 600 rules that do some table lookup, so that they
consume an identifier and return one of the 600 possible artificial
keyword tokens. But still, this makes the stream of tokens look like an
endless stream of identifiers to the parser, and I have a vague feeling
that this might be not the best possible solution.
Best Regards,
Andreas Meyer
More information about the antlr-interest
mailing list