The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+15 votes
1.5k views

A shift reduce parser carries out the actions specified within braces immediately after reducing with the corresponding rule of grammar

  • $S \rightarrow xxW \text{{print"1"}}$
  • $S \rightarrow y \text{{print"2"}}$
  • $W \rightarrow Sz \text{{print"3"}}$

What is the translation of $xxxxyzz$ using the syntax directed translation scheme described by the above rules?

  1. $23131$
  2. $11233$
  3. $11231$
  4. $33211$
asked in Compiler Design by Veteran (59.7k points)
edited by | 1.5k views
0
In the string $xxxxyzz$, $y$ will reduce first to S as there is no other handle other than y. Hence, we can eliminate all other options and A is the correct option.

2 Answers

+18 votes
Best answer

A.
Making a tree and performing post order traversal will yield answer as A.

$S \rightarrow xx W (Pf'1')$
$W \rightarrow S z (Pf'3')$
$S \rightarrow x x W (Pf'1')$
$W \rightarrow S z (Pf'3')$
$S \rightarrow y (Pf'2')$

answered by Boss (19.9k points)
edited by
0
why can't we take s--> y(pf'2') at the 3rd step?
0
@Cruise Device

because, if we do so then we cannot generate the given string.
+7 votes

Shift reduce is bottom up parser. 

Output : 23131

answered by Boss (22.5k points)
0
We should not use L attribute and S attribute thingy

Related questions

0 votes
0 answers
4


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

44,510 questions
49,966 answers
165,817 comments
65,915 users