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

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

ANTLR crifan 2563浏览 0评论

【问题】

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

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
80
81
82
83
84
85
86
87
88
89
90
91
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

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

1
2
3
4
5
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.340 seconds, using 22.18MB memory