term :
| LOGICALVALUE
| literal
;
literal :
ATOM
( LEFTROUNDBRACKET termlist? RIGHTROUNDBRACKET )?
;termlist :
term ( COMMA term )*
;ATOM :
LOWERCASELETTER
( LOWERCASELETTER | UPPERCASELETTER | DIGIT )*
;LOGICALVALUE :
TRUE| FALSE
;fragment TRUE : 'true' | 'success';
fragment FALSE : 'false' | 'fail';fragment DIGIT : [0-9];fragment LOWERCASELETTER : [a-z];
fragment UPPERCASELETTER : [A-Z];If I try to parse the string "success" in the term rule, it match to the literal rule, because the ATOM rule matches, butin this case I need to match to the LOGCIALVALUE token, because it is a "fixed keyword". Can you help me todeal with this fixed word. IMHO the LOGICALVALUE token is be tested first, so the literal rule should not match, but I thinkI don't understand it correct.In my case, I have got 4 fixed keyword "true, false, success, fail" which are written in lower-case, but if it is strict matchedthe terminal should be used, but otherwise the literal rule should be used. How can I define this correct?ThanksPhil
Greetings!
In ANTLR, when 2 lexer rules match exactly the same input sequence of characters, the rule mentioned first in the grammar file is used to create the corresponding Token.
Move ATOM rule to be after all other lexer rules. All keyword
rules should appear before any other lexer rule.
Hope this helps...
-jbb
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.