是否有可能获得一个默认令牌,该令牌不会覆盖ANTLR3中已存在的令牌?

时间:2016-04-15 09:37:18

标签: c# antlr3

我有一个要求,其中我已将Lexer令牌写为:

IF_LEXER_TOKEN: 'IF' (.)* 'END_IF'
ANY :(options {greedy=true;}: .)* ;

但如果输入为:

IF a>b then a=b END_IF
IF c>d then c=d

在这种情况下,预期的行为是它应该使用令牌IF_LEXER_TOKEN作为第一行,ANY令牌作为第二行,而是考虑两行的ANY令牌。请帮助。注意:由于某些限制,我无法为上述场景创建解析器规则。

1 个答案:

答案 0 :(得分:0)

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.

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 Y1, while you ought to be explaining problem X1.

1 https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem