A. LR(0)
B. LR(1)
C. LALR(1)
D. LL(0)
E. SLR
Choose the correct answer from the options given below:
This section details the relative power of various grammar parsers used in compiler construction. Parser power signifies a parser's ability to recognize and process grammars within a specific class. A parser with greater power can handle a broader set of grammars. We analyze the hierarchy for $LL(0)$, $LR(0)$, $SLR$, $LALR(1)$, and $LR(1)$ parsers.
$LL(0)$ parsers operate top-down. They are highly constrained, requiring unambiguous grammars without left recursion and using zero lookahead. Consequently, $LL(0)$ can only parse extremely simple context-free grammars.
$LR(0)$ parsers work bottom-up. As the most basic type of LR parser, they build states from grammar items but lack lookahead for resolving shift/reduce conflicts. While superior to $LL(0)$, their grammar handling capacity remains limited.
$SLR$, or Simple LR, enhances $LR(0)$ by incorporating FOLLOW sets. These sets help in resolving shift/reduce conflicts. The use of FOLLOW sets gives $SLR(1)$ parsers greater power than $LR(0)$ parsers, enabling them to handle more grammars.
$LALR(1)$ (Look-Ahead LR) strikes a balance between $LR(1)$'s power and $SLR$'s state efficiency. It merges states from an $LR(1)$ parser that share identical item sets (disregarding lookaheads). This merging process allows $LALR(1)$ to handle more grammars than $SLR$.
$LR(1)$ parsers represent the most powerful deterministic type among the common LR parsers. They utilize a lookahead symbol effectively for action decisions. Unlike $LALR(1)$, $LR(1)$ maintains distinct states even for identical item sets if their lookaheads differ. This characteristic enables $LR(1)$ parsers to handle the broadest range of unambiguous context-free grammars.
The hierarchy of parser power, from least capable to most capable, is determined by the class of grammars each parser type can handle:
The correct sequence representing the increasing order of parser power is:
$LL(0)$ $\rightarrow$ $LR(0)$ $\rightarrow$ $SLR$ $\rightarrow$ $LALR(1)$ $\rightarrow$ $LR(1)$
Consider the following statements:
Statement I: LALR parser is more powerful than canonical LR Parser.
Statement II: SLR parser is more powerful than LALR
Which of the following is correct?
Given below are two statements
Statement I : LL(1) and LR are examples of Bottom‐up parsers.
Statement II : Recursive descent parser and SLR are examples of Top‐down parsers
In light of the above statements, choose the correct answer from the options given below
Consider the grammar G with productions \(S\to A\mid B,\quad A\to a\mid c,\quad B\to b\mid c\). The nonterminals are S, A, B and the terminals are a, b, c.
Without rewriting G or resolving parsing-table conflicts by an extra rule, which statements are correct?
S1: The canonical LR(1) parsing table for G is conflict-free.
S2: The LL(1) predictive parsing table for G is conflict-free.