Categorized Questions from Compiler Construction Paper
Compiler Phases
- 1. Give the output of every phase of the compiler for the following statement: 4 * a * c (Where a and b are
float variables and c is an integer variable).
FIRST and FOLLOW Sets
- 2. (i) Write a general rule to calculate FIRST(S) and FOLLOW(B) for the production rule S -> uBB, where S
and B are non-terminals, S is a start non-terminal and both u and B derive e.
- 2. (ii) Compute the FIRST and FOLLOW set for all non-terminals for the following grammar (S is a start
non-terminal): S -> ACB | cbB | e, A -> da | BC
Grammar Ambiguity
- 3. Check whether the following grammar is ambiguous or unambiguous. If yes, write an equivalent
unambiguous grammar for the following grammar: R -> R + R | R . R | R * | a | b | c
Regular Expressions
- 4. Find the regular expression for the following language L = {na(w) mod 3 = 0 | w in {a, b}* and na(w) is the
number of a's in w}
Three Address Code
- 5. Generate the three address code for the following C program (assume w = 4 bytes per word): sum = 0;
for (i = 1; i <= 10; i++) sum = sum + a[i] + b[i];
Symbol Table
- 6. (a) What is the role of the symbol table in Compiler? Discuss any two approaches for the implementation
of a symbol table.
SLR Parsing
- 6. (b) Check whether the following grammar is SLR(1) or not? Construct a SLR(1) parsing table for the
following grammar: S -> bAc | BC | bBa. Also, parse the string bce using the SLR(1) parsing table.
Directed Acyclic Graph (DAG)
- 7. (a) Discuss the application of DAG. Construct the DAG for the following basic block: d = c * e; f = a + b; b
= c * a;
LALR Parsing
- 7. (b) Construct a LALR(1) parsing table for the following grammar: S -> BB. Also, parse the string abab
using the LALR(1) parsing table.
LEX Tool
- 8. (a) Explain how LEX tool is used in compiler design.
Parse Tree Construction
- 8. (b) Consider two binary operators 't' and 'U' with the precedence of operator U being lower than that of
the operator t. The operator t is right-associative while operator U is left-associative. Construct a correct
parse tree for the expression (7 $ 3 t 4 t 3 $ 2 $ 5) using given information.
Code Optimization
- 8. (c) Explain the following with respect to code optimization: (i) Peephole Optimization, (ii) Reduction in
Strength
Predictive Parsing Table (PPT)
- 9. (a) Consider the following grammar: S -> aBDh | g | e. (i) Construct a Predictive parsing table (PPT) for
the above grammar. (ii) Parse the string acgfh using the PPT obtained in part (i).
Operator Precedence Parser
- 9. (b) Consider the following grammar: (i) Compute the LEADING and TRAILING set for the grammar. (ii)
Design the operator precedence parser for the grammar.
Quadruples and Triples
- 9. (c) Write a Quadruples and Triple representation for the following statement: B = c + D