编译原理中,算符优先文法和LR(1)文法啥关系
它是LR(1)的子集
■网友
我在stackoverflow问了下,这是回答。说的比较深奥,因为我还没搞明白算符优先文法,所以这个回答里说的有些特点什么的看不太懂。把原文贴上,不翻译了。大家参考下。
【编译原理中,算符优先文法和LR(1)文法啥关系】 An operator grammar is a context-free grammar in which there are no consecutive non-terminals in any right-hand side. (Intuitively, every production has an operator, as in the grammar for mathematical expressions.)
A operator precedence grammar is an operator grammar in which the parsing automaton can decide whether to shift or reduce based simply on a precedence relationship between the terminal closest to the top of the parsing stack and the lookahead token. Such a precedence relation does not need to be complete, nor transitive, nor antisymmetric.
I\u0026#39;m pretty sure that every operator precedence grammar is LR(1), but the converse is certainly not true. An LR(1) grammar does not have the restriction against consecutive non-terminals, for example, and it is quite possible for the shift/reduce decision in an LR(1) grammar to not be correlated with the uppermost terminal in the parse stack and the lookahead token. Nonetheless, some useful languages can be expressed with an operator precedence grammar.
Like LR-parsing, operator-precedence parsing is a bottom-up technique. It is possibly easier to understand than the LALR algorithm, but it has no other obvious advantage: it is not faster; it is less reliable (in the sense that some implementations will recognize erroneous sentences); and it is harder to verify. Before the LALR algorithm was discovered, however, the size of LR(1) automata (and the limited computing resources available) made operator-precedence parsing seem like a reasonable approach.
These days, you would be much better off using one of the many available parser generators.
推荐阅读
- 外交谈判|
- 既然c程序编译为机器码直接操作硬件,为啥不同操作系统下需要重新编译
- 数独设计的原理是啥
- 华为交换机的二层端口隔离,三层通是啥原理
- 以前的山寨DVD播放机的超强纠错是基于啥原理的
- qq空间非常火的gif图,是啥原理
- 请教智能合约编译的问题
- 计算机组成原理和离散数学考研的话选哪一门简单点
- 云兔免流的原理是啥
- 像迅游加速器这种加速软件的工作原理是啥怎么样才能分辨一个加速器对你有没有实际用处
