Work Out Problems

You might also like

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

UNIT - 1 INTRODUCTION TO COMPILERS AND LEXICAL ANALYSIS

1. What are the phases of the compiler? Explain the phases in detail. Write down the output of each phase
for the expression:

i) a := b + c * 60
ii) a = (b+c) * (b+c) *2
iii) position := initial +rate * 60
iv) amount = principle + rate * 36.0
v) a := b + c - 60

2. Convert regular expression to DFA using direct method and minimize it .

i) abb (a|b)*
ii) (a|b)* abb

3. Write notes on regular expression to NFA. Convert regular expression to NFA.

i) abb (a|b)*
ii) (a|b)* abb
iii) ab*| ab
iv) (a|b)* a
v)(a*|b*)*

4. Construct minimized DFA for the regular expression

i) (0+1)*(0+1)01
ii) (a|b|c)* (a|b)*

5. Draw the DFA for the augmented regular expression directly using syntax tree method.

i) (a|b)*#
ii) (a|b)* abb
iii) abb (a|b)*
UNIT - 2 SYNTAX ANALYSIS

1. what is an ambiguous grammar ? is the following grammar ? Prove E--> E+E/E*E/(E)/id for the
sentence id+id*id.

2. Explain the non-recursive implementation of predictive parser with the help of the grammar,
i) E--> E + T
E--> T
T--> T * F
T --> F
F--> (E) / id

ii) S --> (L) / a


L--> L, S / S and parse the input string i) (a,a) ii) (a,(a,(a,a)))

iii) Define an LL(1) grammar. How do you check whether the grammar is LL(1) or not? Generate
LL(1) parsing table for the grammar.
S--> iEtS / iEtS / a
E--> b
Is grammar in LL(1) or not ?

3. Consider the grammar E--> E+E/E*E/id perform shift reduce parsing of the input String id1+id2*id3.

4. Consider the grammar


S --> (L) / a
L--> L, S / S parse the input string (a,(a,a)) using shift reduce parser.

5. Consider the grammar


S --> TL
T --> int / float
L --> L, id / id parse the input string int id, id using shift reduce parser.
6. Implement the SLR parser for the given grammar
i) E--> E+T
E--> T
T--> T * F
T--> F
F--> (E)
F --> id
ii) S--> L = R
S--> R
L-->* R
L-->id
R--> L

You might also like