chapter
    Syntax-Directed Translation and Intermediate Representations PYQs for GATE CS

    Solve 9+ Syntax-Directed Translation and Intermediate Representations previous year questions for GATE CS with answers and detailed solutions. Free sample que

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    2026 Slot Set1 PYQ
    Consider the following two syntax-directed definitions SDD1 and SDD2 for type declarations.

    SDD1SDD2
    Grammar
    (G1)
    Semantic RulesGrammar
    (G2)
    Semantic Rules






    is the start symbol, and , and are the three terminals. The non-terminal is the same as and the non-terminal is the same as . Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function updates the symbol table with the type information for an identifier.

    Let P and Q be the languages specified by grammars G1 and G2, respectively.

    Which of the following statements is/are true?
    Question 2
    2025 Slot Set2 PYQ
    Consider the following statements about the use of backpatching in a compiler for intermediate code generation:

    (I) Backpatching can be used to generate code for Boolean expression in one pass.
    (II) Backpatching can be used to generate code for flow-of-control statements in one pass.

    Which ONE of the following options is CORRECT?
    Question 3
    2025 Slot Set2 PYQ
    Given the following syntax directed translation rules:

    Rule 1:
    Rule 2:
    Rule 3:

    Which ONE is the CORRECT option among the following?
    Question 4
    2024 Slot Set2 PYQ
    Consider the following expression: . The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6).

    (0)+pr(1)(2)uminus(1)(3)(4)/uw(5)+(3)(4)(6)(7)=(6)(5)

    Which one of the following options fills in the missing entries CORRECTLY?
    Question 5
    2024 Slot Set2 PYQ

    Which of the following statements is/are FALSE?

    Question 6
    2024 Slot Set1 PYQ
    Consider the following syntax-directed definition (SDD).

      
      
      
      
      
      
      
      

    Given "MMLK" as the input, which one of the following options is the CORRECT value computed by the SDD (in the attribute )?
    Question 7
    2023 PYQ
    Consider the syntax directed translation given by the following grammar and semantic rules. Here , , and are non-terminals. is the starting non-terminal, and #, 0 and 1 are lexical tokens corresponding to input letters “#”, “0” and “1”, respectively. denotes the synthesized attribute (a numeric value) associated with a non-terminal . and denote occurrences of and on the right hand side of a production, respectively. For the tokens 0 and 1, and .


    The value computed by the translation scheme for the input string


    is __________. (Rounded off to three decimal places)
    Question 8
    2022 PYQ
    Consider the following grammar along with translation rules. Here # and % are operators and is a token that represents an integer and represents the corresponding integer value. The set of non-terminals is and a subscripted non-terminal indicates an instance of the non-terminal.

    Using this translation scheme, the computed value of for root of the parse tree for the expression is_____________.
    Question 9
    2021 Slot Set2 PYQ

    In the context of compilers, which of the following is/are NOT an intermediate representation of the source program?

    Free preview ends here

    Login to view the complete previous-year questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Syntax-Directed Translation and Intermediate Representations PYQs for GATE CS

    Solve 9+ Syntax-Directed Translation and Intermediate Representations previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Syntax-Directed Translation and IR

    Chapter Roadmap

    Your visual journey through the compiler's middle-end.

    Step 1: Syntax-Directed Definitions
    The Heavyweight (High Exam Yield)
    Attaching semantic rules to grammar. Inherited vs. Synthesized attributes. Dependency graphs.
    Step 2: Backpatching & Control Flow
    The Current Topic (Core Logic)
    Translating boolean logic and control structures (if, while) into Three-Address Code in a single pass.
    Step 3: Intermediate Representations
    The Formats (Direct Applications)
    Quadruples, Triples, and Indirect Triples. How the code is actually stored in memory.
    What you will master: Tracing how a high-level while loop is parsed and converted into low-level jump instructions without a second pass.

    The Forward Reference Problem in One-Pass Compilation

    The Forward Reference Problem

    When generating code for control structures like if or while, the compiler faces a dilemma in a single pass:

    if (x < y) {
      // ... 50 lines of code ...
    }
    // Target Line Unknown!

    The compiler evaluates x < y and needs to emit a jump for the false condition. But the target address (after the 50 lines) hasn't been generated yet.

    Two-Pass Compilation

    Pass 1 records block ends. Pass 2 generates code. Simple but slow and memory-heavy.

    Backpatching (One-Pass)

    Emit goto _ with a blank target. Record the location. "Patch" the address when the target is finally reached.

    Syntax-Directed Translation and Intermediate Representations: Solved Questions with Step-by-Step Explanations (9 Problems)

    Question 1 · Compiler Design · 2026_Set1 MSQ
    Consider the following two syntax-directed definitions SDD1 and SDD2 for type declarations.

    SDD1SDD2
    Grammar
    (G1)
    Semantic RulesGrammar
    (G2)
    Semantic Rules






    is the start symbol, and , and are the three terminals. The non-terminal is the same as and the non-terminal is the same as . Here, the subscript is used to differentiate the grammar symbols on the two sides of a production. The function updates the symbol table with the type information for an identifier.

    Let P and Q be the languages specified by grammars G1 and G2, respectively.

    Which of the following statements is/are true?
    1. A.

      The languages P and Q are the same

    2. B.

      SDD2 is S-attributed and contains only synthesized attributes

    3. C.

      SDD1 is L-attributed and contains only inherited attributes

    4. D.

      The specifications of SDD1 and SDD2 are such that the same entries get added to the symbol table

    Question 2 · Compiler Design · 2025_Set2 MCQ
    Consider the following statements about the use of backpatching in a compiler for intermediate code generation:

    (I) Backpatching can be used to generate code for Boolean expression in one pass.
    (II) Backpatching can be used to generate code for flow-of-control statements in one pass.

    Which ONE of the following options is CORRECT?
    1. A.

      Only (I) is correct.

    2. B.

      Only (II) is correct.

    3. C.

      Both (I) and (II) are correct.

    4. D.

      Neither (I) nor (II) is correct.

    Question 3 · Compiler Design · 2025_Set2 MCQ
    Given the following syntax directed translation rules:

    Rule 1:
    Rule 2:
    Rule 3:

    Which ONE is the CORRECT option among the following?
    1. A.

      Rule 1 is S-attributed and L-attributed; Rule 2 is S-attributed and not L-attributed; Rule 3 is neither S-attributed nor L-attributed

    2. B.

      Rule 1 is neither S-attributed nor L-attributed; Rule 2 is S-attributed and L-attributed; Rule 3 is S-attributed and L-attributed

    3. C.

      Rule 1 is neither S-attributed nor L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed

    4. D.

      Rule 1 is S-attributed and not L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed

    Question 4 · Compiler Design · 2024_Set2 MCQ
    Consider the following expression: . The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6).

    (0)+pr(1)(2)uminus(1)(3)(4)/uw(5)+(3)(4)(6)(7)=(6)(5)

    Which one of the following options fills in the missing entries CORRECTLY?
    1. A.

    2. B.

    3. C.

    4. D.

    Question 5 · Compiler Design · 2024_Set2 MSQ

    Which of the following statements is/are FALSE?

    1. A.

      An attribute grammar is a syntax-directed definition (SDD) in which the functions in the semantic rules have no side effects

    2. B.

      The attributes in a L-attributed definition cannot always be evaluated in a depth-first order

    3. C.

      Synthesized attributes can be evaluated by a bottom-up parser as the input is parsed

    4. D.

      All L-attributed definitions based on LR(1) grammar can be evaluated using a bottom-up parsing strategy

    Question 6 · Compiler Design · 2024_Set1 MCQ
    Consider the following syntax-directed definition (SDD).

      
      
      
      
      
      
      
      

    Given "MMLK" as the input, which one of the following options is the CORRECT value computed by the SDD (in the attribute )?
    1. A.

    2. B.

    3. C.

    4. D.

    Question 7 · Compiler Design · 2023 NAT
    Consider the syntax directed translation given by the following grammar and semantic rules. Here , , and are non-terminals. is the starting non-terminal, and #, 0 and 1 are lexical tokens corresponding to input letters “#”, “0” and “1”, respectively. denotes the synthesized attribute (a numeric value) associated with a non-terminal . and denote occurrences of and on the right hand side of a production, respectively. For the tokens 0 and 1, and .


    The value computed by the translation scheme for the input string


    is __________. (Rounded off to three decimal places)
    Question 8 · Compiler Design · 2022 NAT
    Consider the following grammar along with translation rules. Here # and % are operators and is a token that represents an integer and represents the corresponding integer value. The set of non-terminals is and a subscripted non-terminal indicates an instance of the non-terminal.

    Using this translation scheme, the computed value of for root of the parse tree for the expression is_____________.
    Question 9 · Compiler Design · 2021_Set2 MSQ

    In the context of compilers, which of the following is/are NOT an intermediate representation of the source program?

    1. A.

      Three address code

    2. B.

      Abstract Syntax Tree (AST)

    3. C.

      Control Flow Graph (CFG)

    4. D.

      Symbol table

    More previous year questions (pyqs) in this unit