是否有可能获得一个默认的令牌不覆盖ANTLR3的已经存在的令牌? [英] Is it possible to get a default token which doesn't overrides the already present tokens in ANTLR3?

查看:161
本文介绍了是否有可能获得一个默认的令牌不覆盖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 Y1, while you ought to be explaining problem X1.

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

这篇关于是否有可能获得一个默认的令牌不覆盖ANTLR3的已经存在的令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆