Term 2 - PS3 - Compiler Design

Term 2 - Set 3 - L1: Compiler Design

Section A: Short Answer Questions (3 × 3 = 9 marks)

  1. Answer any three of the following. Each question carries 3 marks.

    1. Differentiate between direct and indirect recursion in CFG with suitable examples.
    2. Explain left recursion and why it is problematic for top-down parsers.
    3. Define First() and Follow() functions with one example each.
    4. Write short notes on:
      a) Symbol Table
      b) Error Handler
    5. Explain the difference between non-deterministic and deterministic CFG with an example.
  2. Section B: Medium Answer Questions (2 × 6 = 12 marks)

  3. Answer any two of the following. Each question carries 6 marks.

    1. a) Eliminate left recursion from the grammar:
          A → Aa | Ab | c
      b) Perform left factoring on the grammar:
          A → aAB | aBC | aAC
    2. Given the grammar:
          S → aAB
          A → ε | c
          B → d | ε
      a) Compute First and Follow sets.
      b) Construct the LL(1) parsing table.
    3. Discuss the phases of a compiler with neat labels and explain how the symbol table and error handler are used across phases.
  4. Section C: Long Answer Question (1 × 9 = 9 marks)

  5. Answer any one of the following.

    1. Given the grammar:
          S → aSbS | bSaS | ε
      a) Perform left factoring on the grammar.
      b) Check whether the resulting grammar is LL(1) using appropriate rules.
      c) If LL(1), construct the LL(1) parsing table and simulate parsing for the string "abab" with stack operations.
    2. Compare Top-Down and Bottom-Up parsing techniques under the following heads:
      a) Derivation Order
      b) Backtracking
      c) Recursive Descent Parser
      d) Predictive Parser
      e) Operator Precedence Parser
      f) Parse Tree Construction