chapter
    Compiler Design PYQs for GATE CS

    GATE CS Compiler Design: 6 chapters, 43 previous year questions (100% of Compiler Design), 25 practice questions and one solved question from each chapter.

    A question from this chapter

    Question 1
    2026 Slot Set2 PYQ
    Level 3: Exam Standard
    A lexical analyzer uses the following token definitions

    •
    •
    •
    •
    •

    For the string given below,


    the number of tokens (excluding ) that will be produced by the lexical analyzer is __________. (answer in integer)
    Question 2
    2026 Slot Set1 PYQ

    Which of the following statements is/are true?

    Question 3
    2026 Slot Set2 PYQ
    Consider the canonical parsing of the grammar below using terminals and non-terminals with as the start symbol.





    Which one of the following options gives the number of shift-reduce conflicts that will occur in the ACTION table?
    Question 4
    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 5
    2023 PYQ
    Consider the following program:

    int main()
    {
       f1();
       f2(2);
       f3();
       return(0);
    }

    int f1()
    {
       return(1);
    }

    int f2(int X)
    {
       f3();
       if (X==1)
          return f1();
       else
          return (X*f2(X-1));
    }

    int f3()
    {
       return(5);
    }

    Which one of the following options represents the activation tree corresponding to the main function?
    Question 6
    2026 Slot Set2 PYQ
    Consider the control flow graph given below.
    ENTRY B1 a = b + c B2 d = a + e B3 e = a + f B4 g = d + e EXIT Which one of the following options is the set of live variables at the exit point of each basic block?
    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.

    Compiler Design PYQs for GATE CS

    GATE CS Compiler Design: 6 chapters, 43 previous year questions (100% of Compiler Design), 25 practice questions and one solved question from each chapter.

    About Compiler Design Previous Year Questions (PYQs)

    43 previous year questions from Compiler Design in GATE CS, grouped by chapter with the exam year, answer key and step-by-step solution for each.

    Compiler Design Weightage in GATE CS

    Compiler Design accounts for 43 of 43 Compiler Design previous year questions in our bank (100%), about 4.3 per paper across 10 papers.

    Compiler Design Chapter Matrix

    ChapterTopicsPYQsShare of unit PYQsPractice questions
    Compiler Phases, Lexical Analysis and Semantic ProcessingCompiler Phases, Front-End, Back-End and Symbol Tables, Lexical Tokens, Regular Expressions and Finite Automata, Semantic Analysis and Syntax-Directed Type Checking, Lexical, Syntax and Semantic Error Classification921%25
    Top-Down and Predictive ParsingFIRST and FOLLOW Set Computation, LL(1) Grammar Conditions and Predictive Parsing, LL(1) Parsing Table Construction614%0
    Bottom-Up and LR ParsingBottom-Up Parser Types and LR Grammar Classes, Operator Precedence and Shift-Reduce Parsing, LR Item Closure and GOTO Computation, LR Parsing Conflicts and Grammar Ambiguity819%0
    Syntax-Directed Translation and Intermediate RepresentationsBackpatching and Control-Flow Code Generation, Syntax-Directed Definitions and Attribute Evaluation, Intermediate Representations and Triple Code921%0
    Runtime Environments and Procedure CallsActivation Trees and Procedure Call Sequences25%0
    Basic Blocks, Data-Flow Analysis and Code OptimizationBasic Blocks and Control-Flow Graph Construction, Live Variables and Data-Flow Analysis, DAG Optimization, Common Subexpressions and Available Expressions921%0

    More from Compiler Design

    One Solved Question from Each Compiler Design Chapter

    Question 1 · Compiler Phases, Lexical Analysis and Semantic Processing · 2026_Set2 NAT
    A lexical analyzer uses the following token definitions

    •
    •
    •
    •
    •

    For the string given below,


    the number of tokens (excluding ) that will be produced by the lexical analyzer is __________. (answer in integer)
    Correct Answer:

    13

    Step-by-Step Solution

    Key idea: Apply the maximal munch rule (longest match) to tokenize the input string based on the given regular expressions.

    Step 1: The input string is separated by whitespace. We process each space-separated chunk.

    Step 2: x1 starts with a letter and is followed by a digit. Matches id. (1 token)

    Step 3: 23mm starts with digits. The longest match for number is 23. The remaining mm matches id. (2 tokens)

    Step 4: 78 matches number. (1 token)

    Step 5: y matches id. (1 token)

    Step 6: 7z starts with a digit. 7 matches number. z matches id. (2 tokens)

    Step 7: zz5 starts with a letter, followed by letters/digits. Matches id. (1 token)

    Step 8: 14A starts with digits. 14 matches number. A matches id. (2 tokens)

    Step 9: 8H starts with a digit. 8 matches number. H matches id. (2 tokens)

    Step 10: AaYcD starts with a letter, followed by letters. Matches id. (1 token)

    Step 11: Sum the tokens: 1 + 2 + 1 + 1 + 2 + 1 + 2 + 2 + 1 = 13.

    Answer: 13

    Question 2 · Top-Down and Predictive Parsing · 2026_Set1 MSQ

    Which of the following statements is/are true?

    1. A.

      LL(1) parser uses backtracking

    2. B.

      For a grammar to be LL(1), it must be left-recursive

    3. C.

      For a grammar to be LL(1), it must be left-factored

    4. D.

      The LL(1) parsers are more powerful than the SLR parsers

    Question 3 · Bottom-Up and LR Parsing · 2026_Set2 MCQ
    Consider the canonical parsing of the grammar below using terminals and non-terminals with as the start symbol.





    Which one of the following options gives the number of shift-reduce conflicts that will occur in the ACTION table?
    1. A.

      2

    2. B.

      3

    3. C.

      4

    4. D.

      5

    Question 4 · Syntax-Directed Translation and Intermediate Representations · 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 5 · Runtime Environments and Procedure Calls · 2023 MCQ
    Consider the following program:

    int main()
    {
       f1();
       f2(2);
       f3();
       return(0);
    }

    int f1()
    {
       return(1);
    }

    int f2(int X)
    {
       f3();
       if (X==1)
          return f1();
       else
          return (X*f2(X-1));
    }

    int f3()
    {
       return(5);
    }

    Which one of the following options represents the activation tree corresponding to the main function?
    1. A. mainf1f2f3f3f2f3f1
    2. B. mainf1f2f3f3f1
    3. C. mainf1f2f3f1
    4. D. mainf1f2f3f3f2f1
    Question 6 · Basic Blocks, Data-Flow Analysis and Code Optimization · 2026_Set2 MCQ
    Consider the control flow graph given below.
    ENTRY B1 a = b + c B2 d = a + e B3 e = a + f B4 g = d + e EXIT Which one of the following options is the set of live variables at the exit point of each basic block?
    1. A.

      B1:{a, b, c, e, f}, B2:{d, e}, B3:{b, c, e, f}, B4:

    2. B.

      B1:, B2:{d, e}, B3:{a, c, f}, B4:

    3. C.

      B1:{a, b, c, e, f}, B2:{d, e}, B3:{c, e, f}, B4:

    4. D.

      B1:, B2:{d, e, f}, B3:{a, b, c, e, f}, B4: