handle.pdf
TRANSCRIPT
12/11/2015 Parsing and Syntax directed translation GeeksQuiz
http://geeksquiz.com/parsingandsyntaxdirectedtranslation/ 1/2
Question 8 CORRECT
It is the position in a sentential form where the next shift or reduce operation will occur
It is nonterminal whose production will be used for reduction in the next step
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
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
Which of the following describes a handle (as applicable to LRparsing) appropriately?
ABC
Discuss it
Question 8 Explanation: Let's first understand the terminology used here. LR Parsing Here 'L' stands for Left toRight screening of input string, and 'R' stands for Right Most Derivation in Reverse (because it is about bottomup parsing). Sentential Form Suppose For a given ContextFree Grammar G, we have a start symbol S, then to define Language generated byGrammar G, i.e. L(G), we start the derivation starting from S using the production rules ofthe grammar. After one complete derivation we get a string w which consists of onlyterminal symbols, i.e. w belongs to L(G). Then we can say that w is a sentence of theGrammar G. Now, while the derivation process, if it gets some form q, where q maycontain some Nonterminal 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 alsocontains Nonterminal S).
For Ex :
Grammar is :
S‐> aAcBe
A‐>Ab|b
B‐>d
Input string : abbcde
Derivation : ( Top‐Down, Right Most Derivation)
S‐>aAcBe ‐>aAcde
12/11/2015 Parsing and Syntax directed translation GeeksQuiz
http://geeksquiz.com/parsingandsyntaxdirectedtranslation/ 2/2
‐>aAbcde ‐>abbcde
Here { abbcde } is the sentence of the Grammar( because it contains only terminalsymbols), and { S, aAcBe, aAcde, aAbcde } are the sentential forms of the G ( becausethese forms contain nonterminals during the derivation process ) Now, let's look at thequestion. The question is related to LR parsing which is a bottomup parsing. Let's takethe 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 replacedby their LHS is called Handle, So , { b, Ab, d, aAcBe} are handles, and replacing it with itsLHS is called HandlePruning. Hence option D suits best.