2022 question paper
Compiler Design
25 questions
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
View this question on its own page →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 treeQ1b. 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)
View this question on its own page →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 reverseQ1c. 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)
View this question on its own page →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) regularQ1d. 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)
View this question on its own page →Choose the correct answer of the following:
Consider the following grammar:
For input string cad, how many times the recursive descent parser will backtrack?
(i) 2
(ii) 3
(iii) 4
(iv) 5Q1e. 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
View this question on its own page →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 compilerQ1f. 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
View this question on its own page →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) 3Q1g. 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)
View this question on its own page →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.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)
View this question on its own page →Choose the correct answer of the following:
After removing left recursion from , the resulting grammar will be
(i)
(ii)
(iii)
(iv)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)
View this question on its own page →Choose the correct answer of the following:
If x is a terminal then FIRST(x) is
(i)
(ii) {x}
(iii) x*
(iv) xx*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)
View this question on its own page →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 aboveQ2a. Explain the working of each phase of compiler in detail with an example.20227m
Module 1 : Introduction & Lexical Analysis
View this question on its own page →Explain the working of each phase of compiler in detail with an example.
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
View this question on its own page →For the given grammar and associated semantic rules. Find the output for the input: aadbd.
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)
View this question on its own page →Consider the following grammar:
(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.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)
View this question on its own page →Construct LALR(1) parsing table for the following grammar. Also prove that this is not SLR(1).
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
View this question on its own page →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];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)
View this question on its own page →Consider the context free grammar: ; eliminate left factoring and left recursion from the grammar. Does these removals make the grammar suitable for top-down parsing? Justify.
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)
View this question on its own page →Compute FIRST and FOLLOW for the given grammar. Also derive the LL(1) parsing table.
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
View this question on its own page →Translate the arithmetic expression into:
(a) Syntax tree
(b) Quadruples
(c) Triples
(d) Indirect TriplesQ7b. Differentiate between S-attributed SDDs and L-attributed SDDs with suitable examples.20227m
Module 3 : Semantic Analysis & Symbol Table
View this question on its own page →Differentiate between S-attributed SDDs and L-attributed SDDs with suitable examples.
Q8a. Discuss *code motion* and *copy propagation* as machine - independent code optimization techniques.20227m
Module 4 : Intermediate Code Generation & Code Improvement
View this question on its own page →Discuss code motion and copy propagation as machine - independent code optimization techniques.
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
View this question on its own page →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 is live on exit from the block.
Q9a. Write short notes on: Activation Records20227m
Module 3 : Semantic Analysis & Symbol Table
View this question on its own page →Write short notes on: Activation Records
Q9b. Write short notes on: YACC20227m
Q9c. Write short notes on: Symbol table20227m
Module 3 : Semantic Analysis & Symbol Table
View this question on its own page →Write short notes on: Symbol table
Q9d. Write short notes on: Peephole optimization20227m
Module 4 : Intermediate Code Generation & Code Improvement
View this question on its own page →Write short notes on: Peephole optimization