compiler-construction - 每个LL(1)语法也是LR(1)吗?

标签 compiler-construction lr

每个LL(1)语法也是LR(1)吗?

最佳答案

是的,因为LL和LR都从左到右解析数据;并且因为LL(1)仅向前看一个 token ,所以它必须一定是LR(1)。对于LR(k)(k> 1)也是如此,因为可以将LR(k)语法转换为LR(1)语法。

LR和LL语法之间的差异在于LR产生最右导数,而LL产生最左导数。因此,这意味着与LR语法相比,LR语法分析器实际上可以从叶子中解析出更大的集合。

可以说我们的作品如下:

A -> "(" A ")" | "(" ")"

然后LL(1)将解析字符串(()):
(()) -> A
     -> "(" A ")"
     -> "(" "(" ")" ")"

LR(1)将解析如下:
Input  Stack          Action
(())   0       
())    0 '('
))     0 '(' '(' 
)      0 '(' '(' ')'  Reduce using A -> "(" ")"
)      0 '(' A
-      0 '(' A ')'    Reduce using A -> "(" A ")"
-      0  A           Accept

有关更多信息,请参见:http://en.wikipedia.org/wiki/LL_parsing

关于compiler-construction - 每个LL(1)语法也是LR(1)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4175632/

相关文章:

parsing - 如何使用 Warshall 的传递闭包算法来确定规范的 LR(1) 解析器闭包?

compiler-construction - Less不能使用Twitter Bootstrap编译文件

c++ - 查看编译器扩展代码 - C++

bison - 如何解决减少减少冲突 :

parsing - 如何解决三元表达式 (a ? b : c) and "maybe" expressions (a? ) 之间的 LR(1) 语法歧义?

Python lrparsing模块;无法解析简单的递归文法

parsing - 这个语法是 LR(1) 而不是 SLR(1)?

c - 如何为特定部分构建大量全局数据?

optimization - 什么是好的、免费的 SSA/SCCP 资源?

javascript - 将 dart 编译为 javascript 的限制是什么?