最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】antlr语法警告:warning: Decision can match input such as "WS" using multiple alternatives: 1, 2

ANTLR crifan 2451浏览 0评论

【问题】

用antlrworks去调试antlr的语法文件,代码为:

grammar DDParserDemo;

options {
	output = AST;
	ASTLabelType = CommonTree; // type of $stat.tree ref etc...
}

//NEWLINE :   '\r'? '\n' ;
//NEWLINE :   '\r' '\n' ;
fragment NEWLINE :   '\r'? '\n' ;


ID  :	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'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'
        ) {skip();}
    ;

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
    ;

fragment
DIGIT
	:	'0'..'9';

//FAKE_TOKEN 	:	'1' '2' '3';

/*
DECIMAL_VALUE
	:	'1'..'9' DIGIT*;
*/

DECIMAL_VALUE
	:	DIGIT*;

HEX_VALUE
	:	'0x' HEX_DIGIT+;
/*	
startParse	:	(identification)+;
*/
startParse	:	(identification)+;

identification	:	definiton WS* ','? WS*   -> definiton
		;
	
definiton	:	(ID)^ ('\t'!|' '!)+ (DECIMAL_VALUE | HEX_VALUE)
		;

然后去

Generate -> Generate Code

结果虽然是可以正常编译,以及后续的正常调试。

但是却出现警告:

[13:56:55] warning(200): DDParserDemo.g:87:28:

Decision can match input such as "WS" using multiple alternatives: 1, 2

As a result, alternative(s) 2 were disabled for that input

[13:56:55] warning(200): D:\DevRoot\IndustrialMobileAutomation\HandheldDataSetter\ANTLR\projects\v1.5\DDParserDemo\DDParserDemo.g:87:28:

Decision can match input such as "WS" using multiple alternatives: 1, 2

As a result, alternative(s) 2 were disabled for that input

很明显,该警告,对应的代码为:

WS  :   ( ' '
        | '\t'
        | '\r'
        | '\n'
        ) {skip();}

此处想要完全搞懂,此处的警告的确切含义。

如果可以的话,尽量消除此警告。

【解决过程】

1.

转载请注明:在路上 » 【未解决】antlr语法警告:warning: Decision can match input such as "WS" using multiple alternatives: 1, 2

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.183 seconds, using 22.11MB memory