我有一个令牌 OR:'OR'; 我用于评估布尔表达式(a==b OR a==c)我有另一个规则用于解析字符列表 AZ、AK、OR、GA 中的状态缩写...我发现的是 antlr在状态列表上有错误认为 OR 应该是一个or
令牌而不是
stateName
: CHAR CHAR (','|EOF) ->^(STATE CHAR+)
;
我将如何解决这种歧义?
这是我试图解析的一些规则
- THEN STATE_LICENSE AL,AK,AS,AZ,AR,CT,DE,DC,FM,FL,GA,GU,HI,ID,IL,IN,IA,KS,KY,LA,ME,MH,MD,MA, MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,MP,OH,OK,OR,PW,PA
- 如果 1198 == "x" 或 1190 != "x" 那么禁用 800
- IF 801 >= "1000000" THEN DISPLAY_ERROR "这+太贵了。+Go+and+get+cheaper+one+!!!"
这是我正在使用的语法
grammar PointFieldRule;
options
{
//language = 'CSharp3';
output=AST;
ASTLabelType=CommonTree;
}
tokens{
STATE;
}
rule : ifExpression? actionExpression EOF!
;
ifExpression
:'IF'! logicalConditionExpression
;
logicalConditionExpression
: booleanAndConditionExpression ( BigOR^ booleanAndConditionExpression)*
;
booleanAndConditionExpression
: logicalCondition ( BigAND^ logicalCondition )*
;
BigAND : 'and'|'AND';
logicalCondition
: booleanAndCondition ( OR^ booleanAndCondition )*
;
OR:'||';
booleanAndCondition
: evalCondition ( AND^ evalCondition)*
;
AND: '&&';
evalCondition
: FieldID OPERATOR^ (FieldID|STRING)
;
actionExpression
: 'THEN'! (actionMessage | fieldAction | stateAction )
;
actionMessage
: ('DISPLAY_WARNING' | 'DISPLAY_ERROR')^ STRING
;
fieldAction
: ('DISABLE' | 'REQUIRED')^ FieldID ( ','! FieldID )*
;
stateAction
: 'STATE_LICENSE'^ stateName+ //(','! stateName)*
;
FieldID
:'0'..'9'+;
/* item : FIELD
| CHAR CHAR
;
*/
//class csharpTestLexer extends Lexer;
stateName
: CHAR CHAR (','|EOF) ->^(STATE CHAR+)
;
CHAR: ('a'..'z'|'A'..'Z')
;
WS : (' '
| '\t'
| '\n'
| '\r')
{ $channel = HIDDEN; }
//{ $channel = Hidden; }
;
OPERATOR
: '=='
| '!='
| '<='
| '>='
| '<'
| '>'
| 'TD'
| 'FD'
| 'PD'
| 'TY'
| 'LY'
| 'TM'
| 'LM'
| '+(DELTA%)>'
| '-(DELTA%)>'
| '+(DELTA)>'
| '-(DELTA)>'
| 'LIKE'
;
STRING
: '"' ( ESC_SEQ | ~('\\'|'"') )* '"'
;
fragment
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
fragment
ESC_SEQ
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
| UNICODE_ESC
| OCTAL_ESC
;
fragment
OCTAL_ESC
: '\\' ('0'..'3') ('0'..'7') ('0'..'7')
| '\\' ('0'..'7') ('0'..'7')
| '\\' ('0'..'7')
;
fragment
UNICODE_ESC
: '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
;
//fragment
BigOR: 'or'|'OR';