handle.pdf

2
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? A B C Discuss it Question 8 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 bottomup 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 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 also contains 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

Upload: sachin-mittal

Post on 26-Jan-2016

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Handle.pdf

12/11/2015 Parsing and Syntax directed translation ­ GeeksQuiz

http://geeksquiz.com/parsing­and­syntax­directed­translation/ 1/2

Question 8 CORRECT

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

It is non­terminal 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 LR­parsing) 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 bottom­up 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 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 alsocontains 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 

Page 2: Handle.pdf

12/11/2015 Parsing and Syntax directed translation ­ GeeksQuiz

http://geeksquiz.com/parsing­and­syntax­directed­translation/ 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 non­terminals during the derivation process ) Now, let's look at thequestion. The question is related to LR parsing which is a bottom­up 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 Handle­Pruning. Hence option D suits best.