[antlr-interest] Gated semantic predicates without lookahead?

Terence Parr parrt at cs.usfca.edu
Tue Feb 17 10:55:02 PST 2009


hi, you can set k=1 but it will still check at least one symbol of  
lookahead. I don't believe there's a way to totally turn off look ahead.
Ter
On Feb 17, 2009, at 10:34 AM, Andreas Meyer wrote:

> 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
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list