20,185 views
73 73 votes

Which of the following describes a handle (as applicable to LR-parsing) appropriately?

  1. It is the position in a sentential form where the next shift or reduce operation will occur

  2. It is non-terminal whose production will be used for reduction in the next step

  3. It is a production that may be used for reduction in a future step along with a position in the sentential form where the next shift or reduce operation will occur

  4. It is the production $p$ that will be used for reduction in the next step along with a position in the sentential form where the right hand side of the production may be found

3 Answers

Best answer
93 93 votes

A sentential form is the start symbol $S$ of a grammar or any string in $(V \cup T)^*$ that can be derived from $S$.

Consider the linear grammar

$(\{S, B\}, \{a, b\}, S, \{S  \rightarrow aS, S  \rightarrow B, B  \rightarrow bB, B  \rightarrow \lambda \})$.

A derivation using this grammar might look like this:

$S \Rightarrow aS \Rightarrow aB \Rightarrow abB \Rightarrow abbB \Rightarrow abb$
 

Each of $\{S, aS, aB, abB, abbB, abb\}$ is a sentential form.

Because this grammar is linear, each sentential form has at most one variable. Hence there is never any choice about which variable to expand next.

Here, in option D the sentential forms are same but generated differently coz we are using here Bottom Up production.

Handle:
for example the grammar is:

$$\begin{align*} E &\rightarrow E+n\\ E &\rightarrow E*n\\ E &\rightarrow n \end{align*}$$

Then say to derive string $n+n*n$:

these are three different handles shown in $3$ different colors = $\left\{ n, E+n, E*n \right \}$

that's what option D says

• edited by
17 17 votes
Answer is (D)

Handle is a substring of sentential form from which the start symbol can be reached using reduction at each step.
1 1 vote

It is the production that will be used for reduction in the next step along with a position in the sentential form where the right-hand side of the production may be found.

In LR-parsing, a handle is a substring of the right-hand side of a production that matches the right end of the current stack contents. The reduction operation is applied using this handle to replace the matched substring with the non-terminal on the left-hand side of the production. The position in the sentential form indicates where the right-hand side of the production may be found.

Answer:
Position:
Show:

Related questions

74 74 votes
4 answers 4 answers
35.8k
35.8k views
Kathleen asked Sep 12, 2014
35,819 views
Which of the following are NOT true in a pipelined processor?Bypassing can handle all RAW hazardsRegister renaming can eliminate all register carried WAR hazardsControl h...
49 49 votes
3 answers 3 answers
25.7k
25.7k views
Kathleen asked Sep 12, 2014
25,718 views
An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only ifThe SLR(1) parser for G has S-R conflictsThe LR(1) parser for G has S-R conflictsThe...
53 53 votes
7 answers 7 answers
25.4k
25.4k views
Kathleen asked Sep 11, 2014
25,376 views
Some code optimizations are carried out on the intermediate code becauseThey enhance the portability of the compiler to the target processorProgram analysis is more accur...
70 70 votes
5 answers 5 answers
20.2k
20.2k views
Kathleen asked Sep 11, 2014
20,165 views
Which of the following statements are true?Every left-recursive grammar can be converted to a right-recursive grammar and vice-versaAll $\epsilon$-productions can be remo...