Professional Documents
Culture Documents
Assignment
(Solved for practicing)
Grade: Points: /100
Theory: 50 Points
Definitions (Give every definition formally!):
1. Define ~M! 3 Points
a
– this is the parse tree for each a Σ
• its root: 'a'
• its leaf: 'a'
• its yield: 'a'
A
y1 yn
A
A1 A2 ... An
T1 T2 Tn
y1 y2 yn
– if the above graphs are parse trees, where n ≥ 1, with roots labeled A1,
A2, … An respectively, and with yields y1…yn, and A → A1 A2 …An is a
rule in R then
compatible transitions ((p, a, ), (q, )) and ((p, a', '), (q', ')):
'a' is consistent with a' and is consistent with '
c b
c
b c
a a a a a
c
b c
b
b c
b a a a c
c b
a,b,c
E => E+T => E+F => E+(E) => E+(E+T) => E+(T+T) => E+(F+T) =>
=> E+(F+T*F) => E+(F+F*F) => E+(F+(E)*F) => E+(F+(T)*F) =>
=> E+(F+(F)*F) => E+(F+(id)*F)
o (id*(id))
E => T => F => (E) => (T) => (T*F) => (F*F) => (id*F) => (id*(E)) =>
=> (id*(T)) => (id*(F)) => (id*(id))
( E )
T * F
F ( E )
id T
id
Give the leftmost derivation of the first, and the rightmost derivation of the
second parse tree!
o The first one doesn’t have a parse tree, hence it also does not
have a leftmost derivation by definition.
o The leftmost derivation is already constructed in the first task.
12. Let grammar G = (V, Σ, R, S), where 8 Points
V = {a, b, c, d, A, B, C, D, S}
Σ = {a, b, c, d}
R = {S → ABCD, A → ab, B → e, C → e, D → cd}
Give the Chomsky normal form of grammar G!
• V = {a, b, c, d, A, D, S}
• Σ = {a, b, c, d}
• R = {S → AD, A → ab, D → cd}
5 {)} {}
4 {)} {} {}
3 {)} {} {} {}
x1 ≠ x2 ≠
Π Π
1,2 2 2 1,2
>R x L →R
Π x1
1
Π
15. Write a program for a random access TM to perform the following computation
while x>5 do 10 Points
x = x-2y+1
R1:=x, R2:=y
1. load 1
2. sub =5
3. jzero 10
4. load 1
5. sub 2
6. sub 2
7. add =1
8. store 1
9. jump 1
10. halt