UNIT 1: Introduction To Compiler Design
UNIT 1: Introduction To Compiler Design
UNIT 1: Introduction To Compiler Design
For each
question:
- For *3-5 mark* questions, provide more detailed answers (100-200 words).
2. Include diagrams where necessary. If a question requires a diagram, create a simple and clear diagram and
incorporate it into the answer.
3. If references are needed, include reliable sources with links to back up any technical or theoretical
information.
Example format:
Here is the complete list of questions from the "Question Bank Compiler Design 2024":
1. What is Compiler? Design the Analysis and Synthesis Model of Compiler. (4 marks)
7. What are the major components of a simple compiler, and what functions do they perform? (4 marks)
8. What are the advantages and disadvantages of using an interpreter over a compiler? (4 marks)
13. How does semantic analysis differ from syntax analysis? (4 marks)
18. Discuss the importance of tokenization in the lexical analysis phase. (4 marks)
19. What is input buffering in the context of lexical analysis? Why is it necessary? (3 marks)
21. Differentiate between tokens, patterns, and lexemes. (3 marks) (in table)
22. Explain how reserved words and identifiers are distinguished during token specification. (4 marks)
23. Discuss the role of finite automata in the recognition of tokens. (4 marks)
25. Differentiate between deterministic finite automata (DFA) and non-deterministic finite automata
(NFA). (8 marks) (in table)
26. Convert the regular expression a(b|c)* into a non-deterministic finite automaton (NFA). Draw the state
transition diagram for the NFA. (8 marks)
27. Given the regular expression (01|10)*, construct the corresponding deterministic finite automaton
(DFA). Show each step of the conversion process. (8 marks)
28. Consider the regular expression 0(0|1)*1. Create the NFA for this regular expression, and then convert
it into a DFA. Verify that the DFA correctly accepts strings like "01", "001", and "011", and rejects
strings like "00" and "10". (8 marks)
29. Given the regular expression (a|b)*abb, construct the corresponding NFA and then use the subset
construction method to derive the equivalent DFA. Provide the state transition diagram for both the
NFA and DFA. (8 marks)
31. What are the problems associated with Top-Down Parsing? (4 marks)
32. Write the production rules to eliminate the left recursion and left factoring problems. (3 marks)
33. Remove left recursion from the following Grammar:
A -> ABd | Aa | a
B -> Be | b (3 marks)
36. Write Rules to construct the FIRST and FOLLOW functions. (4 marks)
37. Perform Operator Precedence parsing for input string: (id+id)*id using the grammar:
E -> E + T | T
T -> T * F | F
F -> (E) | id (3 marks)
38. Write the algorithm to create a Predictive parsing table with the scanning of input strings. (8 marks)
40. Perform shift-reduce parsing of the input string “id1+id2+id3” using the grammar:
E -> E + E
E -> E * E
E -> id (8 marks)
41. Write the properties of LR parser with its structure. Also, explain the techniques of LR parser. (4 marks)
44. Write the rules to construct the SLR parsing table. (3 marks)
45. Construct the SLR parsing table and parse the input “ab+a” using the grammar:
E -> E + T | T
T -> TF | F
F -> F | a | b (4 marks)
47. What is LALR parser? Construct the set of LR(1) items for this grammar:
S -> CC
C -> aC
C -> d (3 marks)
49. Write the comparison among SLR Parser, LALR parser, and Canonical LR Parser. (4 marks)
50. What are the limitations of recursive descent parsing? Provide an example grammar where recursive
descent parsing fails. (4 marks)
51. Create the predictive parsing table for the following grammar:
S -> (S)S | ε
Parse the input string "(())" using the table. (4 marks)
52. What are the common conflicts encountered in shift-reduce parsing? Provide examples for
shift/reduce and reduce/reduce conflicts. (4 marks)
53. Construct the SLR parsing table and parse the input string "cdcd" using the grammar:
S -> CC
C -> cC | d
Show each step of the parsing process. (4 marks)
54. Construct the canonical LR(1) (CLR) parsing table for the grammar:
E -> E + T | T
T -> T * F | F
F -> (E) | id
Parse the string "id + id * id" and demonstrate how the CLR parser processes this input. (4 marks)
58. What is a Syntax-Directed Definition (SDD), and how is it used in compilers? (4 marks)
61. What is an S-attributed definition, and how is it evaluated in a bottom-up parsing approach? (4 marks)
63. What is an L-attributed definition, and how does it differ from an S-attributed definition? (4 marks)
64. Describe the process of generating intermediate code using a syntax-directed translation scheme for
arithmetic expressions. (4 marks)
65. How do inherited and synthesized attributes influence the design of translation schemes? Provide an
example to demonstrate this. (4 marks)
66. Differentiate between synthesized translation and inherited translation. (4 marks) (in table)
67. Differentiate between compile-time errors and run-time errors with examples. (4 marks) (in table)
68. Describe the different types of errors that can occur during lexical, syntax, and semantic analysis in a
compiler. (3 marks)
69. What are the typical error handling strategies employed during the various phases of compilation? (3
marks)
70. Explain the role of error detection in a compiler. How does it differ from error recovery? (3 marks)
71. What are the different strategies for error recovery in parsing? Compare and contrast panic mode,
phrase-level recovery, error productions, and global correction. (8 marks)
72. Provide an example of an ad-hoc error recovery technique that could be used in lexical analysis and
explain how it operates. (4 marks)
73. Discuss the advantages of using systematic methods like global correction over ad-hoc methods.
Provide an example scenario. (3 marks)
74. Explain the concept of error productions and how they are used in systematic error recovery. (4 marks)
75. Write the definition of the symbol table and the procedure to store the names in the symbol table. (4
marks)
76. What are the data structures used in the symbol table? (3 marks)
77. What are the limitations of stack allocation? (3 marks)
79. Write the comparison among Static allocation, Stack allocation, and Heap Allocation with their merits
and limitations. (8 marks)
80. What is the activation record? Write the various fields of Activation Record. (4 marks)
81. What are the limitations of static storage allocation? Explain the problem of dangling references. (4
marks)