SlideShare a Scribd company logo
1 of 75
1
Reverse of a Regular Language
2
Theorem:
The reverse of a regular language
is a regular language
R
L L
Proof idea:
Construct NFA that accepts :
R
L
invert the transitions of the NFA
that accepts L
3
Proof
Since is regular,
there is NFA that accepts
L
Example:
baabL += *
a
b
b
a
L
4
Invert Transitions
a
b
b
a
5
Make old initial state a final state
a
b
b
a
6
Add a new initial state
a
b
b
a
λ
λ
7
a
b
b
a
λ
λ
Resulting machine accepts R
L
baabL += *
ababLR
+= *
R
L is regular
8
Grammars
9
Grammars
Grammars express languages
Example: the English language
verbpredicate
nounarticlephrasenoun
predicatephrasenounsentence
→
→
→
_
_
10
walksverb
runsverb
dognoun
boynoun
thearticle
aarticle
→
→
→
→
→
→
11
A derivation of “the boy walks”:
walksboythe
verbboythe
verbnounthe
verbnounarticle
verbphrasenoun
predicatephrasenounsentence
⇒
⇒
⇒
⇒
⇒
⇒
_
_
12
A derivation of “a dog runs”:
runsdoga
verbdoga
verbnouna
verbnounarticle
verbphrasenoun
predicatephrasenounsentence
⇒
⇒
⇒
⇒
⇒
⇒
_
_
13
Language of the grammar:
L = { “a boy runs”,
“a boy walks”,
“the boy runs”,
“the boy walks”,
“a dog runs”,
“a dog walks”,
“the dog runs”,
“the dog walks” }
14
Notation
dognoun
boynoun
→
→
Variable
or
Non-terminal
TerminalProduction
rule
15
Another Example
Grammar:
Derivation of sentence :
λ→
→
S
aSbS
abaSbS ⇒⇒
ab
aSbS → λ→S
16
aabbaaSbbaSbS ⇒⇒⇒
aSbS → λ→S
aabb
λ→
→
S
aSbSGrammar:
Derivation of sentence :
17
Other derivations:
aaabbbaaaSbbbaaSbbaSbS ⇒⇒⇒⇒
aaaabbbbaaaaSbbbb
aaaSbbbaaSbbaSbS
⇒⇒
⇒⇒⇒
18
Language of the grammar
λ→
→
S
aSbS
}0:{ ≥= nbaL nn
19
More Notation
Grammar ( )PSTVG ,,,=
:V
:T
:S
:P
Set of variables
Set of terminal symbols
Start variable
Set of Production rules
20
Example
Grammar :
λ→
→
S
aSbSG
( )PSTVG ,,,=
}{SV = },{ baT =
},{ λ→→= SaSbSP
21
More Notation
Sentential Form:
A sentence that contains
variables and terminals
Example:
aaabbbaaaSbbbaaSbbaSbS ⇒⇒⇒⇒
Sentential Forms sentence
22
We write:
Instead of:
aaabbbS
*
⇒
aaabbbaaaSbbbaaSbbaSbS ⇒⇒⇒⇒
23
In general we write:
If:
nww
*
1 ⇒
nwwww ⇒⇒⇒⇒ 321
24
By default: ww
*
⇒
25
Example
λ→
→
S
aSbS
aaabbbS
aabbS
abS
S
*
*
*
*
⇒
⇒
⇒
⇒λ
Grammar Derivations
26
baaaaaSbbbbaaSbb
aaSbbS
∗
∗
⇒
⇒
λ→
→
S
aSbS
Grammar
Example
Derivations
27
Another Grammar Example
Grammar :
λ→
→
→
A
aAbA
AbS
Derivations:
aabbbaaAbbbaAbbS
abbaAbbAbS
bAbS
⇒⇒⇒
⇒⇒⇒
⇒⇒
G
28
More Derivations
aaaabbbbbaaaaAbbbbb
aaaAbbbbaaAbbbaAbbAbS
⇒⇒
⇒⇒⇒⇒
bbaS
bbbaaaaaabbbbS
aaaabbbbbS
nn
∗
∗
∗
⇒
⇒
⇒
29
Language of a Grammar
For a grammar
with start variable :
G
S
}:{)( wSwGL
∗
⇒=
String of terminals
30
Example
For grammar :
λ→
→
→
A
aAbA
AbS
}0:{)( ≥= nbbaGL nn
Since: bbaS nn
∗
⇒
G
31
A Convenient Notation
λ→
→
A
aAbA
λ|aAbA →
thearticle
aarticle
→
→
theaarticle |→
32
Linear Grammars
33
Linear Grammars
Grammars with
at most one variable at the right side
of a production
Examples:
λ→
→
→
A
aAbA
AbS
λ→
→
S
aSbS
34
A Non-Linear Grammar
bSaS
aSbS
S
SSS
→
→
→
→
λ
Grammar :G
)}()(:{)( wnwnwGL ba ==
35
Another Linear Grammar
Grammar :
AbB
aBA
AS
→
→
→
λ|
}0:{)( ≥= nbaGL nn
G
36
Right-Linear Grammars
All productions have form:
Example:
xBA →
xA →
or
aS
abSS
→
→
37
Left-Linear Grammars
All productions have form:
Example:
BxA →
aB
BAabA
AabS
→
→
→
|
xA →
or
38
Regular Grammars
39
Regular Grammars
A regular grammar is any
right-linear or left-linear grammar
Examples:
aS
abSS
→
→
aB
BAabA
AabS
→
→
→
|
1G 2G
40
Observation
Regular grammars generate regular languages
Examples:
aS
abSS
→
→
aabGL *)()( 1 =
aB
BAabA
AabS
→
→
→
|
*)()( 2 abaabGL =
1G
2G
41
Regular Grammars
Generate
Regular Languages
42
Theorem
Languages
Generated by
Regular Grammars
Regular
Languages=
43
Theorem - Part 1
Languages
Generated by
Regular Grammars
Regular
Languages
⊆
Any regular grammar generates
a regular language
44
Theorem - Part 2
Languages
Generated by
Regular Grammars
Regular
Languages
⊇
Any regular language is generated
by a regular grammar
45
Proof – Part 1
Languages
Generated by
Regular Grammars
Regular
Languages
⊆
The language generated by
any regular grammar is regular
)(GL
G
46
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 =
47
Grammar is right-linearG
Example:
aBbB
BaaA
BaAS
|
|
→
→
→
48
Construct NFA such that
every state is a grammar variable:
M
aBbB
BaaA
BaAS
|
|
→
→
→
S FV
A
B
special
final state
49
Add edges for each production:
S FV
A
B
a
aAS →
50
S FV
A
B
a
BaAS |→
λ
51
S FV
A
B
a
λ
BaaA
BaAS
→
→ |
a
a
52
S FV
A
B
a
λ
bBB
BaaA
BaAS
→
→
→ |
a
a
b
53
S FV
A
B
a
λ
abBB
BaaA
BaAS
|
|
→
→
→
a
a
b
a
54
aaabaaaabBaaaBaAS ⇒⇒⇒⇒
S FV
A
B
a
λ
a
a
b
a
55
S FV
A
B
a
λ
a
a
b
a
abBB
BaaA
BaAS
|
|
→
→
→
G
M GrammarNFA
abaaaab
GLML
**
)()(
+
==
56
In General
A right-linear grammar
has variables:
and productions:
G
,,, 210 VVV
jmi VaaaV 21→
mi aaaV 21→
or
57
We construct the NFA such that:
each variable corresponds to a node:
M
iV
0V
FV
1V
2V
3V
4V special
final state
58
For each production:
we add transitions and intermediate nodes
jmi VaaaV 21→
iV jV………1a 2a ma
59
For each production:
we add transitions and intermediate nodes
mi aaaV 21→
iV FV………1a 2a ma
60
Resulting NFA looks like this:M
0V
FV
1V
2V
3V
4V
1a
3a
3a
4a
8a
2a 4a
5a
9a
5a
9a
)()( MLGL =It holds that:
61
The case of Left-Linear Grammars
Let be a left-linear grammar
We will prove: is regular
Proof idea:
We will construct a right-linear
grammar with
G
)(GL
G′ R
GLGL )()( ′=
62
Since is left-linear grammar
the productions look like:
G
kaaBaA 21→
kaaaA 21→
63
Construct right-linear grammar G′
In :G kaaBaA 21→
In :G′ BaaaA k 12→
vBA →
BvA R
→
64
Construct right-linear grammar G′
In :G kaaaA 21→
In :G′ 12aaaA k →
vA →
R
vA →
65
It is easy to see that:
Since is right-linear, we have:
R
GLGL )()( ′=
)(GL ′ R
GL )( ′
G′
)(GL
Regular
Language
Regular
Language
Regular
Language
66
Proof - Part 2
Languages
Generated by
Regular Grammars
Regular
Languages
⊇
Any regular language is generated
by some regular grammar
L
G
67
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 =
68
Since is regular
there is an NFA such that
L
M )(MLL =
Example:
a
b
a
bλ
*)*(* abbababL =
)(MLL =
M
1q 2q
3q
0q
69
Convert to a right-linear grammarM
a
b
a
bλ
M
0q 1q 2q
3q
10 aqq →
70
a
b
a
bλ
M
0q 1q 2q
3q
21
11
10
aqq
bqq
aqq
→
→
→
71
a
b
a
bλ
M
0q 1q 2q
3q
32
21
11
10
bqq
aqq
bqq
aqq
→
→
→
→
72
a
b
a
bλ
M
0q 1q 2q
3q
λ→
→
→
→
→
→
3
13
32
21
11
10
q
qq
bqq
aqq
bqq
aqq
G
LMLGL == )()(
73
In General
For any transition:
a
q p
Add production: apq →
variable terminal variable
74
For any final state: fq
Add production: λ→fq
75
Since is right-linear grammar
is also a regular grammar
with
G
G
LMLGL == )()(

More Related Content

What's hot (12)

context free language
context free languagecontext free language
context free language
 
PUSH DOWN AUTOMATA VS TURING MACHINE
PUSH DOWN AUTOMATA VS TURING MACHINEPUSH DOWN AUTOMATA VS TURING MACHINE
PUSH DOWN AUTOMATA VS TURING MACHINE
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR
 
Context free langauges
Context free langaugesContext free langauges
Context free langauges
 
Phttp://www.cw360ms.com/pmsurveyresults/index.aspda
Phttp://www.cw360ms.com/pmsurveyresults/index.aspdaPhttp://www.cw360ms.com/pmsurveyresults/index.aspda
Phttp://www.cw360ms.com/pmsurveyresults/index.aspda
 
Gch6 l2
Gch6 l2Gch6 l2
Gch6 l2
 
Simplification of cfg ppt
Simplification of cfg pptSimplification of cfg ppt
Simplification of cfg ppt
 
L3 cfg
L3 cfgL3 cfg
L3 cfg
 
CLaSH HIW 2014
CLaSH HIW 2014CLaSH HIW 2014
CLaSH HIW 2014
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
 
Automata
AutomataAutomata
Automata
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa
 

Similar to Class5

How-to-convert-a-left-linear-grammar-to-a-right-linear-grammar.pptx
How-to-convert-a-left-linear-grammar-to-a-right-linear-grammar.pptxHow-to-convert-a-left-linear-grammar-to-a-right-linear-grammar.pptx
How-to-convert-a-left-linear-grammar-to-a-right-linear-grammar.pptx
ishawrb
 
Theory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptxTheory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptx
Jisock
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
lavishka_anuj
 
context free grammars automata therory and compiler design
context free grammars automata therory and compiler designcontext free grammars automata therory and compiler design
context free grammars automata therory and compiler design
sunitachalageri1
 

Similar to Class5 (20)

Hw2 2017-spring
Hw2 2017-springHw2 2017-spring
Hw2 2017-spring
 
Natural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarNatural Language Processing - Writing Grammar
Natural Language Processing - Writing Grammar
 
How-to-convert-a-left-linear-grammar-to-a-right-linear-grammar.pptx
How-to-convert-a-left-linear-grammar-to-a-right-linear-grammar.pptxHow-to-convert-a-left-linear-grammar-to-a-right-linear-grammar.pptx
How-to-convert-a-left-linear-grammar-to-a-right-linear-grammar.pptx
 
CNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of ComputationCNF & Leftmost Derivation - Theory of Computation
CNF & Leftmost Derivation - Theory of Computation
 
Open course(programming languages) 20150211
Open course(programming languages) 20150211Open course(programming languages) 20150211
Open course(programming languages) 20150211
 
Open course(programming languages) 20150211
Open course(programming languages) 20150211Open course(programming languages) 20150211
Open course(programming languages) 20150211
 
Context Free Languages by S.Mandal-1.ppt
Context Free Languages by S.Mandal-1.pptContext Free Languages by S.Mandal-1.ppt
Context Free Languages by S.Mandal-1.ppt
 
Grammar
GrammarGrammar
Grammar
 
Simplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationSimplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of Computation
 
Lex analysis
Lex analysisLex analysis
Lex analysis
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLP
 
Theory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptxTheory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptx
 
Ch02
Ch02Ch02
Ch02
 
PARSER .pptx
PARSER .pptxPARSER .pptx
PARSER .pptx
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
 
Ch03
Ch03Ch03
Ch03
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
 
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
 
context free grammars automata therory and compiler design
context free grammars automata therory and compiler designcontext free grammars automata therory and compiler design
context free grammars automata therory and compiler design
 
2020CSC4331_Lecture6_1.pdf
2020CSC4331_Lecture6_1.pdf2020CSC4331_Lecture6_1.pdf
2020CSC4331_Lecture6_1.pdf
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Class5