1.7k 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$
edited | 1.7k views
+1
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.

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')$

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.

Shift reduce is bottom up parser.

Output : 23131

0
We should not use L attribute and S attribute thingy

1
2
+1 vote