retagged by
4,953 views
1 votes
1 votes
Consider the following SDT,

S → M {PRINT “2”;} A

M → 1 {PRINT “ ”;}

A → D {PRINT “1”;} E

D → 2 {PRINT “ ”;}

E → E {PRINT “ ”;} A

E → 3 {PRINT “ ”;}

A → S {PRINT “4”;} Y

S → 4 {PRINT “ ”;}

Y → ∈ {PRINT “ ”;}

If the bottom up parsing is used to parse the input string “1234” then the output number produced (without any spaces) is _______
retagged by

3 Answers

Best answer
7 votes
7 votes

Parse tree for $1234$ looks like $\Rightarrow$

In TDP, Traverse the tree top $\rightarrow$ down, left $\rightarrow$ right, and perform a semantic action for the first time it occurs during tree traversal. Thus $214$ is the answer.

In BUP we perform semantic action during reduction, Thus $412$ is the answer in the case of BUP.

edited by
0 votes
0 votes
In my opnion the input string is not parsed successfully.

why because of at the output 2 and 3 we are not getting the S symbol that means starting symbol or there is no way to derive the starting symbol. Based on the bottom up we are parsing the string from leaves to root but it is not successfully here yet. Please suggest me if i am wrong.
0 votes
0 votes
For top down approach answer is 214 why  because we write the productions along with parse tree and carry out that action when we encounter one but in case of bottom up approach we totally focus on reduction, when ever we encounter any reduction we go to production and carry out that action so according to that BUP gives me 412 as answer.

Related questions

2 votes
2 votes
1 answer
1
1 votes
1 votes
1 answer
2
iarnav asked Nov 22, 2017
642 views
Do L attributed SDT needs to have both synthesized attributes and inherited attributes?What if we don't have synthesized attributes but inherited attributes (IN WHICH VAL...
0 votes
0 votes
0 answers
3
aditi19 asked Mar 29, 2019
479 views
What is the SDT to eliminate redundant parenthesis from infix expressions with * and +? what is the concept behind removal of redundant parenthesis and how to start?
0 votes
0 votes
0 answers
4