令牌与 antlr 语法谓词不匹配
我的语法文件中有以下词法分析器规则:
LINE : 'F' | 'G';
RULE : (('->' ('F' | 'G')) => 'F' | 'G' )
| LINE LINE + | LINE * (ROTATE + LINE+)+ ;
fragment ROTATE : ('/' | '\\');
我基本上是在尝试匹配看起来像 F -> 的产生式。 F/F\F\F/F。它成功匹配了上面的内容,但我猜我的语法谓词有问题,因为 G -> G 产生 MismatchedTokenException。该谓词用于消除“->”左侧的单个字母(我希望将其识别为 LINE 标记)和右侧的单个字母(应该是规则)之间的歧义。
知道我做错了什么吗?
I have the following lexer rules in my grammar file:
LINE : 'F' | 'G';
RULE : (('->' ('F' | 'G')) => 'F' | 'G' )
| LINE LINE + | LINE * (ROTATE + LINE+)+ ;
fragment ROTATE : ('/' | '\\');
I'm basically trying to match productions that look like F -> F/F\F\F/F. It successfully matches stuff like the above, but I'm guessing there's a problem with my syntactic predicate, since G -> G produces a MismatchedTokenException. The predicate serves to disambiguate between single letters on the lhs of '->', which I want to be recognized as the LINE token, and those on the rhs, which should be RULEs.
Any idea what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,规则:
匹配单个
G
而不带谓词。上面的规则可以重写为:反过来又等于:
也许你打算做这样的事情:
Note that the rule:
matches a single
G
without the predicate. The rule above could be rewritten as:which in its turn equals:
Perhaps you meant to do something like this: