Muhamedsultan Awol Compiler
Muhamedsultan Awol Compiler
By Muhamedsultan Awol
ID RNS -4803/19
a b
This strings is derivable from the grammar.
II. aabbb S→ TF
S→ aF (T applied by a)
S→ aaFb (F applied by aFb)
S→ aabb (F applied by b)
This string is not derivable from the grammar.
III. aba S→ TF
S→ aF (T applied by a)
S→ ab (F applied by b) OR
S→ aabb
This string is not derivable from the grammar.
IV. aaabb S→ TF S→ TF
S→ aF (T applied by a) S→ TTTF
S→ aaFb (F applied by aFb) S→ aaaF
S→ aaaFbb (F applied by aFb) S→ aaaaFb
S→ aaaabb S→ aaaabb
This string is not derivable from the grammar.
V. aaaabb S→ TF S
S→ TTTF (T applied by TTT)
S→ aaaF (T applied by a) F T
T T T a F b
S→ aaaaFb (F applied by aFb)
S→ aaaabb (F applied by b)
This strings is derivable from the grammar.
3. Show that the following CFGs are ambiguous by giving two parse trees for the same string?
3.1) Terminals = { a, b }
Non-Terminals = {S, T}
Start Symbol = S
Rules = S→ STS
S→ b
T→ aT
T→ ε
Based on this string ‘bbb’.
1st parse tree: S
S T S
b ε S T S
b ε b
2nd parse tree:
s
S T S
S T S ε b
b ε b
3.2) Terminals = { if, then, else, print, id }
Non-Terminals = {S, T}
Start Symbol = S
Rules = S→ if id then S T
S→ print id
T→ else S
T→ ε
1st parse tree: S
If id then S T
print id ε
If id then S T
print id else s
print id