【问题】
写了个antlr v3的语法:
grammar DDParserDemo; options { output = AST; ASTLabelType = CommonTree; // type of $stat.tree ref etc... } ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ; INT : '0'..'9'+; ; FLOAT : ('0'..'9')+ '.' ('0'..'9')* EXPONENT? | '.' ('0'..'9')+ EXPONENT? | ('0'..'9')+ EXPONENT ; COMMENT : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} | '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;} ; WS : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;} ; STRING : '"' ( ESC_SEQ | ~('\\'|'"') )* '"' ; CHAR: '\'' ( ESC_SEQ | ~('\''|'\\') ) '\'' ; fragment EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ; 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 ; NEWLINE : '\r'? '\n' ; DECIMAL_VALUE : (INT)+; HEX_VALUE : '0x' (HEX_DIGIT)+; prog : identification+ ; identification : definiton ','? (WS)* -> definiton ; definiton : ID (' '|'\t')+ (DECIMAL_VALUE | HEX_VALUE) ;
结果出错了:
[17:02:19] error(100): DDParserDemo.g:12:5: syntax error: antlr: MissingTokenException(inserted [@-1,0:0='<missing EOF>’,<-1>,12:4] at 😉 |
【解决过程】
1.才注意到,原来是INT后面多个冒号:
INT : '0'..'9'+; ;
去掉多余的冒号,即可:
INT : '0'..'9'+;
【总结】
虽然有antlr的语法错误,但是此处AntlrWorks却没有报错,显示的是绿色的:
所以,貌似此处属于语义错误?
否则,那就是antlrworks的bug了。
转载请注明:在路上 » 【已解决】error syntax error: antlr: MissingTokenException(inserted [@-1,0:0='<missing EOF>’,<-1>,12:4] at 😉