The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+17 votes

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 (52k points)
edited by | 1.8k views
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

+20 votes
Best answer

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
why can't we take s--> y(pf'2') at the 3rd step?
@Cruise Device

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

Shift reduce is bottom up parser. 

Output : 23131

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

Related questions

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
49,530 questions
54,139 answers
71,068 users