[antlr-interest] booleans in interpreters
Michael Laszlo
mjl at nova.edu
Fri Sep 23 09:10:59 PDT 2005
In my lexer code, my ID pattern picks out keywords and literals.
For example:
ID: LETTER (LETTER|DIGIT)* {
...
// primitive literals
else if (getText().equals("true")) { $setType(BOOLEAN); }
else if (getText().equals("false")) { $setType(BOOLEAN); }
}
My parser includes this code:
tokens {
BOOLEAN<AST=BooleanNode>;
...
}
My intention is to build a true and a false instance of the
BooleanNode class. The BooleanNode constructor uses getText()
to distinguish the two cases.
However, antlr.Tools complains about nondeterminisms between
rules BOOLEAN and ID.
I've noticed that if I include an assignment clause in the
tokens declarations, things work fine. Something like:
tokens {
BOOLEAN_TRUE="true"<AST=BooleanNode>;
BOOLEAN_FALSE="false"<AST=BooleanNode>;
...
}
However, it shouldn't be necessary to define distinct token types
for true and false.
Any suggestions?
Thanks, Michael
More information about the antlr-interest
mailing list