这个问题在我身上出现过很多次。我不完全理解这个问题。我的语法如下所示:
grammar Syntax;
options {
language = Java;
backtrack = true;
}
rule: ('syntax' (INTEGER | HEX) ';')? (structure | packet)+;
structure: ('struct' | 'structure')? field;
packet: 'packet'? NAME '{' field+ '}';
field: NAME (':' | '=' | ':=' | '->')? value ';';
value: (TYPE (MULT (INTEGER | HEX))?);
MULT: 'x' | 'X';
INTEGER: ('0'..'9')+;
HEX: '0x' ('0'..'9' | 'A'..'F' | 'a'..'f');
TYPE: ('unsigned'? 'byte' | 'short' | 'int16' | 'int8')
| 'int' | 'int32'
| 'long' | 'int64'
| 'char' | 'char8' | 'char16' | 'unicode'
| 'utf' | 'utf8' | 'utf16';
NAME: ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*;
WHITESPACE: ( ' ' | '\n' | '\r' | '\f' | '\t')+{$channel = HIDDEN;} ;
测试用例如下所示:
syntax 1;
packet a
{
a int;
b byte;
d byte x 10;
c int x b;
}
现在错误是: