[antlr-interest] gated semantic predicate usage

Jim Idle jimi at temporal-wave.com
Tue Jan 22 13:18:29 PST 2008


> -----Original Message-----
> From: Mark Volkmann [mailto:r.mark.volkmann at gmail.com]
> Sent: Tuesday, January 22, 2008 12:22 PM
> To: Jim Idle
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] gated semantic predicate usage
> 
> I'm using the antlr-2008-01-14.10 version now. I no longer get the
> NullPointerException which is good, but it also doesn't throw an
> exception when the predicate fails. Maybe it's not supposed to. I just
> get a message that says "
> 
> line 11:0 mismatched input 'list' expecting EOF
> MathTree.g: node from line 0:0 mismatched tree node: <mismatched
> token: [@55,354:357='list',<12>,11:0], resync=a = 3.14".
> 
> I'd like to figure out a way to detect that some input (in this case a
> statement that starts with "list") wasn't processed due to the gated
> semantic predicate and output a better error message. Do you know how
> to detect this?

I think you are probably trying to use a gated predicate for something 
that it is not intended for. If the gate is turned off it means that the 
recognizer just won't ever take the alt that the gate protects. If there 
are tokens in the input stream, then something must match them or you 
have a syntax error.

When you get  a syntax error, your tree rewrite will possibly try to 
write null elements. You must protect for this in rewrite rules -> {$xxx 
!=null}? ^(TOKEN $xxx+)

If you want to know whether the gate was open or closed, either 
reevaluate the predicate, or evaluate it in the rule and return it as a 
Boolean return type. However, you will still need something to process 
your list token. Perhaps what you want are conditional rewrites? What is 
it that you are trying to achieve?

Jim




More information about the antlr-interest mailing list