COMP3630/6360: Theory of Computation Semester 1, 2020 The Australian National University Context Free Languages
1 / 15
COMP3630/6360: Theory of Computation Semester 1, 2020 The - - PowerPoint PPT Presentation
COMP3630/6360: Theory of Computation Semester 1, 2020 The Australian National University Context Free Languages 1 / 15 This lecture covers Chapter 5 of HMU: Context-free Grammars (Context-free) Grammars (Leftmost and Rightmost)
1 / 15
Grammars
3 / 15
Grammars
4 / 15
Derivations
5 / 15
Derivations
G γ2 ⇒ G · · · ⇒ G γk for some k ∈ N where
∗
G β.
G
S→0S0
G
S→1S1
G
S→0S0
G
S→1S1
G
S→1
6 / 15
Derivations
7 / 15
Derivations
∗
LM β (or α
∗
RM β) to denote the
↑ ⇒
G S
↑S ⇒
G (S)S
↑ ⇒
G (S
↑)() ⇒
G (())()
↑ ⇒
G S
↑S ⇒
G (S
↑)S ⇒
G (())S
↑ ⇒
G (())()
↑ ⇒
G SS
↑ ⇒
G S
↑() ⇒
G (S
↑)() ⇒
G (())()
8 / 15
Parse Trees
9 / 15
An Equivalence between Parse Trees and Derivations
∗
G w
∗
LM w
∗
RM w.
∗
LM w
∗
G w
By Definition
10 / 15
An Equivalence between Parse Trees and Derivations
G w ⇒ ∃ Parse Tree
∗
G α ⇒ there exists a parse tree with root A and yield α
G α be a one-step derivation. Since α = A,
11 / 15
An Equivalence between Parse Trees and Derivations
G w ⇒ ∃ Parse Tree
G γ2 ⇒ G γ3 ⇒ G · · · ⇒ G γk−1 ⇒ G γk = α
∗
G
∗
G
12 / 15
An Equivalence between Parse Trees and Derivations
LM w
∗
LM α.
∗
LM wi.
∗
LM wi.
X1 X2 Xk Depth ‘ − 1
A
s1 s2 s‘ · · · Basis: ¸ = s1 · · · s‘ (A; ¸) ≡ (A − ! ¸) 2 P
G X1X2 · · · Xk
∗
LM w1X2 · · · Xk
∗
LM w1w2X3 · · · Xk
∗
LM · · ·
∗
LM w1 · · · wk 13 / 15
Ambiguous Grammars
E + ∗ 9 2 2 E E E E E + ∗ 9 2 2 E E E E
14 / 15
Ambiguous Grammars
LM SS ⇒ LM ()S ⇒ LM ()SS ⇒ LM ()()S ⇒ LM ()()()
LM SS ⇒ LM SSS ⇒ LM ()SS ⇒ LM ()()S
∗
LM ()()()
∗
LM (RB ⇒ LM ()B ⇒ LM ()(RB ⇒ LM ()()B ⇒ LM ()()()B ⇒ LM ()()()ǫ
15 / 15