0% found this document useful (0 votes)
45 views8 pages

Questions Set Compiler

Uploaded by

Lucky Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views8 pages

Questions Set Compiler

Uploaded by

Lucky Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

5 MARKS QUESTIONS

1) Consider the grammar

S->( L )|a

L->L ,S|S

a. List the terminals, variables and start symbol[1 mark]


b. Find the parse tree for the following sentences [2 marks]
i. (a, (a,a))
c. Construct a rightmost derivation for each of the sentences obtained in (b) [1 mark]
d. Construct a leftmost derivation for each of the sentences obtained in (b)[1 mark]
2) Construct Finite automaton for the following : [2+3]marks
a. identifiers
b. numbers
3) Find the output, given grammar G1 and associated semantic rules and input: aadbd [5 marks]
• S->AS {print(1)}
• S->AB {print(2)}
• A->a {print(3)}
• B->b C {print(4)}
• B->d B {print(5)}
• C->c {print(6)}
4) Explain the model of a non recursive predictive parser with a diagram[5 marks]
5) Explain the model of a LR parser with a diagram [5 marks]
6) What do you mean by Syntax directed translation? Compare and contrast between S-Attributed
SDT and L-attributed SDT. [1+4]marks
7) Why left recursive grammar is not suitable for predictive parsers? Remove left recursion from
the grammar G:{E->E+T|T, T->TF|F, F->F* |a | b} [2+3]marks
8) What is lexical analysis? Identify the lexemes and tokens in the following code
printf(“total=%d”, sum); [2+3]marks
9) What is a left recursive grammar? Remove left recursion from the grammar G:{S->Aa|b, A->
Ac|Sd|𝞊 } [1+4]marks
10) What is ambiguity? Show that G2:{S->aS|Sa|a} is ambiguous [1+4]marks
11) Write the CFG’s for the following languages:[2+3]marks
a. {ambn:m≥n}
b. {ambncpdq : m+n =p+q}
12) Represent the following sets by regular expression[1+2+2] marks
a. {0,1,2}
b. The set of all strings over {a,b} which consists of all words with exactly two a’s
c. The set of all strings over {a,b} which consists of all words that contain aaa or bbb as
substring
13) Translate the following C program into three address code

14) For the following grammars find FIRST(X),Follow(X) for each variable in the grammar
G:{ E->E+T|T, T->TF|F, F->F* |a | b}
15) What do you understand by left factoring? Perform left factoring to dangling-else grammar S-
>iCtS | iCtSe|a , C->b
16) Describe input buffering in lexical analyser
17) Describe the language processing system with a diagram
18) what is DAG? Construct a DAG for the following code:
a=a+b,
e= a+d + e
19) What is code optimization? Optimize the following C-code:

count=0;
result= 0;
while(count++ < 20)
{
increment= 2*count;
result +=increment;
}
20) Construct the transition system equivalent to the given regular expression: a* +(ab + a)* using
Thompsons construction
15 MARKS QUESTIONS

1) For the following grammar

E-> E or T|T
T->T and F|F
F-> not F|(E)| 0|1
a) Eliminate left recursion from the above grammar [3 marks]
b) Find FIRST(X),Follow(X) for each variable in the grammar [5 marks]
c) Construct a predictive parser table for the grammar[5 marks]
d) Is the above grammar LL(1). Justify your answer[2 marks]
2) Consider the regular expression (a+b)*a(a+b)(a+b)
I. Augment the expression and construct the syntax tree for the above regular expression
[3 marks]
II. Find Firstpos() and Lastpos() for every internal node in the syntax tree[6 marks]
III. Find Followpos() for every position in the syntax tree [3 marks]
IV. Construct the corresponding DFA for the given RE using Followpos()[3 marks]

3) For the following grammar

S->L=R | R
L->*R |id
R-> L
a) Augment the grammar[1 mark]
b) What is the initial item? [1 mark]
c) Find FIRST(X),Follow(X) for each variable in the grammar [3 marks]
d) Construct the Set of SLR Items for the above grammar [5 marks ]
e) Construct a SLR parser table for the grammar[3 marks]
f) Can an SLR parser be generated for the grammar? Justify your answer[2 marks]
4) Consider the following augmented grammar

S’->S
S->CC
C->c C
C->d
a) Construct the Set of LR(1) Items for the above grammar [5 mark]
b) Construct an LALR parsing table for the same [3 marks]
c) Show which states LA LR parser could be combined and why [4 marks ]
d) Construct the corresponding CLR parsing table [3 marks]
5) Consider the following augmented grammar

E’->E
E->E+T|T
T->T*F|F
F->id
a) Construct the Set of SLR Items for the above grammar [6 mark]
b) Construct the goto graph [2 marks]
c) Construct an SLR parsing table for the same [3 marks]
d) Use the above table to demonstrate the parsing of the string id * id + id [4 marks ]
6) i) Express the expression y=(a+b)*c in [9+6]marks
I. postfix notation
II. Abstract syntax tree
III. Three address code
ii) Implement the TAC using
a. quadruples
b. triples
c. indirect triples

7) a) What is LEX?
b) Explain the working of LEX
c) Show the step by step construction of a lexical analyzer with the following three tokens
• a {}
• abb{}
• a*b+
8) a) What is a compiler?
b) Explain the different phases of compiler with an example
c) Compare and contrast between a compiler and an interpreter

9) What are basic blocks? How are leaders in basic blocks determined? What are equivalent basic
blocks? Explain the different kinds of local transformations that can be applied to a basic block
for optimization. What is a flow graph? How a flow graph is constructed? [2+3+1+4+1+4]marks
10) Define syntax directed translation. Construct an annoted parse tree for the expression
(4*7+1)*2. Define back patching and semantic rule for Boolean expression (2+8+5)
11) Write short notes on (3 × 5=15)
I. Lexical Error And Syntax Error
II. Activation Record
III. yacc parser generator
12) Consider the following three address code segment: (6+9)marks
I. prod:=0
II. i=1
III. t1=4*i
IV. t2=addr(A)-4
V. t3=t2[t1]
VI. t4= addr(B)-4
VII. t5:=t4[t1]
VIII. t6:=t3*t5
IX. prod:=prod + t6
X. i=i+1
XI. if i<=20 goto(3)
i. Find the basic blocks and flow graph of the above sequence
ii. Optimize the code sequence by applying function preserving transformation and
loop optimization techniques

13) Show that the following grammar(12+3)marks


S->AaAb |BbBa
A->𝞊
B->𝞊
is LL(1) but not SLR(1)
What is the difference between LL(k) and LK(k) grammar?
14) Explain how stack implementation of shift reduce parsing is done considering the following
grammar: E->E+E|E*E|(E)|id and the input string id + id * id. Explain shift-reduce and reduce-
reduce problem with example [9+6]marks
15) a) Show that the following grammar(10+5)marks
S->Aa |bAc|Bc|bBa
A->d
B->d

is LR(1) but not LALR(1)

b) Find the output, given grammar G1 and associated semantic rules and input: 00011 [5 marks]

• S->0X {print(1)}
• S->00Y{print(2)}
• A->1Y|1 {print(3)}

16) a) What is the role of symbol table? [3 marks]


b) Discuss various data structures used for symbol table. [6 marks]
c) What is an activation record? [2 marks]
d) Explain the organization of activation record[4 marks]
17) Consider the following augmented grammar

S’->S
S->c A|cc B
A->cA|a
B->ccB|b
a) Construct the Set of SLR Items for the above grammar [6 mark]
b) Construct the goto graph [3 marks]
c) Construct an SLR parsing table for the same [3 marks]
d) Is the above grammar SLR(0). Justify your answer [3 marks ]
18) a) What do you mean by peephole optimization?[2 marks]
b) Explain with example (i)constant folding (ii) common sub-expression elimination (iii)loop
unrolling (iv)loop jamming [3×4=12]
c) What do you mean by redundant load store statement? [1 mark]

19) a) What is code optimization? [2 marks]


b) Why is code optimization needed?[5 marks]
b) Study the program flow graph given below and indicate whether any of the following optimizing
transformation can be applied to it
[8 marks]
i) Common Sub-Expression Elimination
Ii) Elimination of Dead Code
Iii) Constant Propagation
Iv) Frequency reduction
20) Construct the operator precedence parse table for the following grammar and show its shift
reduce actions for the input strings given below (5+5+5)marks
S->a|^|(R)
T->S,T | S
R->T
i) (a,(a,a))
ii) (((a,a), ^, (a)),a)

1. A. Discuss the following parameter passing techniques with suitable example:


i. Call by value
ii. Call by reference
iii. Call by name 5
B. Discuss the following storage allocation strategies:
i. Stack allocation
ii. Heap allocation 5
C. Explain activation record and display structure. Show the activation records and
display just after the procedure call.
program main();
procedure p;
function q(a: integer) : integer;
begin
if (a=) then q:=1;
else q:= a+q(a-1);
end
begin q(3); end;
begin p; end; 5
2. A. Consider the following program:
void term()
{
int x, y, z; /* level ‘0’ declaration*/
……………..
……………..
{
int x, y: /* level ‘1x’ declaration*/
……………….
……………….
}.
{
float z, p; /* level ‘1y’ declaration*/
{
int q; /* level ‘2’ declaration*/
……………………….
……………………….
}
}
} 7
B. What do you understand by scoping in the symbol table. Explain with example. 5

C. Give the difference between scope by numbering and scope by location. 3

3. A. Write down the process to design a type checker. 5

B. What is type equivalence? Explain with example. 5

C. Explain the type conversion with suitable example. 5

You might also like