0% found this document useful (0 votes)
104 views

Compiler_Design_Worksheet

The document outlines various tasks related to context-free grammars, syntax-directed translation schemes, and parsing techniques. It includes generating strings, constructing parse trees, and translating between different notations, such as infix and postfix. Additionally, it addresses the construction of DFAs, NFA, and predictive parsing tables for given grammars.

Uploaded by

Fekadu Tigu
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)
104 views

Compiler_Design_Worksheet

The document outlines various tasks related to context-free grammars, syntax-directed translation schemes, and parsing techniques. It includes generating strings, constructing parse trees, and translating between different notations, such as infix and postfix. Additionally, it addresses the construction of DFAs, NFA, and predictive parsing tables for given grammars.

Uploaded by

Fekadu Tigu
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/ 2

1) Consider the context-free grammar S -> 55 + | 55 * | a

a) Show how the string aa+a* can be generated by this grammar.


b) Construct a parse tree for this string.
c) What language does this grammar generate? Justify your answer.
2) Construct a syntax-directed translation scheme that translates arithmetic expressions from
infix notation into prefix notation in which an operator appears before its operands; e.g., -xy
is the prefix notation for x-y. Give annotated parse trees for the inputs 9-5+2 and 9-5*2.
3) Construct a syntax-directed translation scheme that t translates roman numerals into integers.
4) Construct a syntax-directed translation scheme that t translates postfix arithmetic expressions
into equivalent infix arithmetic expressions.
5) Construct a syntax-directed translation scheme that translates arithmetic expressions from
postfix notation into infix notation. Give annotated parse trees for the inputs 95-2* and 952*-
6) Construct a syntax-directed translation scheme that translates integers into roman numerals.
7) Construct recursive-descent parsers, starting with the following grammars:
a) S -> + SS | -SS | a
b) S -> 5(5) 5 | e
c) S 0 5 1 | 0 1
8) Construct DFAs for the string matched by the following definition:
a) digit =[0-9]
b) nat=digit+
c) signednat=(+|-)?nat
d) number=signednat(“.”nat)?(E signedNat)?
9) Regular expression Consider the regular expression r = (a|b)*abb, that matches {abb, aabb,
babb, aaabb, bbabb, ababb, aababb, ……}
a) Construct a NFA from this, use Thompson’s construction.
b) Construct a DFA from this NFA.
c) Built a Transition Table.
10) Using the grammar below, construct a parse tree for the following string using RDP
algorithm: ( ( id . id ) id ( id ) ( ( ) ) )
S→E
E → id
|(E.E)
|(L)
|()
L→LE
|E
11) Consider the following grammar over the alphabet { g,h,i,b}
A → BCD
B → bB | ε
C → Cg | g | Ch | i

Page 1 of 2
D → AB | ε
a) Fill in the table below with the FIRST and FOLLOW sets for the non-terminals in
this grammar:
12) Consider the following grammar:
S → ScB | B
B → e | efg | efCg
C → SdC | S
a) Justify whether the grammar is LL(1) or not?
b) If not, translate the grammar into LL(1).
c) Construct predictive parsing table for the above grammar.
13) Given the following Grammar:
S→A
S→B
A→aAb
A→0
B→aBbb
B→1
a) Construct the SLR parsing table.
b) Write the action of an LR parse for the following string aa1bbbb

Page 2 of 2

You might also like