字符串匹配问题(我可以优先考虑吗?)
我有一个(错误指定的)要求,要求我识别某些关键字,但也有“任何字符串”的规定...
例如,在输入“让我们有一个”中,我必须处理==“啤酒”,== “curry” 和 == 任何其他字符串(理论上,关键字 beer 和 curry 优先于所有其他字符串)。
当然,当我尝试定义它时,我想象
Decision can match input such as "'curry" using multiple alternatives: 2, 3
As a result, alternative(s) 3 were disabled for that input
这是一个 st00pid n00b 常见问题解答,但没有看到明显的答案。任何帮助感激不尽...
I have a (badly specified) requirement that I recognize certain keywords, but there is also provision for 'any string' ...
For instance, in the input "let's have a " I have to handle == "beer", == "curry" and == anything else at all (in theory, the keywords beer & curry have priority over all other strings).
When I try to define this, of course, I get
Decision can match input such as "'curry" using multiple alternatives: 2, 3
As a result, alternative(s) 3 were disabled for that input
I imagine this is a st00pid n00b FAQ, but don't see an obvious answer. Any help gratefully received ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要应用一些您正在学习的语法消歧技术(如果这是家庭作业)。一般来说,您添加一条附加规则来消除语法歧义。
您可以做的另一件事是向规则添加一个操作来处理差异。
如果您发布有问题的 antlr 代码,我可能会提供更多帮助。
You need to apply some of the grammar disambiguation techniques that you are either learning (if this is homework). Generally speaking you add an additional rule that disambiguates the grammar.
Another antlr specific thing you can do is add an action to the rule that will handle the differences.
I might be able to help more if you post the antlr code in question.