Lexer antlr3 令牌问题
令牌
ENDPLUS: '+' (options (greedy = false;):.) * '+'
;
我是否可以构建一个由词法分析器考虑的
PRE: '<<'
;
,前提是它前面有一个令牌 PRE
而不包含在 ENDPLUS 中?谢谢。
Can I construct a token
ENDPLUS: '+' (options (greedy = false;):.) * '+'
;
being considered by the lexer only if it is preceded by a token PRE
without including in ENDPLUS?
PRE: '<<'
;
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,据我所知,这是不可能“开箱即用”的。通过使用属性
input
并调用LA(int)
(向前看)。例如,以下词法分析器规则:匹配任何单个字符,只要该单个字符后跟
b
。不幸的是,没有input.LA(-1)
功能可以在令牌流中查看后面的情况。{...}?
部分称为“语法谓词”,以防您想知道或想用 Google 搜索它。这里给出了讨论以及有关如何解决该问题的一些指示:http://www.antlr.org/pipermail/antlr-interest/2004-July/008673.html
请注意,它是
{greedy=false;}
,而不是 <代码>(贪婪=假;)。No, AFAIK, this is not possible "out of the box". One only has look-ahead-control over the tokens stream in the lexer or parser by using the attribute
input
and callingLA(int)
(look-ahead) on it. For example, the following lexer rule:matches any single character as long as that single character is followed by a
b
. Unfortunately, there's noinput.LA(-1)
feature to look behind in the token stream. The{...}?
part is called a "syntactic predicate" in case you're wondering, or wanting to Google it.A discussion, and some pointers on how to go about solving it, are given here: http://www.antlr.org/pipermail/antlr-interest/2004-July/008673.html
Note that it's
{greedy=false;}
, not(greedy=false;)
.