📜  LL和LR解析器之间的区别

📅  最后修改于: 2021-06-28 07:08:11             🧑  作者: Mango

LL解析器包括递归下降解析器和非递归下降解析器。它的一种使用回溯,而另一种使用解析表。这些是自上而下的解析器。
示例:给定的语法是

S -> Ac
A -> ab 

其中S是开始符号,A是非终结符,a,b,c是终结符。

输入字符串: abc
解析由LL解析器生成的树:

LR解析器是自底向上的解析器之一,它使用语法分析表(动态编程)来获取给定字符串的语法树形式的语法树形式。

示例:在上面的示例中,解析由LR解析器生成的树:

LL和LR解析器之间的区别:

LL Parser LR Parser
First L of LL is for left to right and second L is for leftmost derivation. L of LR is for left to right and R is for rightmost derivation.
It follows the left most derivation. It follows reverse of right most derivation.
Using LL parser parser tree is constructed in top down manner. Parser tree is constructed in bottom up manner.
In LL parser, non-terminals are expanded. In LR parser, terminals are compressed.
Starts with the start symbol(S). Ends with start symbol(S).
Ends when stack used becomes empty. Starts with an empty stack.
Pre-order traversal of the parse tree. Post-order traversal of the parser tree.
Terminal is read after popping out of stack. Terminal is read before pushing into the stack.
It may use backtracking or dynamic programming. It uses dynamic programming.
LL is easier to write. LR is difficult to write.
Example: LL(0), LL(1) Example: LR(0), SLR(1), LALR(1), CLR(1)