Compiler Design - Topic-wise Numbered
Question Bank
1. Overview of Compilation
1. 1. What is a compiler? Explain the structure and phases of a compiler with a diagram.
2. 2. Differentiate between a compiler and an interpreter.
3. 3. What is the difference between the front-end and back-end of a compiler?
4. 4. Explain the Analysis and Synthesis Model of compilation.
5. 5. Define bootstrapping. What is its use in compiler design?
6. 6. What is a cross-compiler? Where is it used?
7. 7. What are passes in a compiler? Compare one-pass and two-pass compilers.
8. 8. List and explain challenges in designing an efficient compiler.
9. 9. Discuss the applications and significance of compiler technology in modern
computing.
10. 10. How does compiler technology contribute to software performance and
optimization?
11. 11. What are the cousins of the compiler: linker, loader, and preprocessor?
12. 12. What are the five essential properties of a good compiler?
2. Introduction to Syntax Analysis
13. 13. What is parsing? Explain parsing techniques with a hierarchical diagram.
14. 14. Role of a parser in compiler design.
15. 15. What are context-free grammars (CFG)? Provide examples.
16. 16. What is ambiguity in grammars? How can it be resolved?
17. 17. Explain parse trees and derivations (leftmost, rightmost).
18. 18. Differentiate between top-down and bottom-up parsing.
19. 19. Provide CFG and parse tree for constructs like if-else or arithmetic expressions.
20. 20. Explain non-context-free constructs in programming languages.
21. 21. Write an algorithm to construct a predictive parsing table.
3. Top-Down and Bottom-Up Parsing (LL, LR, etc.)
22. 22. Define FIRST and FOLLOW sets and their construction rules.
23. 23. Calculate FIRST and FOLLOW for:
a. S → aBDh, B → cC, C → bC | ε, D → EF, E → g | ε, F → f | ε
b. S → aAbB | bAaB | ε; A → S; B → S
c. E → E+T; T → F; F → (E) | id
24. 24. Define recursive descent parsing and predictive (LL(1)) parsing with examples.
25. 25. What are the limitations and error recovery mechanisms of top-down parsing?
26. 26. Explain LL(1) parsing with example.
27. 27. Explain left recursion and its removal with example.
28. 28. What is left factoring? Rule and example.
29. 29. Compare top-down and bottom-up parsers.
30. 30. Construct syntax tree and DAG for expression (a*b)+(a*b)/(a*b)
31. 31. Explain bottom-up parsing with example.
32. 32. Explain shift-reduce parsing with example and the concept of handle pruning.
33. 33. What is the LR parsing algorithm? Describe shift-reduce actions and parsing table.
34. 34. Construct LR parsing table for a given grammar.
35. 35. Construct collection of LR(0) items for: S → AabAc | de | bda; A → d
36. 36. Define viable prefixes, kernel items, closure, and GOTO operations.
37. 37. Explain LR(0), SLR(1), LALR(1), and LR(1) parsers. Compare them with examples.
38. 38. Provide an example grammar that is LR(1) but not SLR(1)/LALR(1).
39. 39. What is YACC? Explain how it generates parsers and handles errors.
40. 40. Explain augmented grammar and how to check if a grammar is LL(1).
41. 41. Shift-reduce conflicts in bottom-up parsing (explain any one).
42. 42. Check if a grammar is LL(1).
43. 43. Draw FA for (0+1)*101(0+1)*
44. 44. Construct NFA from a regular expression and convert to DFA (a/b)*ab#
4. Syntax-Directed Definitions (Attribute Grammars)
45. 45. What are syntax-directed definitions (SDDs)? Provide examples.
46. 46. Define synthesized and inherited attributes with examples.
47. 47. Compare S-attributed and L-attributed grammars.
48. 48. Explain the use of dependency graphs and evaluation order in SDDs.
49. 49. Provide annotated parse trees and SDDs for arithmetic/control expressions.
50. 50. Difference between syntax tree and parse tree. Draw both for a given expression.
51. 51. What are the limitations of attribute grammars?
5. Semantic Analysis
52. 52. What is semantic analysis? What is its role in compilation?
53. 53. How is type checking and type inference performed? Detect type mismatches.
54. 54. Explain the use of symbol tables. Discuss suitable data structures and scope
representation.
55. 55. Describe operations used in symbol table.
56. 56. Use of symbol table and how identifiers are stored.
57. 57. What are the techniques and challenges for semantic error recovery?
58. 58. Provide semantic analysis for constructs like function calls, arrays, assignments, etc.
6. Intermediate Code Generation
59. 59. What is intermediate code? What are its types and benefits?
60. 60. Compare intermediate representations: quadruples, triples, indirect triples.
61. 61. Translate arithmetic and control-flow constructs to intermediate code.
62. 62. Explain Static Single Assignment (SSA) form and its advantages.
63. 63. Define short-circuit evaluation and backpatching with examples.
64. 64. Construct syntax tree, DAG, and three-address code for given expressions.
65. 65. Write three-address code for:
int i = 0;
while(i < 10) {
printf("i=%d", i);
i++;
}
66. 66. Examples to illustrate intermediate code generation for all constructs.
67. 67. Write three-address code for array access, if-else, loops, etc.
7. Run-Time Environments
68. 68. What is an activation record? How is stack space managed during runtime?
69. 69. Explain static vs dynamic memory allocation. What is a dangling reference?
70. 70. How are recursive procedures and non-local variables handled?
71. 71. Differentiate procedures with and without nesting.
72. 72. Explain tail-recursion and its effect on stack allocation.
8. Introduction to Machine Code Generation and Optimization
73. 73. What is machine code generation? Provide steps and examples.
74. 74. What are the major challenges in machine code generation?
75. 75. Describe machine-independent optimizations like:
a. Constant folding
b. Common subexpression elimination
c. Dead code elimination
76. 76. Write an algorithm for global common subexpression elimination.
77. 77. What is peephole optimization? Provide examples.
78. 78. Describe design issues in code generation.
79. 79. Explain register allocation and instruction selection.