Skip to content
CS-603 · Compiler Design/Unsolved PYQ Paper

CS-603 Compiler Design - Dec 2024 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.

  1. 8 Marks
    aWhat is a translator? Compare compiler and interpreter in terms of translation method, memory requirement and speed.
    How to answer
    • Define translator as language processor
    • Compare translation method: compilation vs line-by-line interpretation
    • Compare memory requirement and speed with reasons
    • Conclude with examples
  2. 3 Marks
    bExplain LEX tool in brief.
    How to answer
    • Define LEX as lexical analyzer generator
    • Describe LEX specification format and workflow
    • Mention input to output: lex.l to lex.yy.c
  3. 3 Marks
    cWhat is left factoring in grammar? Explain with an example.
    How to answer
    • Define left factoring
    • Explain need to avoid backtracking in predictive parsing
    • Give general form A -> alpha beta1 | alpha beta2 transformation
    • Illustrate with example
  4. 6 Marks
    aConsider the following grammar for list structures: $$S \rightarrow a / \wedge(T)$$ $$T \rightarrow T,S / S$$ Find left most derivation, right most derivation and parse tree for the string $(((a,a),\wedge(a)),a)$.
    How to answer
    • State grammar S->a/^(T), T->T,S/S
    • Show leftmost derivation steps for (((a,a),^(a)),a)
    • Show rightmost derivation steps
    • Draw parse tree
  5. 4 Marks
    bFor the following grammar find First and Follow sets for each of non-terminal. $$S \rightarrow aAB / bA / \varepsilon$$ $$A \rightarrow aAb / \varepsilon$$ $$B \rightarrow bB / \varepsilon$$
    How to answer
    • State grammar S->aAB/bA/epsilon etc.
    • Compute First for A,B,S
    • Compute Follow for A,B,S
    • Present sets
  6. 4 Marks
    cDescribe the following in brief. i) Ambiguity ii) Left recursion
    How to answer
    • Define ambiguity with example grammar
    • Define left recursion with example
    • Explain problems caused in parsing
  7. 8 Marks
    aWhat is parser? Explain backtracking and non-backtracking parsers with their types.
    How to answer
    • Define parser and its role in syntax analysis
    • Explain backtracking parsers with types
    • Explain non-backtracking parsers with types
    • Compare with examples
  8. 6 Marks
    bConsider the following grammar. $$E \rightarrow E + T$$ $$T \rightarrow TF / F$$ $$F \rightarrow F* / a / b$$ Construct the SLR Parsing table for this grammar.
    How to answer
    • Augment grammar and construct LR(0) items
    • Compute canonical collection and Follow sets
    • Fill SLR action and goto table
    • Check for conflicts
  9. 8 Marks
    aDefine the following with an example. i) Synthesized attributes ii) Annotated parse tree iii) Dependency graph
    How to answer
    • Define synthesized attributes with example
    • Define annotated parse tree with example
    • Define dependency graph with example
  10. 6 Marks
    bGenerate the three address code for the following code segment: While (a < c and b < d) do If a = 1 then c = c + 1. Else While (a <= d) do a = a + 3
    How to answer
    • Analyze while and if-else control flow
    • Generate labels and temporaries for conditions
    • Emit three-address instructions sequentially
    • Show final TAC list
  11. 8 Marks
    aExplain various intermediate code generation techniques in brief.
    How to answer
    • List syntax tree, postfix, three-address code
    • Explain each technique briefly
    • Mention quadruples/triples/indirect triples
    • Give small example
  12. 6 Marks
    bConsider the grammar with the following translation rules and E as the start symbol. $$E \rightarrow E1 \# T \; \{E.value = E1.value * T.value\}$$ $$| T \; \{E.value = T.value\}$$ $$T \rightarrow T1 \& F \; \{T.value = T1.value + F.value\}$$ $$| F \; \{T.value = F.value\}$$ $$F \rightarrow num \; \{F.value = num.value\}$$ Compute E.value for the root of the parse tree for the expression. $$2 \ll 3 \& 5 \# 6 \& 4$$
    How to answer
    • Interpret translation rules for E,T,F
    • Build parse tree for 2 << 3 & 5 # 6 & 4
    • Evaluate bottom-up F.value, T.value, E.value
    • Report E.value at root
  13. 6 Marks
    aWrite an algorithm to construct a DAG from a basic block.
    How to answer
    • List steps: leader identification, block partitioning
    • Describe node creation for each statement
    • Explain merging common subexpressions
    • State algorithm pseudocode
  14. 8 Marks
    bWhat is S-attributed SDT & L-attributed SDT? Consider the following grammar and write the SDT rules for the given grammar. $$S \rightarrow S * A$$ $$S \rightarrow A$$ $$A \rightarrow A + B$$ $$B \rightarrow (S)$$ $$A \rightarrow B$$ $$B \rightarrow id$$
    How to answer
    • Define S-attributed SDT characteristics
    • Define L-attributed SDT characteristics
    • Write SDT rules for S->S*A, A->A+B etc.
    • Mention evaluation order
  15. 7 Marks
    aWrite the differences between Synthesized and inherited attributes.
    How to answer
    • Define synthesized vs inherited with dependency direction
    • Tabulate differences: definition, parse tree flow, evaluation
    • Give examples
  16. 7 Marks
    bExplain the common sub expression, elimination, copy propagation, and Transformation for moving loop invariant computations in detail.
    How to answer
    • Define common subexpression elimination
    • Explain copy propagation
    • Explain loop invariant code motion with transformation
  17. 4 Marks
    aWhat is Local transformation and Global transformation.
    How to answer
    • Define local transformation scope
    • Define global transformation scope
    • Give examples of each
  18. 10 Marks
    bWhat are the 3 areas of code optimization? Explain each one in detail.
    How to answer
    • List three areas of code optimization
    • Explain machine independent, dependent aspects
    • Explain local, global, peephole levels
    • Give examples
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 account

Have an account? Log in