[antlr-interest] gated semantic predicate usage
jimi at temporal-wave.com
Tue Jan 22 15:54:08 PST 2008
> -----Original Message-----
> From: Mark Volkmann [mailto:r.mark.volkmann at gmail.com]
> Sent: Tuesday, January 22, 2008 1:57 PM
> To: Jim Idle
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] gated semantic predicate usage
> 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.
Not really. It just turns on or off rules. If you turn off assert then
the parser will give you a syntax error, which is what you want if you
are not supporting assert!
In your case, in batch mode, then would you not want to reject batch
files that contain commands that can't be used?
However, I must say that my preferred approach to such things is to
parse them and produce the tree then when the tree is parsing you can
issue a semantic error: "help command is no allowed in batch mode.", or
you can just silently ignore it. If you turn off the parsing of it
altogether, then the parser will issue a syntax error, which is what it
should do and the gated predicate is working just fine.
Hope that helps you to decide on the approach to your 'problem'?
More information about the antlr-interest