GateAI
Syntax-Directed Translation

GATE CSE 2016 Set 1 · Q46

MCQ2 marksMedium

Time

Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S,A}\{S, A\} and terminals {a,b}\{a, b\}. S⟶aA{ print 1}S⟶a{ print 2}A⟶Sb{ print 3} \begin{aligned} S & \longrightarrow aA & \{\text{ print } 1 \} S & \longrightarrow a & \{\text{ print } 2 \} A & \longrightarrow Sb & \{\text{ print } 3 \} \end{aligned} Using the above SDTS, the output printed by a bottom-up parser, for the input **aab** is:

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) 2 3 1

Syntax-Directed Translation

In a bottom-up parser (such as shift-reduce parser), the semantic action associated with a production rule is executed when that production is reduced.

Given the input string aab:

  1. Shift the first a onto the stack.

  2. Shift the second a onto the stack.

  3. Reduce the second a using S⟶aS \longrightarrow a. The semantic action { print 2 } executes, printing 2. The stack now contains a S.

  4. Shiftb onto the stack. The stack now contains a S b.

  5. ReduceS b using A⟶SbA \longrightarrow Sb. The semantic action { print 3 } executes, printing 3. The stack now contains a A.

  6. Reducea A using S⟶aAS \longrightarrow aA. The semantic action { print 1 } executes, printing 1. The stack now contains S (the start symbol).

Parsing completes successfully. Combining the printed outputs in order gives 2 3 1, which corresponds to option (C).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Syntax-Directed Translation previous year question is Q46 of the GATE CSE 2016 Set 1 paper. Find more GATE CSE PYQs on Syntax-Directed Translation in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Syntax-Directed Translation PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Syntax-Directed Translation in GATE CSE

Syntax-Directed Translation has 9 GATE CSE PYQs across 9 papers from 2016 to 2026. 4 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2016 Set 1.

How GATE tests Syntax-Directed Translation

More from GATE CSE 2016 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2016 Set 1 · Q46 · MCQ

Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals {a, b}. S & aA & { print 1 } S & a & { print 2 } A & Sb & { print 3 } Using the above SDTS, the output printed by a bottom-up parser, for the input aab is:

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.