1
Chapter Ten: Grammars
Formal Language, chapter 10, slide 1
Chapter Ten: Grammars Formal Language, chapter 10, slide 1 1 - - PowerPoint PPT Presentation
Chapter Ten: Grammars Formal Language, chapter 10, slide 1 1 Grammar is another of those common words for which the study of formal language introduces a precise technical definition. For us, a grammar is a certain kind of collection of
1
Formal Language, chapter 10, slide 1
2
Formal Language, chapter 10, slide 2
3
Formal Language, chapter 10, slide 3
4
A → a A → the
N → dog N → cat N → rat A noun phrase is an article followed by a noun: P → AN
Formal Language, chapter 10, slide 4
5
Formal Language, chapter 10, slide 5
6
Formal Language, chapter 10, slide 6
7
S ⇒ PVP ⇒ ANVP ⇒ theNVP ⇒ thecatVP ⇒ thecateatsP ⇒ thecateatsAN ⇒ thecateatsaN ⇒ thecateatsarat S ⇒ PVP ⇒ ANVP ⇒ aNVP ⇒ adogVP ⇒ adoglovesP ⇒ adoglovesAN ⇒ adoglovestheN ⇒ adoglovesthecat S ⇒ PVP ⇒ ANVP ⇒ theNVP ⇒ thecatVP ⇒ thecathatesP ⇒ thecathatesAN ⇒ thecathatestheN ⇒ thecathatesthedog
Formal Language, chapter 10, slide 7
8
be applied
– PlovesP ⇒ ANlovesP – PlovesP ⇒ PlovesAN
every step, but that is not a requirement
have at least one derivation from the start symbol S
Formal Language, chapter 10, slide 8
9
Formal Language, chapter 10, slide 9
10
Formal Language, chapter 10, slide 10
11
Formal Language, chapter 10, slide 11
12
Formal Language, chapter 10, slide 12
13
Formal Language, chapter 10, slide 13
14
– Sb → bS says that bS can be substituted for Sb
Formal Language, chapter 10, slide 14
15
Formal Language, chapter 10, slide 15
16
Formal Language, chapter 10, slide 16
17
Formal Language, chapter 10, slide 17
18
– G = ({S, X}, {a, b}, S, {S → aS, S → X, X → bX, X → ε})
Formal Language, chapter 10, slide 18
19
Formal Language, chapter 10, slide 19
20
Formal Language, chapter 10, slide 20
21
Formal Language, chapter 10, slide 21
22
Formal Language, chapter 10, slide 22
23
Formal Language, chapter 10, slide 23
24
Formal Language, chapter 10, slide 24
25
Formal Language, chapter 10, slide 25
26
Formal Language, chapter 10, slide 26
27
Transition of M Production in G (S,a) = {S } S → aS (S,b) = {R } S → bR (R,c) = {R} R → cR (R, ) = {T } R → T
Formal Language, chapter 10, slide 27
28
Accepting state of M Production in G T T →
Formal Language, chapter 10, slide 28
29
Formal Language, chapter 10, slide 29
30
! (S,bc ) ! (R ,c) !
! (T, )
Formal Language, chapter 10, slide 30
31
– Q, Σ, and S are the same as for M – P is constructed from δ and F:
G has X →* zY whenever
(X,z) ! (Y,ε) (X,z) !* (Y,ε)
Formal Language, chapter 10, slide 31
32
Formal Language, chapter 10, slide 32
33
– X → zY – X → z – X → ε
Formal Language, chapter 10, slide 33
34
Formal Language, chapter 10, slide 34
35
Formal Language, chapter 10, slide 35
36
Formal Language, chapter 10, slide 36
37
– X → zY, or – X → z
– A single nonterminal on the left – At most one nonterminal on the right, and only as the rightmost symbol
Formal Language, chapter 10, slide 37
38
these n+1 productions, where each Ki is a new nonterminal symbol:
the set of nonterminals used in P'
to the corresponding n+1 steps in G'
X → z1K1 K1 → z2K2 … Kn-1 → znKn Kn → ω
Formal Language, chapter 10, slide 38
39
Formal Language, chapter 10, slide 39
40
Formal Language, chapter 10, slide 40
41
Formal Language, chapter 10, slide 41
42
Formal Language, chapter 10, slide 42
43
Formal Language, chapter 10, slide 43