且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查int是否在两个数字之间

更新时间:2022-06-13 10:20:46

一个问题是三元关系结构会引入严重的解析器问题:

One problem is that a ternary relational construct would introduce serious parser problems:

<expr> ::= <expr> <rel-op> <expr> |
           ... |
           <expr> <rel-op> <expr> <rel-op> <expr>

当你尝试使用典型的PGS表达这些作品的语法时,你会发现那里是第一个< rel-op> 点的转换减少冲突。解析器需要预先查看任意数量的符号,以查看是否有第二个< rel-op> ,然后才能决定是否使用了二进制或三元形式。在这种情况下,你不能简单地忽略冲突,因为这会导致错误的解析。

When you try to express a grammar with those productions using a typical PGS, you'll find that there is a shift-reduce conflict at the point of the first <rel-op>. The parse needs to lookahead an arbitrary number of symbols to see if there is a second <rel-op> before it can decide whether the binary or ternary form has been used. In this case, you could not simply ignore the conflict because that would result in incorrect parses.

我不是说这个语法是致命的歧义。但我认为你需要一个回溯解析器才能正确处理它。对于编程语言而言,这是一个严重的问题,其中快速编译是一个主要卖点。

I'm not saying that this grammar is fatally ambiguous. But I think you'd need a backtracking parser to deal with it correctly. And that is a serious problem for a programming language where fast compilation is a major selling point.