Compiler Design - B.Tech. 6th Semester Examination, 2023
Compiler Design
Instructions:
- The marks are indicated in the right-hand margin.
- There are NINE questions in this paper.
- Attempt FIVE questions in all.
- Question No. 1 is compulsory.
- Symbols used (if any) have their usual meanings.
-
Which of the following is the most powerful parser?
-
A top down parser generates
-
A shift reduce parser carries out the actions specified within braces immediately after reducing with the corresponding rule of grammar: \( S \rightarrow xxW \) {print "1"}, \( S \rightarrow y \) {print "2"}, \( S \rightarrow Sz \) {print "3"}. What is the translation of xxxxyzz using the syntax directed translation scheme described by the above rules?
-
Three-address code involves
-
Handle pruning forms the basis of
-
Left factoring guarantees
-
Consider a grammar \( A \rightarrow aS_1 | aS_2 \). The left factored grammar produced from the grammar is
-
Synthesized attributes are calculated
-
The method which merges the bodies of two loops is
-
For a grammar G, shift reduce (S-R) conflicts are present in LALR(1) parser, if and only if
-
Explain the working of each phase of compiler in detail with an example.
-
What is an activation record? Explain how they are used to access various local and global variables.
-
What are the advantages of LALR parsing over SLR and CLR methods?
-
Write the algorithm to compute FIRST and FOLLOW for a given grammar.
-
What is shift-reduce conflict?
-
Given the Syntax-Directed Definition below with the synthesized attribute val. Draw the annotated parse tree for the expression \( (3+4)*(5+6) \):
\( L \rightarrow E \) ; \( L.val = E.val \)
\( E \rightarrow T \) ; \( E.val = T.val \)
\( E \rightarrow E_1 + T \) ; \( E.val = E_1.val + T.val \)
\( T \rightarrow F \) ; \( T.val = F.val \)
\( T \rightarrow T_1 * F \) ; \( T.val = T_1.val * F.val \)
\( F \rightarrow (E) \) ; \( F.val = E.val \)
\( F \rightarrow digit \) ; \( F.val = digit.lexval \) -
Find the FIRST and FOLLOW from the following production:
\( S \rightarrow aBDh \)
\( B \rightarrow cC \)
\( C \rightarrow bC | \epsilon \)
\( D \rightarrow EF \)
\( E \rightarrow g | \epsilon \)
\( F \rightarrow f | \epsilon \)
-
Construct the predictive parsing table for the following grammar:
\( S \rightarrow A \)
\( A \rightarrow aB | Ad \)
\( B \rightarrow bBC | f \)
\( C \rightarrow cg \) -
Explain how type checking and error reporting are performed in compiler. Draw syntax tree and DAG for the statement: \( a = (a*b+c)\wedge(b+c)*b+c \)
-
What is handle? Consider the grammar: \( E \rightarrow E+E | E*E | id \). Find the handles of the right sentential forms of the reduction for the string \( id_1 + id_2 * id_3 \).
-
When a grammar is called ambiguous? Is there any technique to remove ambiguity? Justify whether the grammar is ambiguous or not: \( A \rightarrow AA | (A) | a \)
-
Discuss about operator precedence parser.
-
Differentiate between S-attribute SDT and L-attribute SDT with suitable examples.
-
Consider the following grammar: \( E \rightarrow E+T | T \), \( T \rightarrow T*F | F \), \( F \rightarrow id \). Draw a SLR state transition diagram for the above grammar. Also draw the SLR parse table.
-
Consider the following grammar: \( S \rightarrow CC \), \( C \rightarrow cC | d \). Find the LR(1) set of items.
-
Translate the expression \( a=(a+b)*(c+d)+(a+b+c) \) into (i) Quadruple (ii) Triple (iii) Indirect triple.