Previous year questions
Compiler Design
94 questions from GATE CS 2011 to 2026, newest first.
Topics
All Compiler Design questions
GATE CS 2026 Set 1, Q.27
Consider the following C statements: char str1 = "Hello; / Statement S1 */ char str2 = "Hello;"; / Statement S2 */ int str3 = "Hello"; / Statement S3 */ Which of the follo...
Lexical Analysis
GATE CS 2026 Set 1, Q.28
Which of the following statements is/are true?
Parsing and Syntax Analysis (LL and LR)
GATE CS 2026 Set 1, Q.42
Consider the control flow graph shown in the figure. Control flow graph with ENTRY leading to basic block B1 (a = b + i), which branches to B2 (a = g * k; f = d - f; a = c * 4)...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2026 Set 1, Q.53
Consider the following two syntax-directed definitions SDD1 and SDD2 for type declarations. SDD1 Grammar (G1) SDD1 Semantic Rules SDD2 Grammar (G2) SDD2 Semantic Rules…
Syntax-Directed Translation
GATE CS 2026 Set 2, Q.17
In C runtime environment, which one of the following is stored in heap?
Runtime Environments and Parameter Passing
GATE CS 2026 Set 2, Q.29
Which of the following grammars is/are ambiguous?
Parsing and Syntax Analysis (LL and LR)
GATE CS 2026 Set 2, Q.35
A lexical analyzer uses the following token definitions - - - -…
Lexical Analysis
GATE CS 2026 Set 2, Q.41
Consider the canonical parsing of the grammar below using terminals and non-terminals with as the start symbol. ...
Parsing and Syntax Analysis (LL and LR)
GATE CS 2026 Set 2, Q.45
Consider the control flow graph given below. Control flow graph with ENTRY leading to basic block B1 (a = b + c); B1 branches to B2 (d = a + e) and B3 (e = a + f); B3 loops back...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2025 Set 1, Q.12
Which ONE of the following statements is FALSE regarding the symbol table?
Lexical Analysis
GATE CS 2025 Set 1, Q.13
Which ONE of the following techniques used in compiler code optimization uses live variable analysis?
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2025 Set 1, Q.46
Which of the following statement(s) is/are TRUE while computing First and Follow during top down parsing by a compiler?
Parsing and Syntax Analysis (LL and LR)
GATE CS 2025 Set 1, Q.52
Refer to the given 3-address code sequence. This code sequence is split into basic blocks. The number of basic blocks is ________. (Answer in integer) 1001: i = 1 1002: j = 1 10...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2025 Set 2, Q.21
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 express...
Intermediate Code Generation, Data Flow Analysis and Code Optimization · Syntax-Directed Translation
GATE CS 2025 Set 2, Q.22
Given the following syntax directed translation rules: Rule 1: Rule 2…
Syntax-Directed Translation
GATE CS 2025 Set 2, Q.40
Given a Context-Free Grammar as follows: Which ONE of the following statements is TRUE?
Parsing and Syntax Analysis (LL and LR)
GATE CS 2025 Set 2, Q.51
Consider two grammars and with the production rules given below…
Parsing and Syntax Analysis (LL and LR)
GATE CS 2024 Set 1, Q.26
Which of the following is/are Bottom-Up Parser(s)?
Parsing and Syntax Analysis (LL and LR)
GATE CS 2024 Set 1, Q.33
Consider the operator precedence and associativity rules for the integer arithmetic operators given in the table below. Operator Precedence Associativity + Highest Left - High R...
Parsing and Syntax Analysis (LL and LR)
GATE CS 2024 Set 1, Q.37
Consider the following syntax-directed definition (SDD).…
Syntax-Directed Translation
GATE CS 2024 Set 1, Q.38
Consider the following grammar , with as the start symbol. The grammar has three incomplete productions denoted by (1), (2), and (3).…
Parsing and Syntax Analysis (LL and LR)
GATE CS 2024 Set 1, Q.39
Consider the following pseudo-code. L1: t1 = -1 L2: t2 = 0 L3: t3 = 0 L4: t4 = 4 * t3 L5: t5 = 4 * t2 L6: t6 = t5 * M L7: t7 = t4 + t6 L8: t8 = a[t7] L9: if t8 <= max goto L11 L...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2024 Set 2, Q.21
Consider the following two sets: Set X Set Y P. Lexical Analyzer 1. Abstract Syntax Tree Q. Syntax Analyzer 2. Token R. Intermediate Code Generator 3. Parse Tree S. Code Optimiz...
Lexical Analysis · Parsing and Syntax Analysis (LL and LR) · Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2024 Set 2, Q.29
Which of the following statements is/are FALSE?
Syntax-Directed Translation
GATE CS 2024 Set 2, Q.40
Consider the following context-free grammar where the start symbol is and the set of terminals is . …
Parsing and Syntax Analysis (LL and LR)
GATE CS 2024 Set 2, Q.43
Consider the following expression: . The following sequence shows the list of triples representing the given expression, with entries missing for t...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2024 Set 2, Q.65
Consider the following augmented grammar, which is to be parsed with a SLR parser. The set of terminals is …
Parsing and Syntax Analysis (LL and LR)
GATE CS 2023, Q.11
Consider the following statements regarding the front-end and back-end of a compiler. S1: The front-end includes phases that are independent of the target hardware. S2: The back...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2023, Q.19
Consider the following definition of a lexical token id for an identifier in a programming language, using extended regular expressions…
Lexical Analysis
GATE CS 2023, Q.37
Consider the control flow graph shown. Control flow graph with basic blocks B1 (i = m - 1, j = n, a = 10), B2 (i = i + 1, j = j - 1), B3 (a = 20), and B4 (i = a + 1), edges ENTR...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2023, Q.60
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...
Syntax-Directed Translation
GATE CS 2022, Q.13
Which one of the following statements is TRUE?
Parsing and Syntax Analysis (LL and LR)
GATE CS 2022, Q.29
Consider the augmented grammar with as the set of terminals. …
Parsing and Syntax Analysis (LL and LR)
GATE CS 2022, Q.65
Consider the following grammar along with translation rules. …
Syntax-Directed Translation
GATE CS 2021 Set 1, Q.14 (CS Q.4)
Consider the following statements. : The sequence of procedure calls corresponds to a preorder traversal of the activation tree. : The sequence of procedure returns co...
Runtime Environments and Parameter Passing
GATE CS 2021 Set 1, Q.15 (CS Q.5)
Consider the following statements. : Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1). : For any context-free grammar...
Parsing and Syntax Analysis (LL and LR)
GATE CS 2021 Set 1, Q.36 (CS Q.26)
Consider the following grammar (that admits a series of declarations, followed by expressions) and the associated syntax directed translation (SDT) actions, given as pseudo-code...
Syntax-Directed Translation
GATE CS 2021 Set 1, Q.41 (CS Q.31)
Consider the following context-free grammar where the set of terminals is . …
Parsing and Syntax Analysis (LL and LR)
GATE CS 2021 Set 1, Q.60 (CS Q.50)
Consider the following C code segment: a = b + c; e = a + 1; d = b + c; f = d + 1; g = e + f; In a compiler, this code segment is represented internally as a directed a...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2021 Set 2, Q.13 (CS Q.3)
Consider the following ANSI C program: int main() { Integer x; return 0; } Which one of the following phases in a seven-phase C compiler will throw an error?
Parsing and Syntax Analysis (LL and LR) · Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2021 Set 2, Q.23 (CS Q.13)
In the context of compilers, which of the following is/are NOT an intermediate representation of the source program?
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2021 Set 2, Q.40 (CS Q.30)
Consider the following ANSI C code segment: z = x + 3 + y->f1 + y->f2; for (i = 0; i < 200; i = i + 2) { if (z > i) { p = p + x + 3; q = q + y->f1; } else { p = p + y->f2;...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2021 Set 2, Q.48 (CS Q.38)
For a statement in a program, in the context of liveness analysis, the following sets are defined: …
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2021 Set 2, Q.61 (CS Q.51)
Consider the following augmented grammar with as the set of terminals.…
Parsing and Syntax Analysis (LL and LR)
GATE CS 2020, Q.19 (CS Q.9)
Consider the following statements. I. Symbol table is accessed only during lexical analysis and syntax analysis. II. Compilers for programming languages that support recursion n...
Runtime Environments and Parameter Passing · Parsing and Syntax Analysis (LL and LR) · Parsing and Syntax Analysis (LL and LR)
GATE CS 2020, Q.34 (CS Q.24)
Consider the following grammar. The number of reduction steps taken by a bottom-up parser while accepting the s...
Parsing and Syntax Analysis (LL and LR)
GATE CS 2020, Q.43 (CS Q.33)
Consider the productions and . Each of the five non-terminals , and has two attributes: is a synthesized attribute, and is an inhe...
Syntax-Directed Translation
GATE CS 2019, Q.13 (CS Q.3)
Which one of the following kinds of derivation is used by LR parsers?
Parsing and Syntax Analysis (LL and LR)
GATE CS 2019, Q.29 (CS Q.19)
Consider the grammar given below: Let and be indexed...
Parsing and Syntax Analysis (LL and LR)
GATE CS 2019, Q.46 (CS Q.36)
Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let and be the placeholders for th...
Syntax-Directed Translation
GATE CS 2019, Q.53 (CS Q.43)
Consider the augmented grammar given below: Let…
Parsing and Syntax Analysis (LL and LR)
GATE CS 2018, Q.18 (CS Q.8)
Which one of the following statements is FALSE?
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2018, Q.47 (CS Q.37)
A lexical analyzer uses the following patterns to recognize three tokens T1, T2, and T3 over the alphabet .…
Lexical Analysis
GATE CS 2018, Q.48 (CS Q.38)
Consider the following parse tree for the expression
a#b$c$d#e#f, involving two binary operators$and#. Parse tree for the expression a#bd#e#f showing precedence and...Parsing and Syntax Analysis (LL and LR)
GATE CS 2017 Set 1, Q.12 (CS Q.12)
Consider the following intermediate program in three address code: p = a - b q = p * c p = u * v q = p + q Which one of the following corresponds to a static single assi...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2017 Set 1, Q.17 (CS Q.17)
Consider the following grammar: What is ?
Parsing and Syntax Analysis (LL and LR)
GATE CS 2017 Set 1, Q.43 (CS Q.43)
Consider the following grammar: stmt -> if expr then expr else expr; stmt | 0 expr -> term relop term | term term -> id | number id -> a | b | c number -> [0-9] where…
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2017 Set 1, Q.52 (CS Q.52)
Consider the expression . Let be the minimum number of registers required by an optimal code generation (without any register spill) algorithm...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2017 Set 2, Q.5 (CS Q.5)
Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it: | Input | Compiler Phase | | :--- | :--- | | (P) Syn...
Lexical Analysis · Parsing and Syntax Analysis (LL and LR)
GATE CS 2017 Set 2, Q.6 (CS Q.6)
Which of the following statements about parser is/are CORRECT? I. Canonical LR is more powerful than SLR. II. SLR is more powerful than LALR. III. SLR is more powerful than Cano...
Parsing and Syntax Analysis (LL and LR)
GATE CS 2017 Set 2, Q.32 (CS Q.32)
Consider the following expression grammar : Which of the following g...
Parsing and Syntax Analysis (LL and LR)
GATE CS 2016 Set 1, Q.29 (CS Q.19)
Consider the following code segment. x = u - t; y = x * v; x = y + w; y = t - z; y = x * y; The minimum number of total variables required to convert the above code...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2016 Set 1, Q.46 (CS Q.36)
What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed? a = 3; void n(x) { x = x * a; print(x); } vo...
Runtime Environments and Parameter Passing
GATE CS 2016 Set 1, Q.56 (CS Q.46)
Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals and terminals …
Syntax-Directed Translation
GATE CS 2016 Set 2, Q.29 (CS Q.19)
Match the following: (P) Lexical analysis (Q) Top down parsing (R) Semantic analysis (S) Runtime environments (i) Leftmost derivation (ii) Type checking (iii) Regular expression...
Lexical Analysis
GATE CS 2016 Set 2, Q.55 (CS Q.45)
Which one of the following grammars is free from left recursion?
Parsing and Syntax Analysis (LL and LR)
GATE CS 2016 Set 2, Q.56 (CS Q.46)
A student wrote two context-free grammars and for generating a single C-like array declaration. The dimension of the array is at least one. For example, int a[1...
Parsing and Syntax Analysis (LL and LR) · Context-Free Grammars, Pushdown Automata and CFLs
GATE CS 2015 Set 1, Q.23 (CS Q.13)
Which one of the following is TRUE at any valid state in shift-reduce parsing?
Parsing and Syntax Analysis (LL and LR)
GATE CS 2015 Set 1, Q.60 (CS Q.50)
A variable is said to be live at a statement in a program if the following three conditions hold simultaneously: i. There exists a statement that uses ii. Th...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2015 Set 1, Q.65 (CS Q.55)
The least number of temporary variables required to create a three-address code in static single assignment form for the expression is _____.
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2015 Set 2, Q.24 (CS Q.14)
In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the following is TRUE?
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2015 Set 2, Q.29 (CS Q.19)
Match the following compiler phases / tasks with their underlying algorithmic techniques: List-I P. Lexical analysis Q. Parsing R. Register allocation S. Expression evaluati...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2015 Set 2, Q.39 (CS Q.29)
Consider the intermediate code given below. (1) i = 1 (2) j = 1 (3) t1 = 5 * i (4) t2 = t1 + j (5) t3 = 4 * t2 (6) t4 = t3 (7) a[t4] = -1 (8) j = j + 1 (9) if j<=5 goto (3) (10)...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2015 Set 3, Q.26 (CS Q.16)
Among simple LR (SLR), canonical LR, and look-ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and the method that is the most po...
Parsing and Syntax Analysis (LL and LR)
GATE CS 2015 Set 3, Q.41 (CS Q.31)
Consider the following grammar where and are non-terminal symbols…
Parsing and Syntax Analysis (LL and LR)
GATE CS 2014 Set 1, Q.27 (CS Q.17)
Which one of the following is FALSE?
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2014 Set 1, Q.44 (CS Q.34)
A canonical set of items is given below On input symbol the set has
Parsing and Syntax Analysis (LL and LR)
GATE CS 2014 Set 2, Q.27 (CS Q.17)
Consider the grammar defined by the following production rules, with two operators and …
Parsing and Syntax Analysis (LL and LR)
GATE CS 2014 Set 2, Q.28 (CS Q.18)
Which one of the following is NOT performed during compilation?
Runtime Environments and Parameter Passing
GATE CS 2014 Set 2, Q.44 (CS Q.34)
For a C program accessing
X[i][j][k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of a character is...Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2014 Set 3, Q.27 (CS Q.17)
One of the purposes of using intermediate code in compilers is to
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2014 Set 3, Q.28 (CS Q.18)
Which of the following statements are CORRECT? 1) Static allocation of all data areas by a compiler makes it impossible to implement recursion. 2) Automatic garbage collection i...
Runtime Environments and Parameter Passing
GATE CS 2014 Set 3, Q.44 (CS Q.34)
Consider the basic block given below. a = b + c c = a + d d = b + c e = d - b a = e + b The minimum number of nodes and edges present in the DAG representation of th...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2013, Q.9 (CS Q.9)
What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon- and unit-production (i.e., of type and…
Parsing and Syntax Analysis (LL and LR)
GATE CS 2013, Q.40 (CS Q.40)
Consider the following two sets of LR(1) items of an LR(1) grammar.…
Parsing and Syntax Analysis (LL and LR)
GATE CS 2013, Q.48 (CS Q.48)
Suppose the instruction set architecture of the processor has only two registers. The only allowed compiler optimization is code motion, which moves statements from one place to...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2013, Q.49 (CS Q.49)
What is the minimum number of registers needed in the instruction set architecture of the processor to compile this code segment without any spill to memory? Do not apply any op...
Intermediate Code Generation, Data Flow Analysis and Code Optimization
GATE CS 2012, Q.36 (CS Q.36)
Consider the program given below, in a block-structured pseudo-language with lexical scoping and nesting of procedures permitted. Program main; Var ... Procedure A1; V...
Runtime Environments and Parameter Passing
GATE CS 2012, Q.52 (CS Q.52)
The FIRST and FOLLOW sets for the non-terminals A and B are
Parsing and Syntax Analysis (LL and LR)
GATE CS 2012, Q.53 (CS Q.53)
The appropriate entries for E1, E2, and E3 are
Parsing and Syntax Analysis (LL and LR)
GATE CS 2011, Q.1 (CS Q.1)
In a compiler, keywords of a language are recognized during
Lexical Analysis
GATE CS 2011, Q.19 (CS Q.19)
The lexical analysis for a modern computer language such as Java needs the power of which one of the following machine models in a necessary and sufficient sense?
Lexical Analysis
GATE CS 2011, Q.27 (CS Q.27)
Consider two binary operators '' and '' with the precedence of operator being lower than that of operator . Operator is r...
Parsing and Syntax Analysis (LL and LR)
GATE CS 2011, Q.36 (CS Q.36)
Consider evaluating the following expression tree on a machine with load-store architecture in which memory can be accessed only through load and store instructions. The variabl...
Intermediate Code Generation, Data Flow Analysis and Code Optimization