Skip to content
Official PYQ · 2016

GATE CS 2016 Set 1 Q46 — Syntax-directed Translation

Explain with AI

Consider the following Syntax Directed Translation Scheme (SDTS)( SDTS ), with non-terminals {S,A}\{S,A \} and terminals {a,b}\{a,b \}.

          S→aA{print 1}S \to aA \quad \{\text{print }1\}

          S→a{print 2}S \to a \quad \{\text{print }2\}

          A→Sb{print 3}A \to Sb \quad \{\text{print }3\}

Using the above SDTSSDTS , the output printed by a bottom-up parser, for the input aabaab is:

Choose one option
View worked solution

Answer: C

A bottom-up parser performs reductions in the reverse order of a rightmost derivation.

First, let's find the rightmost derivation for the input string aabaab using the given grammar:

S⇒aA(using S→aA)⇒aSb(using A→Sb)⇒aab(using S→a)\begin{aligned} S &\Rightarrow aA && \text{(using } S \to aA\text{)}\\ &\Rightarrow aSb && \text{(using } A \to Sb\text{)}\\ &\Rightarrow aab && \text{(using } S \to a\text{)} \end{aligned}

The sequence of reductions performed by the bottom-up parser is the exact reverse of this rightmost derivation:

  1. First reduction: a→Sa \to S (reducing the second aa in aabaab to SS)
    Associated action: {print 2}
  2. Second reduction: Sb→ASb \to A (reducing SbSb to AA)
    Associated action: {print 3}
  3. Third reduction: aA→SaA \to S (reducing the entire string aAaA to the start symbol SS)
    Associated action: {print 1}

Thus, the output printed by the parser is: 2 3 12 \ 3 \ 1.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Syntax-directed Translation questions