[antlr-interest] gated semantic predicate usage

Mark Volkmann r.mark.volkmann at gmail.com
Tue Jan 22 13:57:11 PST 2008


On Jan 22, 2008 3:18 PM, Jim Idle <jimi at temporal-wave.com> wrote:
> > -----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.

You're probably right. See my further comments below.

> 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?

I have a language that can be used in "batch" mode or interactively.
In batch mode you process a file of statements. In interactive mode
you enter statements one at a time at a prompt. Some statements are
only intended for interactive use. For example, "help" which outputs
help on the supported statements.

My needs seem similar to what is discussed in section 13.2 of the book
where Terr is conditionally disabling use of the Java assert keyword
using a gated semantic predicate. When allowAssert is false and an
"assert" is found in the input, I suspect no other alternative will
handle it. That's also true for my "help" statements.

If I'm using gated semantic predicates incorrectly then it seems the
book example is a bit suspect.

-- 
R. Mark Volkmann
Object Computing, Inc.


More information about the antlr-interest mailing list