问题描述
该问题埋在另一个问题的更新部分中,现在专门问这个问题.
The question is buried in the update section of another question, now specifically ask it.
我正在使用antlr3.4.
I am using antlr3.4.
我有一个简单的语法试图解析2种类型的文本,该行以"#include"开头,还有其他.这是我的语法:
I have a simple grammar trying to parse 2 types of text, the line started with "#include" and others. Here is my grammar:
:The warning means that input like foo" (a FILE_NAME followed by a DOUBLE_QUOTE) can be matched by the parser in more than one way:
ANTLR将选择贪婪解析,但是由于可能出现贪婪,因此会生成警告.如果您明确告诉解析器贪婪地进行匹配,则不会再发出警告:
ANTLR will choose the greedy parse, but since an ungreedy is possible, a warning is generated. If you explicitly tell the parser to match greedily, the warning would not be issued anymore:
other_cmd : (options {greedy=true;} : ~INCLUDE)+ ;不,据我所知.这个警告确实是个神秘的事物.替代方法通常表示解析器可以遵循的分支:
No, not as far as I know. This warning is indeed rather cryptic. Alternatives usually denote the branches the parser can follow:
parser_rule : alternative_1 | alternative_2 | alternative_3 ;但是在您的情况下,ANTLR似乎在谈论令牌范围是替代方案:DOUBLE_QUOTE..FILE_NAME是替代方案,New_Line..WS是第二替代方案.
But in your case, it seems ANTLR is talking about token ranges being the alternatives: DOUBLE_QUOTE..FILE_NAME being an alternative and New_Line..WS being the 2nd.
这篇关于解析器规则和词法分析器规则之间的替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!