CD Question Bank

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Question Bank J

General
Question Bank

GMIT | KJS
Question Bank J

Topic 1: Introduction to Compiler


1... Draw structure of Compiler.(3)

2. Explain the roles of Linker and Loader.(3-5)

3. Explain the analysis and synthesis model of compilation. List the factors that affect the
design of compiler. Also list major functions done by compiler.(6)

4... Explain the phases of compiler with an example. (7)

5. Explain how type checking is performed in compiler. (3)

6. Explain how error reporting is performed in compiler.(2)

7... Explain lexical analysis phase of a compiler and for a statement, write output of all
phases (except of an optimization phase) of a compiler. Assume a ,b and c are of float type

float a = a + b * c * 2; (7)

8. Explain the roles of preprocessor. (3)

9...List and Explain the types of compilers in detail.(7)

10... What is pass of a compiler? Explain how the single and multi pass compilers work. (7)

11. Compare one pass and two pass compilers.(2)

Topic 2 : Lexical Analyzer


1. Write a brief note on input buffering techniques. (7)

2. Write a short note on Lex actions.(3)

3... Convert the NFA-€ into NFA without € for following NFA.(7)

q1

€ €

q0 € a q3

€ q2 a

4... Construct a DFA for a given regular expression (010+00)*(10)*. (7)

5. Draw Deterministic Finite Automata for the binary strings ending with 10. (4)

GMIT | KJS
Question Bank J
6. Construct DFA for the following regular expression. Use firstpos, lastpos and
followpos function to construct DFA. (7)

(a* | b*)*

7. Convert the following regular expression into deterministic finite automata.(3)

(a + b) * abb (a + b)*

8... Find the regular expression corresponding to given statement, subset of {0,1}*(4)

1. The language of all strings containing at least one 0 and at least one 1.

2. The language of all strings containing 0's and 1's both are even.

3. The language of all strings containing at most one pair of consecutive 1's.

4. The language of all strings that do not end with 01.

9. Draw syntax tree and DAG for the statement a= (a*b+c) ^ (b+c)*b+c. Write three address
for the same.(3)

10. Draw deterministic finite automata for: (7)


1. (0+1)*101(0+1)* 2. 10(0+1)*1

11. Construct minimum state DFA's for following regular expression (a|b)*a(a|b)(a|b)

12... What are regular expressions? Find the regular expression described by
DFA {{A,B},{0,1},δ ,A, {B}}, where δ is detailed in following table.

0 1
A A B
B Φ A

please note B is accepting state.

Describe the language defined by the regular expression. (7)

13... Construct the NFA using thompson's notation for following regular expression and
then convert it to DFA. (7)

a+(c | d) b*f #

14. Draw the DFA for the regular expression (a|b)*abb using set construction method only.(7)

15. . Convert the (a|b|c)*d*(a*|b)ac*# regular expression to DFA directly and draw its DFA. (7)

GMIT | KJS
Question Bank J

Topic 3 : Parsing
1. Write a short note on context free grammar (CFG) explain it using suitable example. (7)

2. Define left recursion (2)

3... Consider following grammar for arithmetic expressions

E -> E+T | T

T -> T*F | F

F -> (E) | id

Eliminate left recursion from this grammar. (5)

4. S -> Aa | b

A -> Ac | Sd | €

Eliminate left recursion from this grammar. (5)

5... Explain the left factoring and perform the left factoring of following grammar.

(5) A -> ad | a | ab | abc | b

6. For the following grammar

(7) D -> T L;

L -> L, id | id

T -> int | float

1) Remove left recursion (if required)

2) Find first and follow for each non terminal for Resultant grammar

3) Construct LL(1) parsing table

4) Parse the following string (show stack action clearly) and draw parse tree for the input:

int id, id

7... How top down and bottom up parser will parse the string 'bbd' using grammar A ->
bA|d. Show all steps clearly.(7)

8.. Write down C program for recursive descend parser for: (7)

GMIT | KJS
Question Bank J
S -> ABC

B-> 1B | ^

A -> 0A1 | ^

C -> 1C0 | ^

9. Implement the following grammar using recursive descent parser. (8)

S -> Aa | bAc | bBa

A -> d

B -> d

10... Draw the transition diagram for the predictive parser for the following grammar. (7)

E -> TE'

E' -> +TE' | €

T -> FT'

T -> *FT' | €

F -> (E) | id

11. Explain Non Recursive Predictive Parsers. Draw the block diagram of it. (4)

12. Consider following grammar for arithmetic expressions and construct parsing table. (7)

E -> E + T | T

T -> T * F | F

F -> (E) | id

13. Test whether grammar is LL(1) or not and construct parsing table. (7 + 7)

(1) S -> AaAb | BbBa

A -> €

B -> €

(2) S -> 1AB | €

A ->1AC | 0C

GMIT | KJS
Question Bank J

B -> 0S

C -> 1

14. Find out FIRST and FOLLOW set for all the Nonterminals (7)

S -> AcB | cbB | Ba

A -> da | BC

B -> g | €

C -> h | €

15... Is the following grammar suitable for LL(1) parsing? If not make it suitable for LL(1)
parsing compute FIRST and FOLLOW sets. Generate the parsing table. (7)

S -> AB A

-> Ca | €

B -> BaAc |c

C -> b | €

16. Draw parsing table for Table Driven Parser for the given grammar. Is the grammar LL(1)?
(7)

A -> AaB | x

B -> BCb | Cy

C -> Cc | €

17... Implement the following grammar using Table Driven parser and check whether it is LL(1)
or not? (8)

S -> aBDh

B -> cC

C -> bC | €

D -> EF

E -> g | €

GMIT | KJS
Question Bank J

18.... What is bottom - up parsing? What is handle? And also differentiate top down and bottom
up parsing. (7)

19... Explain shift reduce parser with suitable example. (7)

20. Explain SLR parser in detail with the help of a suitable example. (7)

21... E -> E + T | T T

-> T * F | F F ->

(E)

F -> id

Construct SLR parsing table. (7)

22. Construct SLR(1) parsing table for the following grammar. (7) S

-> 0S0 | 1S1 | 10

23. Generate the SLR parsing table for the following grammar. (8) S

-> Aa | bAc | bBa

A -> d B

-> d

24. Construct the canonical parsing table for the following grammar. S'

-> S

S -> cC C ->

cC | d

25. Explain LALR parser in detail. Support your answer with example. (7)

26... Differentiate SLR, CLR, and LALR . Also justify the statement "A class of grammar that
can be parsed using LR methods is a proper subset of the class of grammar that can be parsed
with predictive parser" . (7)

27... Construct an LALR (1) parsing table for the following grammar: (7+7)

(1) S -> Aa | bAc | dc | bda

A -> d

(2) S -> Aa | aAc | Bc | bBa

A -> d

GMIT | KJS
Question Bank J
B -> d

28... Consider the following grammar (7)

E -> E + T | T

T -> TF | F

F -> F* | a | b

(1) Construct the SLR parsing table.

(2) Construct LALR parsing table.

29. Explain the conflict in LR parsing. (1)

30... Define an operator precedence grammar. also write down the rules to find relations between
each pair of terminal symbols. (8)

31... Compute the operator precedence matrix and precedence function for the following
grammar if it exits. + ,* ,- , / , id , num , (and) are terminal symbols.(7)

G -> E

E -> E + T | E - T | T

T -> T * F | T/F/F F -

> num | id | (E)

32. Explain the parser generator. (1)

33... List the error generated by the syntax analysis phase. (3)

34. Discuss error handling methods in the syntax analysis phase. (4)

35. . Explain how panic mode recovery can be implemented. (7)

36. . How can phrase level recovery be implemented in LR parsers? (2)

37... Show syntax directed definition for simple desk calculator. Also show annotated parse tree for
3*5+4n, where n indicates newline. (7)Discuss inherited attributes using a suitable grammar. (4)

38. Explain the dependency graph. (1)

40 What is the difference between parse tree and syntax tree? (2)

41. Draw the parse tree for the expression a : := a + a * b + a * b * c - a / b + a * b.

42... Give the translation scheme that converts infix to prefix expression for the following
grammar and also generate the annotated parse tree for input string 7+3+2 ; (7)

E -> E + T;
E -> T; T -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
GMIT | KJS
Question Bank J

Topic 4 : Error Recovery


1. Explain all error recovery strategies using suitable examples. (7)

Topic 5 : Intermediate Code Generation


1.. What is intermediate code? What is its importance.? (4)

2. Discuss various representation of three address code. (3)

3.. Explain quadruple, triple and indirect triple with suitable example. (6)

4... What is intermediate form of the code? what are the advantages of it? What are generally
used intermediate forms? Write N- Tuple notation for (a+b) * (c+d) - (a+b+c). (8)

5.. Translate the expression - (a+b) * (c+d) + (a+b+c) into 1) Quadruples 2) Triples 3) indirect
triples. (7)

6. Write three address code for a := a+a*b+a*b*c-a/b+a*b (4)

7... Translate the arithmetic expression a*-(b + c) into (7)

1. syntax tree

2. Postfix notation

3 Three address code

8. Convert the following statement into triple, indirect triple and quadruple forms. (7) A

= (B+C) $ E + (B+C) * F

Topic 6 : Run Time Memory Management


1. Explain activation tree. (2)

2. Explain control stack. (2)

3.... What is an activation record? Explain how they are used to access various local and global
variables. (7)

4.. write a note on static memory allocation. (2)

5. Explain stack allocation in brief. (3)

6... What do you mean by dangling reference? (3)

7... What is the use of a symbol table? How the identifiers are stored in the symbol table? (7)

8... Write a note on dynamic memory allocation. (2)

9... Differentiate : Static v/s dynamic memory allocations. (3)


GMIT | KJS
Question Bank J

Topic 7 : Code Optimization


1... Discuss various code optimization techniques. (7)

2... Write an algorithm for global common sub expression elimination. (7)

Topic 8 : Code Generation


1... Discuss generic issues in the design of code generation. (7)

2... Write down the algorithm for partitioning of basic blocks. (7)

3... Write a note on peephole optimization. (8)

GMIT | KJS
Question Bank J

IMP
Question Bank

GMIT | KJS
Question Bank J

Topic 1: Introduction to Compiler


1 Draw structure of Compiler. 3
3
Explain the roles of Linker and Loader. -
2 Write a short note on input buffering method. 5
3 Explain the phases of compiler with an example. 7
4 Explain lexical analysis phase of a compiler and for a statement, write output 7
of all phases (except of an optimization phase) of a compiler. Assume a ,b and
c are of float type
float a = a + b * c * 2
5 List and Explain the types of compilers in detail. 7
6 What is pass of a compiler? Explain how the single and multi pass compilers 7
work.
Topic 2: Lexical Analyzer
1 Convert the NFA-€ into NFA without € for following NFA. 7
q1
€ €

q0 € a q3


A

q2

2 Construct a DFA for a given regular expression (010+00)*(10)*. 7


3 Find the regular expression corresponding to given statement, subset of {0,1}* 4
1. The language of all strings containing at least one 0 and at least one 1.
2. The language of all strings containing 0's and 1's both are even.
3. The language of all strings containing at most one pair of consecutive 1's.
4. The language of all strings that do not end with 01.

4 What are regular expressions? Find the regular expression described by DFA 7
{{A,B},{0,1}, δ ,A, {B}}, where δ is detailed in following table.

0 1
A A B
B Φ A

please note B is accepting state.


Describe the language defined by the regular expression.
5 Construct the NFA using thompson's notation for following regular expression 7
and then convert it to DFA.
6 Convert the (a|b|c)*d*(a*|b)ac*# Regex to DFA directly and draw its DFA. 7

GMIT | KJS
Question Bank J
Topic 3 : Parsing
1 Consider following grammar for arithmetic expressions 5
E -> E+T | T
T -> T*F | F
F -> (E) | id
Eliminate left recursion from this grammar.
2 Explain the left factoring and perform the left factoring of following grammar. 5
A -> ad | a | ab | abc | b
3 How top down and bottom up parser will parse the string 'bbd' using grammar 7
A -> bA|d. Show all steps clearly.
4 Write down C program for recursive descend parser for: 7
S -> ABC
B-> 1B | ^
A -> 0A1 | ^
C -> 1C0 | ^
5 Draw the transition diagram for the predictive parser for the following 7
grammar. (7)
E -> TE'
E' -> +TE' | €
T -> FT'
T -> *FT' | €
F -> (E) | id
6 Is the following grammar suitable for LL(1) parsing? If not make it suitable 7
for LL(1) parsing compute FIRST and FOLLOW sets. Generate the parsing
table.
S -> AB
A -> Ca | €
B -> BaAc |c
C -> b | €
7 Implement the following grammar using Table Driven parser and check 8
whether it is LL(1) or not?
S -> aBDh
B -> cC
C -> bC | €
D -> EF
E -> g | €
F -> f | €
8 What is bottom - up parsing? What is handle? And also differentiate top down 7
and bottom up parsing.
9 Explain shift reduce parser with suitable example. 7
10 E -> E + T | T 7
T -> T * F | F
F -> (E)
F -> id

GMIT | KJS
Question Bank J
Construct SLR parsing table.
11 Differentiate SLR, CLR, and LALR . Also justify the statement "A class of 7
grammar that can be parsed using LR methods is a proper subset of the class
of grammar that can be parsed with predictive parser"
12 Construct an LALR (1) parsing table for the following grammar: 7+7
(1) S -> Aa | bAc | dc | bda
A -> d
(2) S -> Aa | aAc | Bc | bBa
A -> d
B -> d
13 Consider the following grammar 7
E -> E + T | T
T -> TF | F
F -> F* | a | b
(1) Construct the SLR parsing table.
(2) Construct LALR parsing table.
14 Define an operator precedence grammar. also write down the rules to find 8
relations between each pair of terminal symbols.
15 Compute the operator precedence matrix and precedence function for the 7
following grammar if it exits. + ,* ,- , / , id , num , (and) are terminal
symbols.
G -> E
E -> E + T | E - T | T
T -> T * F | T/F/F
F -> num | id | (E)
16 List the error generated by the syntax analysis phase. 3
17 Explain how panic mode recovery can be implemented. 7
18 How can phrase level recovery be implemented in LR parsers? 2-3

What is operator grammar? Check the following grammar is operator or not.


Justify your answer.
E ->EOE
E -> id
O -> * | + | -
19 Show syntax directed definition for simple desk calculator. Also show 7
annotated parse tree for 3*5+4n, where n indicates newline.
20 Give the translation scheme that converts infix to prefix expression for the 7
following grammar and also generate the annotated parse tree for input string
7+3+2 ;
E -> E + T;
E -> T;
T -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Topic 4 : Error Recovery
1 Explain all error recovery strategies using suitable examples. 7
Topic 5 : Intermediate Code Generation
1 What is intermediate form of the code? what are the advantages of it? What 8
are generally used intermediate forms? Write N- Tuple notation for (a+b) *
(c+d) - (a+b+c)
2 Translate the arithmetic expression a*-(b + c) into 7
1. syntax tree

GMIT | KJS
Question Bank J
2. Postfix notation

3 Three address code


Topic 6 : Run Time Memory Management
1 What is an activation record? Explain how they are used to access various 7
local and global variables.
2 What do you mean by dangling reference? 3
3 What is the use of a symbol table? How the identifiers are stored in the symbol 7
table?
4 Write a note on dynamic memory allocation. 2
5 Differentiate : Static v/s dynamic memory allocations. 3
Topic 7 : Code Optimization
1 Discuss various code optimization techniques. 7
2 Write an algorithm for global common sub expression elimination. 7
Topic 8 : Code Generation
1 Discuss generic issues in the design of code generation. 7
2 Write down the algorithm for partitioning of basic blocks. 7
3 Write a note on peephole optimization. 7

GMIT | KJS
Question Bank J

Twisted
Question Bank

GMIT | KJS
Question Bank J

1. What is regular expression, give all the algebraic properties of


regular expression. (Topic - 2)
2. Explain Buffer pairs and Sentinels. (Topic -2)
3. Unsigned numbers are strings such as 5280, 39.37, 6.336E4 or
1.894E-4, give the regular definitions for the above mentioned
strings. (Topic - 2)
4. Differentiate SLR, CLR, and LALR. Also justify the statement "A class
of grammar that can be parsed using LR methods is a proper subset
of the class of grammar that can be parsed with predictive parser”.
(Topic 3)
5. Write unambiguous grammar production rules for producing
arithmetic expression consisting of symbols id, * , - , (,) and ^ ,
Where ^ represents exponent. Parse following string using shift –
reduce parser:
Id – id * id ^ id * (id ^ id) ^ id (Topic 3)
6. A robot is to be moved to a unit step in a direction specified as a
command given to it. The robot moves in the direction North, South,
East, West on receiving N, S, E, W command respectively & in the
direction North-East , North-West, South East, South-West on
receiving A, B, C, D commands respectively. The current position of
the robot is initialized to (0,0) Cartesian coordinates on receiving
command Start. Write production rules for producing sequence of
commands and semantic rules for knowing position of a robot after
receiving a sequence of commands. Draw annotated parse tree for
following sequence: Start N N A A C C N (Topic - 4)
7. Explain activation record. How is task divided between calling &
called program for stack updating? (Topic - 7)
8. Write a short note on Symbol Table Management. (Topic - 7)
9. What is a symbol table? Discuss the most suitable data structure for
it by stating merits / demerits. (Topic - 7)

GMIT | KJS

You might also like