Compiler Design - B.Tech. 6th Semester Examination, 2017
Compiler Design
Instructions:
- There are Nine Questions in this Paper.
- Attempt Five questions in all.
- Question No. 1 is Compulsory.
- The marks are indicated in the right-hand margin.
-
A grammar that produces more than one parse tree for some sentence is said to be
-
What is not the phase of a compiler?
-
Given a grammar \( G=(\{E\}, \{id, +\}, P, E) \); where P is given by \( E \rightarrow E+E | id \). Then FOLLOW(E) will contain
-
Which of the following expressions has no l-value?
-
Consider the statement "fi (x>=10)", where 'if' has been misspelled. The error is detected by the compiler in the phase
-
Which of the following is not a loop optimization?
-
If x is a terminal then FIRST(x) is
-
Consider following grammar \( S \rightarrow cAd \), \( A \rightarrow ab | a \). For input string cad, how many times the recursive descent parser will backtrack?
-
The optional access link in the activation record is used for
-
Suppose two productions are there: \( A \rightarrow \alpha \) and \( A \rightarrow \beta \). The recursive descent parsing without backtracking requires:
-
Construct DFA for \( (ab^* | ba^*) \) and minimize the number of states of the above constructed DFA.
-
A grammar is given below:
\( S \rightarrow A \)
\( A \rightarrow aB | Ad \)
\( B \rightarrow bBC | f \)
\( C \rightarrow g \)
Find the FIRST and FOLLOW set. -
Construct a predictive parsing table for the grammar given above.
-
What is a symbol table? Why is it needed in compiler design? Explain different components of a symbol table with an example.
-
Consider the following program fragment:
prod = 0;
i = 1;
do {
prod = prod + a[i] * b[i];
i = i + 1;
} while (i <= 20);
Generate the three-address code for the above program fragment. -
Determine the basic blocks for the computed three-address code.
-
What is DAG? What is the use of DAG in compiler construction? Construct a DAG for the following statements:
\( Z = X - Y + X * Y \)
\( U = V / W + X + V \)
-
Explain peephole optimization in detail.
-
Suppose a basic block is formed from the C assignment statements:
\( x = a + b + c + d + e + f; \)
\( y = a + c + e; \)
(a) Give the three-address statements (only one addition per statement) for this block.
(b) Use the associative and commutative laws to modify the block to use the fewest possible number of instructions, assuming both \( x \) and \( y \) are live on exit from the block.
-
Given the grammar \( G = (S, \{S, A, B\}, \{a, b, c, d\}, P) \) with set of productions \( P \) below compute;
a. LR(1) sets of items.
b. Compute the corresponding parsing table for the corresponding shift-reduce parse engine.
c. Show the actions of the parsing engine as well as the contents of the symbol and state stacks for the input string \( w = \text{"bdac"} \).
d. Is this grammar LALR(1)? Justify.
\( S \rightarrow Aa | bAc | Bc | bBa \)
\( A \rightarrow d \)
\( B \rightarrow d \)
Do not forget to augment the grammar with the production \( S' \rightarrow S \).