GATE | GATE CS 2008 | Question 10

Which of the following describes a handle (as applicable to LR-parsing) appropriately?
(A) It is the position in a sentential form where the next shift or reduce operation will occur

(B) It is non-terminal whose production will be used for reduction in the next step
(C) 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
(D) 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


Answer: (D)

Explanation: Let’s first understand the terminology used here.

LR Parsing – Here ‘L’ stands for Left to Right screening of input string, and ‘R’ stands for Right Most Derivation in Reverse ( because it is about bottom-up parsing).

Sentential Form – Suppose For a given Context Free Grammar G, we have a start symbol S, then to define Language generated by Grammar G, i.e. L(G), we start the derivation starting from S using the production rules of the grammar. After one complete derivation we get a string w which consists of only terminal symbols, i.e. w belongs to L(G). Then we can say that w is a sentence of the Grammar G. Now, while the derivation process, if it gets some form q, where q may contain some Non-terminal then we say that q is a sentential form of the Grammar G. Even the start symbol S is also the sentential form of the Grammar G ( because it also contains Non-terminal S).


For Ex :

Grammar is :

S-> aAcBe

A->Ab|b

B->d

Input string : abbcde

Derivation : ( Top-Down, Right Most Derivation)

S->aAcBe
->aAcde
->aAbcde
->abbcde 

Here { abbcde } is the sentence of the Grammar( because it contains only terminal symbols), and { S, aAcBe, aAcde, aAbcde } are the sentential forms of the G ( because these forms contain non-terminals during the derivation process )

Now, let’s look at the question.



The question is related to LR parsing which is a bottom-up parsing.

Let’s take the same grammar above, as it is a bottom up parsing we need to start from the string “abbcde” and try to get S using production rules.


: abbcde

->aAbcde ( using A-> b )

->aAcde ( using A-> Ab )

->aAcBe ( using B -> d )

->S ( using S-> aAcBe ) 

The above process is called reduction.

The RHS of the Production which is being replaced by their LHS is called Handle, So , { b, Ab, d, aAcBe} are handles, and replacing it with its LHS is called Handle-Pruning.

Hence option D suits best.


Quiz of this Question




Recommended Posts:



0 Average Difficulty : 0/5.0
No votes yet.