Skip to content
SmartFigureEdu

CS 3501 Compiler Design question paper, April/May 2024

Question Paper Code : 50906

B.E./B.Tech. DEGREE EXAMINATIONS, APRIL/MAY 2024.

Fifth Semester

Computer Science and Engineering

CS 3501 — COMPILER DESIGN

(Common to : )

(Regulations 2021)

Time : Three hoursMaximum : 100 marks

Answer ALL questions.

PART A — (10 × 2 = 20 marks)

  1. 1.

    State the difference between a compiler and an interpreter.

  2. 2.

    Define the interaction between lexical analyzers and parsers.

  3. 3.

    What are the common programming errors that can occur at different levels?

  4. 4.

    What is the purpose of LR parsers?

  5. 5.

    Define inherited attribute.

  6. 6.

    State the rules of type checking.

  7. 7.

    What are two strategies for dynamic storage allocation?

  8. 8.

    Write the role of activation record.

  9. 9.

    What are the causes of redundancy?

  10. 10.

    What is copy propagation?

PART B — (5 × 13 = 65 marks)

  1. 11.
    (a)
    • (i)Divide the following C++ program. float limitedSquare(x) { /* returns x-squared, but never float x; more than 100*/ return (x<=-10.0||x>=10.0)? 100:x*x; } Into appropriate lexemes. Which lexemes should get associated lexical values? What should those values be?(5)
    • (ii)Explain the role of lexical analyzer.(8)
  2. Or
  3. (b)
    • (i)Describe the languages denoted by the following regular expressions: (1) a(a|b)*a (2) ((epsilon|a)b*)* (3) (a|b)*a(a|b)(a|b) (4) a*ba*ba*ba* (5) !! (aa|bb)*((ab|ba)(aa|bb)*(ab|ba)(aa|bb)*)*.(5)
    • (ii)Explain the construction of a DFA from a regular expression.(8)
  4. 12.
    (a)
    • (i)Consider the context-free grammar. S -> SS + | S S * | a and the string aa + a* (1) Give a leftmost derivation for the string. (1) (2) Give a rightmost derivation for the string. (1) (3) Give a parse tree for the string. (1) (4) Is the grammar ambiguous or unambiguous? Justify your answer. (2)(5)
    • (ii)Explain the error handling and error recovery mechanism of syntax analyser.(8)
  5. Or
  6. (b)
    • (i)Show that the following grammar. S -> S A | A A -> a is SLR(1) but not LL(1).(5)
    • (ii)State and explain the algorithm to eliminate left recursion from a grammar.(8)
  7. 13.
    (a)
    • (i)The expressions involving operator + and integer or floating-point operands. Floating-point numbers are distinguished by having a decimal point. E -> E + T | T T -> num.num | num Give an SDD to determine the type of each term T and expression E.(5)
    • (ii)Explain the S-Attribute Definitions with example.(8)
  8. Or
  9. (b)
    • (i)Translate the arithmetic expression a + (b + c) into (1) Syntax tree (2) Quadruples.(5)
    • (ii)State and explain the translation of expressions and the addressing array elements with example.(8)
  10. 14.
    (a)

    What are the issues in the design of a code generator? Explain with example.

  11. Or
  12. (b)

    Explain the stack allocation of space with example? What principles are helpful when designing calling sequences?

  13. 15.
    (a)

    What are induction variable and how to find the induction variable in loops and optimize their computation. Explain with example.

  14. Or
  15. (b)

    Explain the optimization of basic blocks? How does the Directed Acyclic Graph (DAG) representation of a basic block facilitate code-improving transformations within the represented code?

PART C — (1 × 15 = 15 marks)

  1. 16.
    (a)

    Construct the DAG and identify the value numbers for the subexpressions of the following expressions, assuming + associates from the left.

    • (i)a + b + (a + b)
    • (ii)a + b + a + b
    • (iii)a + a + (a + a + a + (a + a + a + a)).
  2. Or
  3. (b)

    Explain the steps involved in the construction of predictive parser with suitable example.


Other CS3501 papers