是否有可能获得一个默认的令牌不覆盖ANTLR3的已经存在的令牌? [英] Is it possible to get a default token which doesn't overrides the already present tokens in ANTLR3?
问题描述
我有其中我已经写了词法令牌作为一项要求:
I have a requirement wherein I have written the Lexer token as:
IF_LEXER_TOKEN: 'IF' (.)* 'END_IF'
ANY :(options {greedy=true;}: .)* ;
但是,如果输入被给定为:
But if the input is given as:
IF a>b then a=b END_IF
IF c>d then c=d
在这种情况下,预期的行为是它应该使用标记 IF_LEXER_TOKEN
的第一行和第二行中的任何标记,而是其考虑两条线的任何标记。请帮助。注:由于一些限制,我不能创建对于上述方案解析器规则
In this case the expected behavior is that it should use the token IF_LEXER_TOKEN
for first line and ANY token for second line, but instead its considering the ANY token for both lines. Kindly help. Note:Due to some constraints I can't create a parser rule for the above scenario.
推荐答案
我的答案是:不要'吨做你想做什么。切勿使用 *
或 +
在词法规则的末尾:。它消耗的一切,直到 EOF
。
My answer would be: don't do what you're trying to do. Never use .*
or .+
at the end of a lexer rule: it consumes everything until EOF
.
我不知道你想要做的事情,但在我看来,你正在试图获得回答问题是
1 ,而你应该被解释问题 X
1
I don't know exactly what you're trying to do, but it seems to me you're trying to get an answer to problem Y
1, while you ought to be explaining problem X
1.
1 的 http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem
这篇关于是否有可能获得一个默认的令牌不覆盖ANTLR3的已经存在的令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!