Back to Study Material GATE Exam

Compiler Design Previous Year Questions

Compiler Design previous year questions in GATE cluster into predictable categories. The most frequent category is parsing, which has appeared in every GAT...

Compiler Design Previous Year Questions

PYQ Patterns in Lexical Analysis and Parsing

Compiler Design previous year questions in GATE cluster into predictable categories. The most frequent category is parsing, which has appeared in every GATE CS paper from 2010 through 2024 without exception. Lexical analysis questions appear less frequently but are reliably straightforward when they do.

Lexical analysis questions in GATE typically ask about the number of tokens in a given source code snippet. For example, GATE 2012 gave a small C-like expression and asked how many tokens the lexer would produce. The answer requires you to correctly identify each identifier, keyword, operator, delimiter, and literal as a separate token. White space is not a token. Comments are not tokens. A common trap is counting a multi-character operator like less-than-equals as two tokens when it is actually one.

FIRST and FOLLOW computation has appeared repeatedly. GATE 2015 gave a context-free grammar for arithmetic expressions and asked for FOLLOW of a specific nonterminal. The answer requires careful application of the FOLLOW rules, tracing through all productions where the nonterminal appears on the right side. These questions are fully mechanical and should be answered without making errors if you have practiced the algorithm.

LL(1) parsing table questions ask you to fill in specific cells or identify conflicts. GATE 2018 gave a grammar and asked which of four given entries in the LL(1) table was correct. Verifying each option by computing FIRST and FOLLOW and applying the table construction rule is faster than constructing the entire table.

SLR(1) item set questions ask you to compute the closure of a given set of items or to identify which action to take in a given state for a given input. GATE 2016 gave a grammar and asked for the number of states in the SLR(1) automaton. This requires constructing all LR(0) item sets, which is time-consuming but systematic.

Conflict identification questions present a grammar and ask whether it is SLR(1), LALR(1), or neither. The key is identifying shift-reduce or reduce-reduce conflicts in the parsing table. GATE 2020 asked whether a specific grammar was LL(1) or not, requiring you to check FIRST set disjointness for alternatives of each nonterminal.

A practical strategy: for each GATE paper from 2015 to 2024, locate the Compiler Design questions and categorize them. You will find that FIRST-FOLLOW computation and LR item set construction together account for roughly half of all Compiler Design marks in the exam. Focused practice on these two skill types is the highest return-on-investment activity for this subject.

PYQ Patterns in Semantic Analysis and Attribute Grammars

Semantic analysis and attribute grammar questions in GATE Compiler Design are among the most conceptually interesting and are worth studying carefully because they require applying a procedure precisely to a given grammar, leaving little room for guessing.

Attribute grammar questions give you a grammar with semantic rules attached to productions and ask you to evaluate a specific attribute for a given input string. GATE 2014 gave a grammar for arithmetic expressions with rules that computed the value of each subexpression as a synthesized attribute, and asked for the value at the root when parsing a specific expression. The approach: build the parse tree for the input, annotate each node using the semantic rules, and read off the root attribute.

A critical distinction tested in GATE is between synthesized and inherited attributes. GATE 2017 gave a grammar with a mix of attribute types and asked which attributes were synthesized and which were inherited. An attribute is synthesized if its value is defined by a rule in a production where the attribute's nonterminal is on the left side. It is inherited if defined by a rule where the nonterminal is on the right side.

S-attributed versus L-attributed questions ask you to classify a grammar or to determine what evaluation order is needed. S-attributed grammars can be evaluated during a single bottom-up pass, making them compatible with LR parsers. L-attributed grammars can be evaluated during a single left-to-right top-down pass, making them compatible with recursive descent parsers. GATE has asked whether specific grammars satisfy these definitions.

Type checking questions are less frequent but have appeared. GATE 2011 described a type system and asked whether a given expression would pass type checking under the stated rules. These require you to apply the type rules mechanically to each subexpression.

Symbol table questions sometimes appear embedded in a larger question about compilation. A question might describe a program with nested scopes and ask which declarations are visible at a specific point, or ask what happens when a variable in an inner scope shadows one in an outer scope.

For preparation, collect all GATE attribute grammar questions from 2010 to 2024. You will find that annotation of parse trees is the core skill. Practice annotating parse trees for five different grammars with synthesized attributes and three with inherited attributes. This variety prepares you for any phrasing the exam might use.

PYQ Patterns in Code Generation and Optimization

Code generation and optimization questions in GATE Compiler Design test a different skill set from parsing questions. They require you to trace the effect of optimizations on concrete code fragments, recognize optimization opportunities, and reason about the correctness of transformations.

Three-address code questions present a high-level code fragment and ask you to write the corresponding three-address code, or vice versa. GATE 2013 gave a while loop with a conditional and an assignment and asked how many three-address instructions the compiler would generate. The answer requires understanding how control flow constructs expand into conditional jumps in three-address code. Each conditional becomes a comparison instruction and a conditional jump. Each iteration of the loop requires a jump back to the loop test.

Basic block identification questions give you a sequence of three-address instructions and ask you to partition them into basic blocks. The rules are: a new basic block starts at the first instruction, at any instruction that is the target of a jump, and at any instruction immediately following a jump. The number of basic blocks is often asked.

Optimization tracing questions give you a sequence of three-address instructions and ask what the sequence looks like after applying a specific optimization. GATE 2019 gave a code fragment with a constant assigned to a variable, then that variable used in a computation, and asked how many instructions remain after constant propagation and dead code elimination. The answer requires tracing propagation first, then identifying dead variables.

Loop optimization questions ask about invariant code motion. A computation inside a loop that does not depend on any variable modified within the loop is invariant and can be hoisted outside. GATE has asked students to identify which expressions in a loop body are invariant.

Dataflow analysis questions are less frequent but have appeared. A question might ask for the set of live variables at a program point, or the set of reaching definitions at a point. These require applying the dataflow equations iteratively until a fixed point is reached.

The key insight for code optimization questions in GATE is that each optimization has a precise definition and a mechanical application procedure. Constant folding: evaluate constant expressions. Dead code elimination: remove assignments to variables never subsequently read. Common subexpression elimination: find identical expressions computed at two points and save the result. Practice identifying which optimization applies to each type of redundancy.