【问题】
写了个antlr v3的语法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 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后面多个冒号:
1 2 | INT : '0'..'9'+; ; |
去掉多余的冒号,即可:
1 | INT : '0'..'9'+; |
【总结】
虽然有antlr的语法错误,但是此处AntlrWorks却没有报错,显示的是绿色的:
所以,貌似此处属于语义错误?
否则,那就是antlrworks的bug了。
转载请注明:在路上 » 【已解决】error syntax error: antlr: MissingTokenException(inserted [@-1,0:0='<missing EOF>’,<-1>,12:4] at