[antlr-interest] Testing For Alternative Terminals In Actions
Randall R Schulz
rschulz at sonic.net
Thu Mar 20 13:01:56 PDT 2008
On Thursday 20 March 2008 12:38, Randall R Schulz wrote:
> Hi,
Sorry to jump to the list so quickly.
> I have a few productions such as this one:
>
> booleanSentence
>
> : ( Open! ( If^ | Then^ | Iff^ | XOr^ ) sentence sentence Close! )
>
> ;
I tried this:
{
if ($Then != null)
noteNonCLIF($Then.getLine(), $Then.getCharPositionInLine(), "Non-standard CLIF: \"then\" ");
if ($XOr != null)
noteNonCLIF($XOr.getLine(), $XOr.getCharPositionInLine(), "Non-standard CLIF: \"xor\" ");
}
and got an NPE. I then sent the mail with the question. It turns out
that in my ever-dubious practice of copy-and-modify I left in $
references to a terminal that was prefixed by !. This apparently makes
the token null at the time the action code is executed.
So basically, I actually did have the right technique, just not quite
the right code.
> ...
Randall Schulz
More information about the antlr-interest
mailing list