Compiler Design CS8602 Questions & Problem Answers
Compiler Design CS8602 Questions & Problem Answers
QUESTION BANK
VII SEMESTER
CS8602 – COMPILER DESIGN
Regulation – 2017
Academic Year 2019 – 20 EVEN
Prepared by
Mrs. K. Devi, Assistant Professor/CSE
Mrs.S.Shanthi, Assistant Professor/CSE
5 Summarize in detail about how the tokens are specified by the (13) Understand BTL2
compiler with suitable example.
7(i)Solve the given regular expression (a/b)* abb (a/b)* into NFA (7) Apply BTL3
using Thompson construction.
(ii).Compare NFA and DFA. (6)
8 Create DFA the following NFA. (13) Create BTL6
M=({q0,q1},{0,1},δ,q0,{q1})
Where δ(q0,0)={q0,q1}
δ (q0,1)={q1}
δ(q1,0)=ɸ
δ(q1,1)={q0,q1}
9 (i) Show how the DFA is directly converted from an augmented (7) Apply BTL3
regular expression
((ε/a)b*)* .
(ii)Draw NFA for the regular expression ab*/ab (6)
i) 10. (i)Define the language accepted by FA. Convert the following NFA Remember BTL1
into DFA. (7)
0 1
p {p,q} {p}
q {r} {r}
r {s} ɸ
*s {s} {s}
(ii)Draw the DFA for the augmented regular expression (a|b)*# (6)
directly using syntax tree.
11 Define Lex and Lex specifications. How lexical analyzer is (13) Remember BTL1
constructed using lex? Give an example.
12 (i)Explain an algorithm for Lex that recognizes the tokens. (7) Evaluate BTL5
(ii) Describe in detail the tool for generating lexical analyzer. (6)
13 (i)Analyze the algorithm for minimizing the number of states of a (7) Analyze BTL4
DFA
A →Ac | Sd |ε
2. Define handle pruning. Remember BTL1
3. Solve FIRST and FOLLOW by use the LL(1) grammar. Apply BTL3
4. List the concepts of Predictive parsing and shift reduce parsing. Remember BTL1
5. Differentiate Top Down parsing and Bottom Up parsing. Understand BTL2
6. Define Recursive Descent Parsing. Remember BTL1
7. List out the properties of parse tree. Remember BTL1
8. Compare and contrast top down parsing with bottom up parsing Analyze BTL4
techniques.
9. Solve the following grammar is ambiguous: S→aSbS / bSaS / € Apply BTL3
10. Define kernel and non-kernel items. Remember BTL1
11. Difference between ambiguous and unambiguous grammar. Analyze BTL4
12. Define parser. Give the advantages and disadvantages of LR Evaluate BTL5
parsing.
13. Define Phrase level error recovery. Remember BTL1
14. Evaluate the conflicts encountered while parsing. Evaluate BTL5
15. Analyze the categories of shift reduce parsing. Analyze BTL4
16. How to create an input and output translator with YACC? Create BTL6
17. Summarize the Error recovery scheme in yacc. Understand BTL2
18. What is the main idea of Left factoring? Give an example. Understand BTL2
19. Discuss when Dangling reference occur? Understand BTL2
20. Examine the approach would you use in Panic mode error Apply BTL3
recovery.
PART-B (13- MARKS)
1. (i)Explain left recursion and Left Factoring. (7) Analyze BTL-4
(ii)Eliminate left recursion and left factoring for the following (6)
grammar.
E→E+T|E-T|T
T → a | b | ( E ).
2. (i)What is an ambiguous and un ambiguous grammar? (5) Create BTL6
Identify the following grammar is ambiguous or not.
E→E+E | E*E | (E)|-E |id for the sentence id+id*id
(ii) Prepare the following grammar is LL(1) but not SLR(1).
S→AaAb | BbBa
A→€ (8)
B→€
3. (i)Illustrate the predictive parser for the following grammar. (8) Apply BTL3
S→ (L) | a
T→T*F | F
F→(E) | id
(ii)Construct Stack implementation of shift reduce parsing for the (6)
grammar
E->E+E
E->E*E
E->(E)
E->id and the input string id1+id2*id3
5. (i).Describe on detail about the role of parser. (7) Remember BTL1
(ii)Discuss about the context-free grammar. (6)
6. (i).What are the different kinds of syntax error phased by a (7) Remember BTL1
program? Explain in detail.
(ii).What are the Error recovery techniques used in Predictive
parsing? Explain in detail. (6)
7. Give the predictive parser for the following grammar. Understand BTL2
S→ (L) | a
L→ L, S | S
i.Give a rightmost derivation for (a, (a, a)) and show the handle of (5)
each right-sentential form.
ii.Show the steps of a shift reduce parser. (8)
8. Analyze the following grammar is a LR(1) grammar and construct (13) Analyze BTL4
LALR parsing table.
S → Aa | bAc | dC | bda
A→ d.
Parse the input string bdc using the table generated.
9. (i)Define YACC parser generator. List out the Error recovery (8) Remember BTL1
actions in YACC.
(ii)List out different error recovery strategies. Explain them.
(5)
10. (i)Show SLR parsing table for the following grammar (8) Apply BTL-3
S → Aa | bAc | Bc | bBa
A→d
B→d
And parse the sentence "bdc" and "dd".
(ii)Construct a parse tree for the input string w-cad using top down
(ii)Predict the following grammar for generate the SLR parsing (8)
table.
E→E+T | T
T→T*F | F
F→F*| a| b
12 (i)Consider the following grammar (10) Apply BTL3
S → AS|b
A→SA|a. (3)
Construct the SLR parse table for the grammar.
(ii)Show the actions of the parser for the input string “abab”.
13. Give the LALR for the given grammar. (13) Understand BTL-2
E → E + T | T , T → T * F | F , F → ( E ) / id and parse the
following. ( a + b ) * c
14. Examine the following grammar using canonical parsing table. (13) Remember BTL-1
E→E+T
F→(E)
E→T
F → id.
T→T*F
T→F
2 Explain in detail about the various types of Top –down parsing. (15) Evaluate BTL5
4 What is CFG .Explain in detail about the Context-Free Grammar. (15) Evaluate BTL5
UNIT-III INTERMEDIATE CODE GENERATION
Syntax Directed Definitions, Evaluation Orders for Syntax Directed Definitions, Intermediate
Languages: Syntax Tree, Three Address Code, Types and Declarations, Translation of Expressions,
Type Checking.
PART-A (2 - MARKS)
1. List out the two rules for type checking. Remember BTL1
2. Compare synthesized attributes and inherited attributes. Analyze BTL4
3. What is Annotated parse tree? Remember BTL1
4. Define Type checker. Remember BTL1
5. What is a syntax tree? Draw the syntax tree for the assignment Create BTL6
statement a := b * -c + b * -c
6. Define type systems. Remember BTL1
7. Express the rule for checking the type of a function. Understand BTL2
8. Define Syntax directed definition of a simple desk calculator. Remember BTL1
9. Summarize about the S-attributed definition? Evaluate BTL5
10. Give the difference between syntax-directed definitions and Understand BTL2
translation schemes.
11. State the type expressions. Remember BTL1
12. Illustrate the methods of implementing three-address statements. Apply BTL3
13. Differentiate S-attribute and L-attribute definitions. Analyze BTL4
14. Create the target machine instructions to implement the call Create BTL6
statement in static allocation.
15. Translate the conditional statement if a<b then 1 else 0 into three Understand BTL2
address code.
16. Test whether the following rules are L-attribute or not? Semantic Evaluate BTL5
rules
A.s = B.b;
B.i = f(C.c,A.s)
17. What are the methods of representing a syntax tree? Understand BTL2
18. Explain the syntax directed definition for if-else statement Analyze BTL4
19. Examine the usage of syntax directed definition Apply BTL3
20. Discuss the three address code sequence for the assignment Understand BTL2
statement. d=(a-b)+(a-c)+(a-c)
PART-B (13- MARKS )
1. Discuss the following in detail about the Syntax Directed Understand BTL2
Definitions.
(i)Inherited Atrributes and Synthesized attributes. (7)
(ii) Evaluate SDD of a parse tree. (6)
Evaluate the expressions for the SDD annotated parse tree for the Evaluate BTL5
2. following expressions.
(i)3 * 5 + 4n (7)
3. Suppose that we have a production A→BCD. Each of the four non (13) Analyze BTL4
terminal A, B, C and D have two attributes: S is a synthesized
attribute and i is an inherited attribute. Analyze For each of the sets
of rules below tell whether (i)the rules are consistent with an S-
attributed definition(ii) the rules are consistent with an L-attributed
definition and(iii) whether the rules are consistent with any
evaluation order at all?
a) A.s = B.i + C.s
b) A.s = B.i + C.s and D.i = A.i + B.s.
4. Apply the S-attributed definition and constructs syntax trees for a (13) Apply BTL3
simple expression grammar involving only the binary operators +
and -. As usual, these operators are at the same precedence level
and are jointly left associative. All nonterminal have one
synthesized attribute node, which represents a node of the syntax
tree.
Production:L->E$ E→E1+T,E →T, T->T1*F,T→ ( E),T→ digit.
6. Create variants of Syntax tree. Explain in detail about it with (13) Create BTL6
suitable examples.
7. (i).Analyse the common three address instruction forms. (7) Analyze BTL4
(ii). Explain the two ways of assigning labels to the following three (6)
address statements
Do i=i+1;
While (a[i]<v);
8. Describe.in detail about Remember BTL1
(i) Quadruples (7)
(ii) Triples. (6)
9. (i) Describe in detail about addressing array Elements. (6) Remember BTL1
(ii) Discuss in detail about Translation of array reference. (7)
Describe in detail about types and declaration with suitable (13) Remember BTL1
10. examples.
11. Compare three address code for expression with the Incremental (13) Analyze BTL-4
translation.
12. Show the intermediate code for the following code segment along (13) Understand BTL-2
with the required syntax directed translation scheme
while ( i < 10 )
if ( i % 2 == 0 )
evensum = evensum + i
else
13. (i)State the rules for type checking with example. (7) Remember BTL-1
(ii) Give an algorithm for type inference and polymorphic function. (6)
14. Illustrate an algorithm for unification with its operation. (13) Apply BTL-3
PART-C(15 -MARKS)
1. Create the following uind the arithmetic expression a+- (b+c)* (15) Create BTL-6
into
(i)Syntax tree
(ii)Quadruples
(iii)Triples
(iv)Indirect Triples
2. Explain the steps for constructing a DAG. Construct the DAG for (15) Evaluate BTL5
the following expression
((x+y)-((x+y)*(x-y)))+((x+y)*(x-y))
3. Generate an intermediate code for the following code segment (15) Create BTL-6
with the required syntax-directed translation scheme.
if ( a > b)
x=a+b
else
x=a-b
4. What is Type conversion? What are the two types of type (15) Evaluate BTL5
conversion? Evaluate the rules for the type conversion.
UNIT IV- RUN-TIME ENVIRONMENT AND CODE GENERATION
Storage Organization, Stack Allocation Space, Access to Non-local Data on the Stack, Heap
Management - Issues in Code Generation - Design of a simple Code Generator.
PART-A (2 -MARKS)
1. List out limitations of the static memory allocation. Remember BTL1
How the storage organization for the run-time memory is Apply BTL3
2.
organized?
3. What is heap allocation? Remember BTL1
4. How the activation record is pushed onto the stack? Apply BTL3
5. Analyze the storage allocation strategies. Analyze BTL4
6. State the principles for designing calling sequences. Remember BTL1
7. List out the dynamic storage techniques. Remember BTL1
8. Define the non-local data on stack. Remember BTL1
9. Define variable data length on the stack. Remember BTL1
10. Differentiate between stack and Heap allocation Analyze BTL4
11. Distinguish between static and dynamic storage allocation. Understand BTL2
12. Discuss the main idea of Activation tree. Understand BTL2
13. Give the fields in an Activation record. Understand BTL2
14. Compose space efficiency and program efficiency. Create BTL6
15. Construct typical memory hierarchy configuration of a computer. Evaluate BTL5
16. How would you solve the issues in the design of code generators? Apply BTL3
PART-C (15-MARKS)
1. Suppose the heap consists of seven chunks, starting at address (15) Evaluate BTL-5
0. The sizes of the chunks, in order, are 80, 30, 60, 50, 70, 20, 40
3. Compute the grn and Kill sets for each Block, In and Out sets for (15) Evaluate BTL5
each block, Compute e_gen and e_kill from the given diagram.