2022 question paper

Compiler Design

25 questions

  1. Q1a. Choose the correct answer of the following: The output of a lexical analyzer is (i) a machine code (ii) an intermediate code (iii) a stream of tokens (iv) a parse tree20222m

    Module 1 : Introduction & Lexical Analysis

    Choose the correct answer of the following:
    The output of a lexical analyzer is
    (i) a machine code
    (ii) an intermediate code
    (iii) a stream of tokens
    (iv) a parse tree

    View this question on its own page →
  2. Q1b. Choose the correct answer of the following: A bottom-up parser generates (i) right-most derivation (ii) right-most derivation in reverse (iii) left-most derivation (iv) left-most derivation in reverse20222m

    Module 2 : Syntax Analysis (Parser)

    Choose the correct answer of the following:
    A bottom-up parser generates
    (i) right-most derivation
    (ii) right-most derivation in reverse
    (iii) left-most derivation
    (iv) left-most derivation in reverse

    View this question on its own page →
  3. Q1c. Choose the correct answer of the following: A grammar that produces more than one parse tree for some sentence is said to be (i) Ambiguous (ii) context free (iii) disambiguous (iv) regular20222m

    Module 2 : Syntax Analysis (Parser)

    Choose the correct answer of the following:
    A grammar that produces more than one parse tree for some sentence is said to be
    (i) Ambiguous
    (ii) context free
    (iii) disambiguous
    (iv) regular

    View this question on its own page →
  4. Q1d. Choose the correct answer of the following: Consider the following grammar: S \rightarrow cAd A \rightarrow ab | ac | a. For input string *cad*, how many times the recursive descent parser will backtrack? (i) 2 (ii) 3 (iii) 4 (iv) 520222m

    Module 2 : Syntax Analysis (Parser)

    Choose the correct answer of the following:
    Consider the following grammar:
    ScAdS \rightarrow cAd
    Aabaca.A \rightarrow ab | ac | a.
    For input string cad, how many times the recursive descent parser will backtrack?
    (i) 2
    (ii) 3
    (iii) 4
    (iv) 5

    View this question on its own page →
  5. Q1e. Choose the correct answer of the following: A compiler for a high-level language that runs on one machine and produce code for different machines is called (i) optimizing compiler (ii) one-pass compiler (iii) cross-compiler (iv) multipass compiler20222m

    Module 1 : Introduction & Lexical Analysis

    Choose the correct answer of the following:
    A compiler for a high-level language that runs on one machine and produce code for different machines is called
    (i) optimizing compiler
    (ii) one-pass compiler
    (iii) cross-compiler
    (iv) multipass compiler

    View this question on its own page →
  6. Q1f. Choose the correct answer of the following: Right side of three-address code has how many numbers of operator at most? (i) 1 (ii) 2 (iii) 4 (iv) 320222m

    Module 4 : Intermediate Code Generation & Code Improvement

    Choose the correct answer of the following:
    Right side of three-address code has how many numbers of operator at most?
    (i) 1
    (ii) 2
    (iii) 4
    (iv) 3

    View this question on its own page →
  7. Q1g. Choose the correct answer of the following: What is the similarity between LR, LALR and SLR? (i) Use of same algorithm, but different parsing table (ii) Same parsing table, but different algorithm (iii) Their parsing tables and algorithms are similar but use top-down approach (iv) Both parsing tables and algorithms are different.20222m

    Module 2 : Syntax Analysis (Parser)

    Choose the correct answer of the following:
    What is the similarity between LR, LALR and SLR?
    (i) Use of same algorithm, but different parsing table
    (ii) Same parsing table, but different algorithm
    (iii) Their parsing tables and algorithms are similar but use top-down approach
    (iv) Both parsing tables and algorithms are different.

    View this question on its own page →
  8. Q1h. Choose the correct answer of the following: After removing left recursion from A \rightarrow A\alpha / \beta , the resulting grammar will be (i) A \rightarrow \beta A' (ii) A \rightarrow \alpha A' (iii) A \rightarrow \alpha \beta A'' (iv) A \rightarrow \beta \alpha A'20222m

    Module 2 : Syntax Analysis (Parser)

    Choose the correct answer of the following:
    After removing left recursion from AAα/βA \rightarrow A\alpha / \beta , the resulting grammar will be
    (i) AβAA \rightarrow \beta A'
    (ii) AαAA \rightarrow \alpha A'
    (iii) AαβAA \rightarrow \alpha \beta A''
    (iv) AβαAA \rightarrow \beta \alpha A'

    View this question on its own page →
  9. Q1i. Choose the correct answer of the following: If x is a terminal then FIRST(x) is (i) \epsilon (ii) {x} (iii) x* (iv) xx*20222m

    Module 2 : Syntax Analysis (Parser)

    Choose the correct answer of the following:
    If x is a terminal then FIRST(x) is
    (i) ϵ\epsilon
    (ii) {x}
    (iii) x*
    (iv) xx*

    View this question on its own page →
  10. Q1j. Choose the correct answer of the following: If a grammar is LALR(1), then it is necessarily (i) SLR(1) (ii) LR(1) (iii) LL(1) (iv) None of the above20222m

    Module 2 : Syntax Analysis (Parser)

    Choose the correct answer of the following:
    If a grammar is LALR(1), then it is necessarily
    (i) SLR(1)
    (ii) LR(1)
    (iii) LL(1)
    (iv) None of the above

    View this question on its own page →
  11. Q2a. Explain the working of each phase of compiler in detail with an example.20227m

    Module 1 : Introduction & Lexical Analysis

    Explain the working of each phase of compiler in detail with an example.

    View this question on its own page →
  12. Q2b. For the given grammar and associated semantic rules. Find the output for the input: *aadbd*. S \rightarrow AS \{print(1)\}; S \rightarrow AB \{print(2)\}; A \rightarrow a \{print(3)\}; B \rightarrow bC \{print(4)\}; B \rightarrow dB \{print(5)\}; C \rightarrow e \{print(6)\}20227m

    Module 3 : Semantic Analysis & Symbol Table

    For the given grammar and associated semantic rules. Find the output for the input: aadbd.
    SAS{print(1)};SAB{print(2)};Aa{print(3)};BbC{print(4)};S \rightarrow AS \{print(1)\}; S \rightarrow AB \{print(2)\}; A \rightarrow a \{print(3)\}; B \rightarrow bC \{print(4)\};
    BdB{print(5)};Ce{print(6)}B \rightarrow dB \{print(5)\}; C \rightarrow e \{print(6)\}

    View this question on its own page →
  13. Q3. Consider the following grammar: S \rightarrow 0S0 | 1S1 | 10 (a) Find LR(0) collection of items for the above grammar. (b) Construct SLR parsing table. (c) Trace whether the string "01100" is accepted or not.202214m

    Module 2 : Syntax Analysis (Parser)

    Consider the following grammar:
    S0S01S110S \rightarrow 0S0 | 1S1 | 10
    (a) Find LR(0) collection of items for the above grammar.
    (b) Construct SLR parsing table.
    (c) Trace whether the string "01100" is accepted or not.

    View this question on its own page →
  14. Q4. Construct LALR(1) parsing table for the following grammar. Also prove that this is not SLR(1). S \rightarrow Aa | bAc | dc | bda A \rightarrow d202214m

    Module 2 : Syntax Analysis (Parser)

    Construct LALR(1) parsing table for the following grammar. Also prove that this is not SLR(1).
    SAabAcdcbdaS \rightarrow Aa | bAc | dc | bda
    AdA \rightarrow d

    View this question on its own page →
  15. Q5a. Find the three-address codes of the following program. There are four bytes per word: ``c Sum = 0; for (i = 1; i<=20; i++) Sum = Sum + a[i] + b[i]; ``20227m

    Module 4 : Intermediate Code Generation & Code Improvement

    Find the three-address codes of the following program. There are four bytes per word:

    Sum = 0;
    for (i = 1; i<=20; i++)
    Sum = Sum + a[i] + b[i];
    
    View this question on its own page →
  16. Q6a. Consider the context free grammar: S \rightarrow SS + | SS * | a; eliminate left factoring and left recursion from the grammar. Does these removals make the grammar suitable for top-down parsing? Justify.20227m

    Module 2 : Syntax Analysis (Parser)

    Consider the context free grammar: SSS+SSaS \rightarrow SS + | SS * | a; eliminate left factoring and left recursion from the grammar. Does these removals make the grammar suitable for top-down parsing? Justify.

    View this question on its own page →
  17. Q6b. Compute FIRST and FOLLOW for the given grammar. Also derive the LL(1) parsing table. E \rightarrow TE' E' \rightarrow + TE' / \epsilon T \rightarrow FT' T' \rightarrow * FT' / \epsilon F \rightarrow (E) / id20227m

    Module 2 : Syntax Analysis (Parser)

    Compute FIRST and FOLLOW for the given grammar. Also derive the LL(1) parsing table.
    ETEE \rightarrow TE'
    E+TE/ϵE' \rightarrow + TE' / \epsilon
    TFTT \rightarrow FT'
    TFT/ϵT' \rightarrow * FT' / \epsilon
    F(E)/idF \rightarrow (E) / id

    View this question on its own page →
  18. Q7a. Translate the arithmetic expression a + - (b + c) into: (a) Syntax tree (b) Quadruples (c) Triples (d) Indirect Triples20227m

    Module 4 : Intermediate Code Generation & Code Improvement

    Translate the arithmetic expression a+(b+c)a + - (b + c) into:
    (a) Syntax tree
    (b) Quadruples
    (c) Triples
    (d) Indirect Triples

    View this question on its own page →
  19. Q7b. Differentiate between S-attributed SDDs and L-attributed SDDs with suitable examples.20227m

    Module 3 : Semantic Analysis & Symbol Table

    Differentiate between S-attributed SDDs and L-attributed SDDs with suitable examples.

    View this question on its own page →
  20. Q8a. Discuss *code motion* and *copy propagation* as machine - independent code optimization techniques.20227m

    Module 4 : Intermediate Code Generation & Code Improvement

    Discuss code motion and copy propagation as machine - independent code optimization techniques.

    View this question on its own page →
  21. Q8b. What is basic block in the graph representation of intermediate codes. Construct DAG for the basic block given below. Also optimize the three address code, assuming only a is live on exit from the block. d = b * c e = a + b b = b * c a = e - d20227m

    Module 4 : Intermediate Code Generation & Code Improvement

    What is basic block in the graph representation of intermediate codes. Construct DAG for the basic block given below. Also optimize the three address code, assuming only aa is live on exit from the block.
    d=bcd = b * c
    e=a+be = a + b
    b=bcb = b * c
    a=eda = e - d

    View this question on its own page →
  22. Q9a. Write short notes on: Activation Records20227m

    Module 3 : Semantic Analysis & Symbol Table

    Write short notes on: Activation Records

    View this question on its own page →
  23. Q9b. Write short notes on: YACC20227m

    Module 2 : Syntax Analysis (Parser)

    Write short notes on: YACC

    View this question on its own page →
  24. Q9c. Write short notes on: Symbol table20227m

    Module 3 : Semantic Analysis & Symbol Table

    Write short notes on: Symbol table

    View this question on its own page →
  25. Q9d. Write short notes on: Peephole optimization20227m

    Module 4 : Intermediate Code Generation & Code Improvement

    Write short notes on: Peephole optimization

    View this question on its own page →