CS-603 · Compiler Design/Unsolved PYQ Paper
CS-603 Compiler Design - May 2023 Question Paper
Under each question, How to answer lists the points an answer should cover, outlined by CampusPrep from the syllabus. Check the details against your textbook.
-
8 MarksaDraw the structure of a compiler and describe various phases in the compilation process. Mention the output of the following statement: $id_1=id_2+id_3*50$ at each phase.
How to answer
- Block diagram of compiler phases: lexical, syntax, semantic, IR, optimization, code gen
- Brief function of each phase with symbol table and error handler
- Trace of id1=id2+id3*50 through each phase output
-
6 MarksbDesign the LEX program that recognizes the tokens of a C language and returns the token found.
How to answer
- LEX definition, rules and user subroutine sections
- Regular expressions for keywords, identifiers, numbers, operators
- Return of token codes for C language tokens
-
14 MarksCompute LR(0) items for the following grammar and construct SLR Parser table. $S \rightarrow L=R | R$ $L \rightarrow *R | id$ $R \rightarrow L$
How to answer
- Augmented grammar and closure/goto for LR(0) canonical items
- Enumeration of item sets I0 to In
- Computation of FOLLOW sets and SLR parsing table with actions/goto
-
7 MarksaDifferentiate between Top down parsing and Bottom up parsing.
How to answer
- Definition of top-down vs bottom-up parsing approach
- Comparison on parse tree construction, backtracking, left recursion
- Examples of LL vs LR parsers
-
7 MarksbConstruct the Recursive Descent Parser with back tracking for the following grammar $S \rightarrow aSbS | bSaS | \epsilon$
How to answer
- Grammar S -> aSbS | bSaS | epsilon and backtracking concept
- Recursive procedures for S with input pointer and backtrack
- Trace on sample string
-
10 MarksaHow is Stack storage allocation strategy different from heap allocation strategy? Describe them and mentioning their merits and demerits.
How to answer
- Stack allocation: activation records, LIFO, compile-time offsets
- Heap allocation: dynamic allocation, fragmentation, garbage collection
- Merits/demerits on speed, flexibility, overhead
-
4 MarksbExplain different Polymorphic functions with suitable examples.
How to answer
- Definition of polymorphism in type systems
- Examples of parametric, ad-hoc/overloading, subtype polymorphism
- Use in programming languages
-
8 MarksaExplain in brief about different sources of optimization of basic blocks with suitable example.
How to answer
- Definition of basic block and optimization scope
- Sources: common subexpression, copy propagation, dead code, algebraic
- Illustrative three-address examples
-
6 MarksbDefine flow graph? Explain how a program is converted into a flow graph.
How to answer
- Definition of flow graph with basic blocks as nodes
- Steps to partition three-address code into blocks and add edges
- Example program to flow graph conversion
-
8 MarksaWhat is DAG? Construct DAG for the following basic blocks: $D := B*C; E := A+B; B := B+C; A := E-D;$
How to answer
- Definition of DAG for common subexpressions
- Stepwise construction for D=B*C, E=A+B, B=B+C, A=E-D
- Sharing of common nodes B+C
-
6 MarksbDifferentiate between S-attribute with L-attribute definition with suitable example.
How to answer
- Definition of S-attributed vs L-attributed definitions
- Rules on synthesized vs inherited attributes and parse-tree evaluation order
- Suitable example grammar for each
-
8 MarksaExplain in brief about equivalence of type expression.
How to answer
- Definition of type expression and equivalence need
- Structural vs name equivalence rules
- Example of equivalent type expressions
-
6 MarksbDiscuss about peephole optimization.
How to answer
- Definition of peephole as sliding window on target code
- Typical optimizations: redundant loads, unreachable code, strength reduction
- Example before-after code snippets
-
14 MarksWrite a short note on following: a) Common sub-expression elimination b) Register allocation c) Three address code
How to answer
- Common subexpression elimination: detection and reuse
- Register allocation: graph coloring and spilling
- Three address code: forms, quadruples/triples and example
Go to where you left off?
Quick Add to Notes
Save questions, your own notes and screenshots into notes filed by unit. It takes a free account.
Create free accountHave an account? Log in
Notes Panel