linear grammars s ab o s asba aab o · fall 2019 1 linear grammars grammars with at most one...
TRANSCRIPT
![Page 1: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/1.jpg)
Fall 2019 1
Linear Grammars
Grammars with
at most one variable at the right side
of a production
Examples:
A
aAbA
AbS
S
aSbS
![Page 2: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/2.jpg)
Fall 2019 2
A Non-Linear Grammar
bSaS
aSbS
S
SSS
Grammar : G
)}()(:{)( wnwnwGL ba
Number of in string a w
![Page 3: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/3.jpg)
Fall 2019 3
Another Linear Grammar
Grammar :
AbB
aBA
AS
|
}0:{)( nbaGL nn
G
![Page 4: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/4.jpg)
Fall 2019 4
Right-Linear Grammars
All productions have form:
Example:
xBA
xA
or
aS
abSS
string of
terminals
![Page 5: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/5.jpg)
Fall 2019 5
Left-Linear Grammars
All productions have form:
Example:
BxA
aB
BAabA
AabS
|
xA
or
string of
terminals
![Page 6: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/6.jpg)
Fall 2019 6
Regular Grammars
![Page 7: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/7.jpg)
Fall 2019 7
Regular Grammars
A regular grammar is any
right-linear or left-linear grammar
Examples:
aS
abSS
aB
BAabA
AabS
|
1G 2G
![Page 8: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/8.jpg)
Fall 2019 8
Observation
Regular grammars generate regular languages
Examples:
aS
abSS
aabGL *)()( 1
aB
BAabA
AabS
|
*)()( 2 abaabGL
1G
2G
![Page 9: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/9.jpg)
Fall 2019 9
Regular Grammars Generate
Regular Languages
![Page 10: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/10.jpg)
Fall 2019 10
Theorem
Languages
Generated by
Regular Grammars
Regular
Languages
![Page 11: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/11.jpg)
Fall 2019 11
Theorem - Part 1
Languages
Generated by
Regular Grammars
Regular
Languages
Any regular grammar generates
a regular language
![Page 12: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/12.jpg)
Fall 2019 12
Theorem - Part 2
Languages
Generated by
Regular Grammars
Regular
Languages
Any regular language is generated
by a regular grammar
![Page 13: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/13.jpg)
Fall 2019 13
Proof – Part 1
Languages
Generated by
Regular Grammars
Regular
Languages
The language generated by
any regular grammar is regular )(GL
G
![Page 14: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/14.jpg)
Fall 2019 14
The case of Right-Linear Grammars
Let be a right-linear grammar
We will prove: is regular
Proof idea: We will construct NFA
with
G
)(GL
M)()( GLML
![Page 15: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/15.jpg)
Fall 2019 15
Grammar is right-linear
G
Example:
aBbB
BaaA
BaAS
|
|
![Page 16: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/16.jpg)
Fall 2019 16
Construct NFA such that
every state is a grammar variable:
M
aBbB
BaaA
BaAS
|
|
SFV
A
B
special
final state
![Page 17: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/17.jpg)
Fall 2019 17
Add edges for each production:
SFV
A
B
a
aAS
![Page 18: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/18.jpg)
Fall 2019 18
SFV
A
B
a
BaAS |
![Page 19: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/19.jpg)
Fall 2019 19
SFV
A
B
a
BaaA
BaAS
|
a
a
![Page 20: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/20.jpg)
Fall 2019 20
SFV
A
B
a
bBB
BaaA
BaAS
|
a
a
b
![Page 21: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/21.jpg)
Fall 2019 21
SFV
A
B
a
abBB
BaaA
BaAS
|
|
a
a
b
a
![Page 22: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/22.jpg)
Fall 2019 22
aaabaaaabBaaaBaAS
SFV
A
B
a
a
a
b
a
![Page 23: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/23.jpg)
Fall 2019 23
SFV
A
B
a
a
a
b
aabBB
BaaA
BaAS
|
|
G
M Grammar NFA
abaaaab
GLML
**
)()(
![Page 24: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/24.jpg)
Fall 2019 24
In General
A right-linear grammar
has variables:
and productions:
G
,,, 210 VVV
jmi VaaaV 21
mi aaaV 21
or
![Page 25: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/25.jpg)
Fall 2019 25
We construct the NFA such that:
each variable corresponds to a node:
M
iV
0V
FV
1V
2V
3V
4V special
final state
![Page 26: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/26.jpg)
Fall 2019 26
For each production:
we add transitions and intermediate nodes
jmi VaaaV 21
iV jV……… 1a 2a ma
![Page 27: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/27.jpg)
Fall 2019 27
For each production:
we add transitions and intermediate nodes
mi aaaV 21
iV FV……… 1a 2a ma
![Page 28: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/28.jpg)
Fall 2019 28
Resulting NFA looks like this: M
0V
FV
1V
2V
3V
4V
1a
3a
3a
4a
8a
2a 4a
5a
9a5a
9a
)()( MLGL It holds that:
![Page 29: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/29.jpg)
Fall 2019 29
Proof - Part 2
Languages
Generated by
Regular Grammars
Regular
Languages
Any regular language is generated
by some regular grammar
L
G
![Page 30: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/30.jpg)
Fall 2019 30
Proof idea:
Let be the NFA with .
Construct from a regular grammar
such that
Any regular language is generated
by some regular grammar
L
G
M )(MLL
M G)()( GLML
![Page 31: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/31.jpg)
Fall 2019 31
Since is regular
there is an NFA such that
L
M )(MLL
Example: a
b
a
b
*)*(* abbababL
)(MLL
M
1q 2q
3q
0q
![Page 32: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/32.jpg)
Fall 2019 32
Convert to a right-linear grammar M
a
b
a
b
M
0q 1q 2q
3q10 aqq
![Page 33: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/33.jpg)
Fall 2019 33
a
b
a
b
M
0q 1q 2q
3q
21
11
10
aqq
bqq
aqq
![Page 34: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/34.jpg)
Fall 2019 34
a
b
a
b
M
0q 1q 2q
3q
32
21
11
10
bqq
aqq
bqq
aqq
![Page 35: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/35.jpg)
Fall 2019 35
a
b
a
b
M
0q 1q 2q
3q
3
13
32
21
11
10
q
bqq
aqq
bqq
aqq
G
LMLGL )()(
![Page 36: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/36.jpg)
Fall 2019 36
In General
For any transition: a
q p
Add production: apq
variable terminal variable
![Page 37: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/37.jpg)
Fall 2019 37
For any final state: fq
Add production: fq
![Page 38: Linear Grammars S Ab o S aSbA aAb o · Fall 2019 1 Linear Grammars Grammars with at most one variable at the right side of a production Examples: o O o o A A aAb S Ab o O o S S aSb](https://reader033.vdocuments.us/reader033/viewer/2022041919/5e6b40410499db02994bf6ce/html5/thumbnails/38.jpg)
Fall 2019 38
Since is right-linear grammar
is also a regular grammar
with
G
G
LMLGL )()(