3
我有一個令牌OR:'OR';我用於評估布爾表達式(a == b OR a == c)我有另一個解析狀態縮寫的規則,它們在char列表AZ,AK,OR,GA ... 我發現的是ANTLR對狀態列表思維錯誤,或者應該是一個or
令牌而不是解決antlr中的令牌衝突
stateName
: CHAR CHAR (','|EOF) ->^(STATE CHAR+)
;
我怎麼會去解決這種不確定性?
這裏有一些規則,我試圖解析
- THEN STATE_LICENSE AL,AK,AS,AZ,AR,CT,DE,DC,FM,佛羅里達州,喬治亞州,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
- IF 1198 == 「X」 或1190!= 「X」 則禁止800
- IF 801> = 「1000000」 THEN DISPLAY_ERROR「這+ 00 +昂貴。+轉到+和+得+便宜+一個+ !!!」
這裏是我使用
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';