字符串匹配问题(我可以优先考虑吗?)

发布于 2024-08-13 17:20:00 字数 383 浏览 4 评论 0原文

我有一个(错误指定的)要求,要求我识别某些关键字,但也有“任何字符串”的规定...

例如,在输入“让我们有一个”中,我必须处理==“啤酒”,== “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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巡山小妖精 2024-08-20 17:20:00

您需要应用一些您正在学习的语法消歧技术(如果这是家庭作业)。一般来说,您添加一条附加规则来消除语法歧义。

您可以做的另一件事是向规则添加一个操作来处​​理差异。

如果您发布有问题的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文