GATE CS Compiler Design: 1 units and 6 chapters, weightage from 43 previous year questions across 10 papers, a study order by exam weight and 1202 practice qu
A question from this chapter
Question 1
Level 1: Warm-up
Which compiler phase is responsible for reading the source code character stream and grouping it into meaningful units called tokens?
Question 2
Level 1: Warm-up
Consider the grammar:
S→aA∣bB
A→c∣ε
B→d
with terminals {a,b,c,d} and end marker \.LetX,Y,andZbethenumberofentriesfilledintheLL(1)parsingtablefornon−terminalsS,A,andB$ respectively.
Rank X, Y, Z from largest to smallest.
Question 3
Level 1: Warm-up
Which ONE of the following statements about the LR parser hierarchy is TRUE?
Question 4
Level 1: Warm-up
Which of the following statements is strictly TRUE regarding the attribute dependency graph for a specific parse tree in a syntax-directed definition?
Question 5
Level 1: Warm-up
Consider the following program:
\begin{verbatim}
void F(int n) {
if (n > 1) {
G();
F(n - 1);
F(n - 2);
}
}
void G() { }
\end{verbatim}
\textbf{Assertion (A):} If main calls F(3), the total number of activation records for function F is 5.
\textbf{Reason (R):} The function F is invoked exactly 5 times during this execution.
Which of the following is correct?
Question 6
Level 1: Warm-up
A basic block is defined by having exactly E entry points and X exit points to ensure safe boundaries for optimization algorithms. What is the value of E+X?
Free preview ends here
Login to view the complete short notes
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.
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.
GATE CS Compiler Design: 1 units and 6 chapters, weightage from 43 previous year questions across 10 papers, a study order by exam weight and 1202 practice questions.
About Compiler Design Short Notes
Quick revision sheets for Compiler Design in GATE CS. Every chapter is condensed into key formulas, shortcuts and common traps so you can revise 6 chapters fast before the exam.
GATE CS Compiler Design Unit-wise Weightage from Past Papers
We counted every GATE CS Compiler Design previous year question in our bank (43 questions from 10 papers) and grouped them by unit.
One Solved Question from Each Compiler Design Chapter
Question 1 · Compiler Phases, Lexical Analysis and Semantic ProcessingMCQ
Which compiler phase is responsible for reading the source code character stream and grouping it into meaningful units called tokens?
A.
Lexical Analyzer
B.
Syntax Analyzer
C.
Semantic Analyzer
D.
Intermediate Code Generator
Correct Answer:
A
Step-by-Step Solution
Key idea: This is a direct recall question about compiler phase responsibilities.
Step 1: Recall the primary function of the Lexical Analyzer. It scans the source code character by character and groups them into meaningful sequences called tokens (e.g., keywords, identifiers, operators).
Step 2: Verify other options. Syntax Analyzer builds parse trees from tokens. Semantic Analyzer checks for logical consistency and type compatibility. Intermediate Code Generator produces an abstract intermediate representation.
Answer: A
Question 2 · Top-Down and Predictive ParsingMCQ
Consider the grammar:
S→aA∣bB
A→c∣ε
B→d
with terminals {a,b,c,d} and end marker \.LetX,Y,andZbethenumberofentriesfilledintheLL(1)parsingtablefornon−terminalsS,A,andB$ respectively.
Rank X, Y, Z from largest to smallest.
A.
X>Y>Z
B.
X=Y>Z
C.
Y>X>Z
D.
X>Z>Y
Correct Answer:
B
Step-by-Step Solution
Key idea: Count table entries for each non-terminal based on FIRST and FOLLOW sets.
Step 1: Compute FOLLOW sets:
\mathrm{FOLLOW}(S) = \{\\}$ (start symbol)
\mathrm{FOLLOW}(A) = \{\\}(sinceS \to aA,A$ is at the end)
\mathrm{FOLLOW}(B) = \{\\}(sinceS \to bB,B$ is at the end)
Which ONE of the following statements about the LR parser hierarchy is TRUE?
A.
Every LALR(1) grammar is also SLR(1)
B.
Every SLR(1) grammar is also LALR(1)
C.
Every CLR(1) grammar is also LALR(1)
D.
LR(0) and SLR(1) have equal parsing power
Correct Answer:
B
Step-by-Step Solution
Key idea: The LR parser hierarchy follows a strict subset relationship: LR(0)⊂SLR(1)⊂LALR(1)⊂CLR(1).
Step 1: Recall the hierarchy:
Every LR(0) grammar is SLR(1), but not vice versa
Every SLR(1) grammar is LALR(1), but not vice versa
Every LALR(1) grammar is CLR(1), but not vice versa
Step 2: Evaluate each option:
"Every LALR(1) is SLR(1)": FALSE — LALR(1) is more powerful than SLR(1)
"Every SLR(1) is LALR(1)": TRUE — SLR(1) ⊂ LALR(1)
"Every CLR(1) is LALR(1)": FALSE — CLR(1) is more powerful than LALR(1)
"LR(0) and SLR(1) are equal": FALSE — SLR(1) is strictly more powerful
Step 3: Only option B is true.
Answer: B
Question 4 · Syntax-Directed Translation and Intermediate RepresentationsMCQ
Which of the following statements is strictly TRUE regarding the attribute dependency graph for a specific parse tree in a syntax-directed definition?
A.
It is constructed statically for the grammar, independent of the specific parse tree.
B.
A directed edge from node X to node Y indicates that the semantic rule for Y requires the value of X.
C.
It is permitted to contain cycles as long as the grammar is L-attributed.
D.
It only maps dependencies for synthesized attributes, ignoring inherited attributes.
Correct Answer:
B
Step-by-Step Solution
Key idea: The dependency graph is dynamic (per parse tree) and must be acyclic to allow valid evaluation.
Step 1: The graph is constructed for each specific parse tree, not statically for the grammar (eliminates option A).
Step 2: A directed edge from X to Y means Y depends on X, so X must be evaluated before Y. This matches option B.
Step 3: The graph must never contain cycles; a cycle means the attributes cannot be evaluated (eliminates option C).
Step 4: The graph maps dependencies for both synthesized and inherited attributes (eliminates option D).
Answer: A directed edge from node X to node Y indicates that the semantic rule for Y requires the value of X.
Question 5 · Runtime Environments and Procedure CallsMCQ
Consider the following program:
\begin{verbatim}
void F(int n) {
if (n > 1) {
G();
F(n - 1);
F(n - 2);
}
}
void G() { }
\end{verbatim}
\textbf{Assertion (A):} If main calls F(3), the total number of activation records for function F is 5.
\textbf{Reason (R):} The function F is invoked exactly 5 times during this execution.
Which of the following is correct?
A.
Both A and R are true and R is the correct explanation of A
B.
Both A and R are true but R is NOT the correct explanation of A
C.
A is true but R is false
D.
A is false but R is true
Correct Answer:
A
Step-by-Step Solution
Key idea: Activation records for a function = number of times that function is invoked.
Step 1: Trace execution for F(3):
F(3): n=3>1, so calls G, F(2), F(1)
F(2): n=2>1, so calls G, F(1), F(0)
F(1) from F(3): n=1, not >1, returns
F(1) from F(2): n=1, not >1, returns
F(0) from F(2): n=0, not >1, returns
Step 2: Count F invocations:
F(3),F(2),F(1),F(1),F(0) = 5 invocations
Step 3: Evaluate A and R:
A: "activation records for F is 5" = TRUE (5 invocations = 5 records)
R: "F is invoked exactly 5 times" = TRUE
R explains A because activation records for F = number of F invocations.
Answer: Both A and R are true and R is the correct explanation of A.
Question 6 · Basic Blocks, Data-Flow Analysis and Code OptimizationMCQ
A basic block is defined by having exactly E entry points and X exit points to ensure safe boundaries for optimization algorithms. What is the value of E+X?
A.
0
B.
1
C.
2
D.
3
Correct Answer:
C
Step-by-Step Solution
Key idea: A basic block is an atomic unit of code with a strict single-entry, single-exit invariant.
Step 1: Recall the definition of a basic block. It is a maximal sequence of instructions where control flow can only enter at the first instruction and leave at the last instruction.
Step 2: This means there is exactly E=1 entry point and exactly X=1 exit point.