Gold 解析器中的错误? 左旋受体

发布于 2024-07-30 09:27:18 字数 400 浏览 11 评论 0原文

这是我的 bnf 语法的一部分。

//this works
<ter-stmnt>     ::= <rval> '?' <rval> ':' <rval>
//this gets an error
<ter-stmnt>     ::= <bool-val> '?' <rval> ':' <rval>
<bool-val>      ::= <rval>

这看起来很疯狂,第二个不应该与第一个完全相同吗? 我在阅读时更喜欢第二个 bc ,我看到我期望一个 bool 值,而不是通用的 rval ,它可以意味着任何东西。

我正在使用 Gold Parser 3.4.4

Here is a piece of my bnf grammer.

//this works
<ter-stmnt>     ::= <rval> '?' <rval> ':' <rval>
//this gets an error
<ter-stmnt>     ::= <bool-val> '?' <rval> ':' <rval>
<bool-val>      ::= <rval>

This seems insane, shouldnt the second be EXACTLY the same as the first? i prefer the second bc when reading i see that i expect a bool value as oppose to the generic rval which can mean anything.

I am using Gold Parser 3.4.4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

情徒 2024-08-06 09:27:18

您收到的错误是:

减少-减少冲突

'?' 可以遵循多个已完成的规则​​。 当语法允许对于同一个标记同时减少两个或多个规则时,就会导致减少-减少错误。 语法有歧义。 请参阅文档以获取更多信息。

也就是说,在评估了一些标记后,它无法决定是读取 还是读取

为了更有意义,您的语法应该具体说明 是什么,然后说 < ;bool-val> 或其他东西。

这是另一个 reduce/reduce 错误的示例,以及 这里是 GOLD 文档。 Gold 将尝试隐藏(即发出警告而不是错误)有关移位/归约的信息,但它将归约/归约视为错误。

我不太明白这一点; 我是解析新手。 也许您认为这是意外行为是对的? 然而,GOLD 邮件列表目前似乎已关闭,可能是因为它已被审核并且 Devin 已经离线数月了。

The error that you're getting is:

Reduce-Reduce Conflict

'?' can follow more than one completed rule. A Reduce-Reduce error is a caused when a grammar allows two or more rules to be reduced at the same time, for the same token. The grammar is ambigious. Please see the documentation for more information.

It's saying that after it's evaluated some tokens, it's unable to decide whether it's just read a <bool-val> or whether it read an <rval>.

To make more sense your grammar ought to say what a <bool-val> is, specifically, and then say that an <rval> is a <bool-val> or other things.

Here's another example of a reduce/reduce error, and here's the GOLD documentation. Gold will try to hide (i.e. emit a warning instead of an error) about a shift/reduce, but it treats reduce/reduce as an error.

I don't entirely understand this; I'm new to parsing. Maybe you're right about this being unexpected behaviour? However the GOLD mailing list seems to be down at the moment, perhaps because it's moderated and Devin has been offline for months.

柳絮泡泡 2024-08-06 09:27:18

你得到什么错误? 你能包含你的整个语法文件吗? 如果我声明如下规则,我不会收到任何错误:

<ter-stmnt>     ::= <bool-val> '?' <rval> ':' <rval>
<bool-val>      ::= <rval>
<rval>  ::= '!'

What error do you get? Can you include your whole grammar file? I don't get any error if I declare rules like ...

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