Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

UNIT 1: Introduction To Compiler Design

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

"I have a question bank with multiple questions, and each question has different weightage in marks.

For each
question:

1. Answer the question according to the marks specified:

- For *1-2 mark* questions, provide concise answers (50-100 words).

- For *3-5 mark* questions, provide more detailed answers (100-200 words).

- For *6-10 mark* questions, provide comprehensive answers (200-500 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:

- Question 1 (2 marks): [Question text]

- Answer: [50-100 words]

- Question 2 (5 marks): [Question text]

- Answer: [100-200 words]

- Diagram: [if needed]

- Question 3 (10 marks): [Question text]

- Answer: [200-500 words]

- Diagram: [if needed]

- References: [if required]

Here is the complete list of questions from the "Question Bank Compiler Design 2024":

UNIT 1: Introduction to Compiler Design

1. What is Compiler? Design the Analysis and Synthesis Model of Compiler. (4 marks)

2. Write down the five properties of the compiler. (3 marks)

3. What is a translator? Write down the steps to execute a program. (3 marks)

4. Discuss all the phases of the compiler with a diagram. (8 marks)

5. What is the role of the optimization phase in a compiler? (4 marks)

6. Explain the role of each phase in the translation process. (8 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)

9. What is the purpose of a linker in the compilation process? (4 marks)

10. How does a loader differ from a linker? (4 marks)

11. Describe the role of a dynamic linker in modern systems. (4 marks)

12. List and describe the different types of compilers. (8 marks)

13. How does semantic analysis differ from syntax analysis? (4 marks)

14. How do single-pass and multi-pass compilers differ? (4 marks)

15. Describe the advantages of using a multi-pass compiler. (4 marks)

UNIT 2: Lexical Analysis

16. Explain the main functions performed by a lexical analyzer. (4 marks)

17. Write a short note on:


a. YACC
b. Pass
c. Bootstrapping
d. LEX Compiler (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)

20. Describe the role of sentinels in input buffering. (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)

24. Describe the process of token recognition in a lexical analyzer. (3 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)

UNIT 3: Parsing Techniques

30. Explain the parsing techniques with a hierarchical diagram. (4 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)

34. Do left factoring in the following grammar:


A -> aAB | aA | a
B -> bB | b (3 marks)

35. Write a short note on:


a. Ambiguity (with example)
b. Recursive Descent Parser
c. Predictive LL(1) parser (working)
d. Handle pruning
e. Operator Precedence Parser (4 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)

39. Consider Grammar:


S -> AaAb | BbBa
A -> €
B -> €
Is it LL(1)? Parse the input string “ba”. (4 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)

42. Write a short note on:


a. Augmented grammar
b. Kernel items
c. Rules of closure operation and goto operation
d. Rules to construct the LR(0) items (3 marks)

43. Compute closure and goto for the following grammar:


S -> Aa | bAc | Bc | bBa
A -> d
B -> d (3 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)

46. Write the rules to construct the LR(1) items. (3 marks)

47. What is LALR parser? Construct the set of LR(1) items for this grammar:
S -> CC
C -> aC
C -> d (3 marks)

48. Show that the following grammar:


S -> Aa | bAc | Bc | bBa
A -> d
B -> d
is LR(1) but not LALR(1). (4 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)

55. Construct the LALR(1) parsing table for the grammar:


S -> L = R
S -> R
L -> *R
L -> id
R -> L
Parse the input string "id = *id" and trace each step of the parsing. (4 marks)

56. Construct the LR(0) items for the grammar:


S -> E
E -> E + T | T
T -> T * F | F
F -> (E) | id
Identify the conflicts and explain how they can be resolved using SLR or LALR parsing techniques. (4
marks)

57. Create the SLR parsing table for the grammar:


S -> A a | b A c | d c | b d a
A -> d
Parse the string "bdac". Show the stack contents, input, and action at each step. (4 marks)

58. What is a Syntax-Directed Definition (SDD), and how is it used in compilers? (4 marks)

59. Given the grammar:


E → E1 + T { E.val = E1.val + T.val }
E → T { E.val = T.val }
T → T1 * F { T.val = T1.val * F.val }
T → F { T.val = F.val }
F → ( E ) { F.val = E.val }
F → id { F.val = id.val }
Define the synthesized attributes and explain how the attribute values are computed during parsing. (4
marks)

60. Given the grammar:


E→E+T
E→T
T→T*F
T→F
F→(E)
F → id
Construct the syntax tree for the expression "id + id * id". (4 marks)

61. What is an S-attributed definition, and how is it evaluated in a bottom-up parsing approach? (4 marks)

62. Given the following grammar and its SDD:


L → L1 , E { L.val = L1.val + [E.val] }
L → E { L.val = [E.val] }
E → num { E.val = num.val }
Perform a bottom-up evaluation of the S-attributed definition for the input "num1 = num + num". (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)

UNIT 4: Error Handling

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)

UNIT 5: Symbol Table and Runtime Environment

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)

78. Write two important points about heap management. (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)

You might also like