SlideShare uma empresa Scribd logo
1 de 21
NORTH WESTERN UNIVERSITY
Computer Science & Engineering
Course Titel: Compiler Design
Course Code: CSE-4103
Presentation on: REGULAR EXPRESSION
Submitted by:
Name : MD. MONIRUL ISLAM
ID: 20151116010
Submitted to:
Name : SAJIB CHATTERJEE
Lecturer
Computer Science & Engineering
North Western University , Khulna
INDEX:
* General Introduction
* Equivalence of FA and RE
* DFA to RE: State Elimination
* Converting a RE to an Automata
* Algebra for Regular Expression’s
* References.
General Introduction
► Regular expression is an important notation for specifying patterns. Each pattern
matches a set of strings, so regular expressions serve as names for a set of strings.
Programming language tokens can be described by regular languages.[1]
R is a regular expression if it is:
1. a for some a in the alphabet , standing for the language {a}
2. ε, standing for the language {ε}
3. Ø, standing for the empty language
4. R1+R2 where R1 and R2 are regular expressions, and + signifies
union (sometimes | is used)
5. R1R2 where R1 and R2 are regular expressions and this signifies
concatenation
6. R* where R is a regular expression and signifies closure
7. (R) where R is a regular expression, then a parenthesized R is
also a regular expression
This definition may seem circular, but 1-3 form the basis
Precedence: Parentheses have the highest precedence, followed by *,
concatenation, and then union.
RE Examples
• L(001) = {001}
• L(0+10*) = { 0, 1, 10, 100, 1000, 10000, … }
• L(0*10*) = {1, 01, 10, 010, 0010, …} i.e. {w | w has exactly a single 1}
• L()* = {w | w is a string of even length}
• L((0(0+1))*) = { ε, 00, 01, 0000, 0001, 0100, 0101, …}
• L((0+ε)(1+ ε)) = {ε, 0, 1, 01}
• L(1Ø) = Ø ; concatenating the empty set to any set yields the empty set.
• R ε = R
• R+Ø = R
• Note that R + ε may or may not equal R (we are adding ε to the language)
• Note that RØ will only equal R if R itself is the empty set.
Equivalence of FA and RE
Finite Automata and Regular Expressions are equivalent. To show this:
- we can express a DFA as an equivalent RE
- we can express a RE as an ε-NFA. Since the ε-NFA can be converted to
a DFA and the DFA to an NFA, then RE will be equivalent to all the
automata we have described.
DFA to RE: State Elimination
 Eliminates states of the automaton and replaces the edges with regular
expressions that includes the behavior of the eliminated states.
 Eventually we get down to the situation with just a start and final node, and
this is easy to express as a RE
State Elimination
 Consider the figure below, which shows a generic state s about to be eliminated.
The labels on all edges are regular expressions.
 To remove s, we must make labels from each qi to p1 up to pm that include the
paths we could have made through s.
q1
qk
s
p1
pm
.
.
.
.
.
.
R1m
R11
SQ1
QK
Rkm
Rk1
P1
Pm
q1
qk
p1
pm
.
.
.
R11+Q1S*P1
Rkm+QkS*Pm
.
.
.
Rk1+QkS*P1
R1m+Q1S*Pm
DFA to RE via State Elimination
 Starting with intermediate states and then moving to accepting states, apply the state
elimination process to produce an equivalent automaton with regular expression labels
on the edges.
The result will be a one or two state automaton with a start state and accepting state.
 If the two states are different, we will have an automaton that looks
like the following:
Start
S
R
T
U
Figure 01 : (R+SU*T)*SU*
 If the start state is also an accepting state, then we must also perform a state elimination
from the original automaton that gets rid of every state but the start state. This leaves the
following:
Start
R
Figure 02: R*.
 If there are n accepting states, we must repeat the above steps for each accepting states
to get n different regular expressions, R1, R2, … Rn. For each repeat we turn any other
accepting state to non-accepting. The desired regular expression for the automaton is
then the union of each of the n regular expressions: R1 R2…  RN
DFARE Example
Convert the following to a RE
Figure 03: Convert to RE
First convert the edges to RE’s:
3Start 1 2
1 1
0
0
0,1
3Start 1 2
1 1
0
0
0+1
Eliminate State 1:
To: 3Start 1 2
1 1
0
Figure 04: Convert to RE
0+1
3Start 2
11
0+10 0+1
Note edge from 33
Figure 05: (0+10)*11(0+1)*
Converting a RE to an Automata
 we can convert an automata to a RE. To show equivalence we must also go the other
direction, convert a RE to an automaton.
 We can do this easiest by converting a RE to an ε-NFA
-Inductive construction
-Start with a simple basis, use that to build more complex parts of the NFA
Basis:
R=a
R=ε
a
ε
R=Ø
R=S+T
S
T
ε
ε
ε
ε
R=ST S ε
ε
ε
T
R=S* S ε
Figure 06: RE to an Automata
Figure 07: RE to an Automata
Figure 08: RE to an Automata
RE to ε-NFA Example
Convert R= (ab+a)* to an NFA
We proceed in stages, starting from simple elements and working our way up
a
a
b
b
ab
a bε
ab+a
a bε
a
ε
ε
ε
ε
(ab+a)*
a bε
a
ε
ε
ε
ε
εε
ε
Figure 09: RE to NFA
Figure 10: RE to NFA
Algebraic Laws for RE’s
Just like we have an algebra for arithmetic, we also have an algebra for regular
expressions.
-While there are some similarities to arithmetic algebra, it is a bit different with regular
expressions.
Algebra for RE’s
Commutative law for union:
L + M = M + L
Associative law for union:
(L + M) + N = L + (M + N)
Associative law for concatenation:
(LM)N = L(MN)
Note that there is no commutative law for
concatenation,
i.e. LM  ML
The identity for union is:
L + Ø = Ø + L = L
The identity for concatenation is:
L ε = ε L = L
The annihilator for concatenation is:
ØL = LØ = Ø
Left distributive law:
L(M + N) = LM + LN
Right distributive law:
(M + N)L = LM + LN
Idempotent law:
L + L = L
Laws Involving Closure
(L*)* = L*
i.e. closing an already closed expression does not change the language
Ø* = ε
ε* = ε
L+ = LL* = L*L
more of a definition than a law
L* = L+ + ε
L? = ε + L
more of a definition than a law
References
[1] Compiler Design - Regular Expressions ,tutorialspoint.
[2] Wikipedia.
[3] Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman-Compilers -
Principles, Techniques, and Tools-Pearson_Addison Wesley (2006).
THANK YOU

Mais conteúdo relacionado

Mais procurados

context free language
context free languagecontext free language
context free languagekhush_boo31
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR Zahid Parvez
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESsuthi
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examplesankitamakin
 
Context free languages
Context free languagesContext free languages
Context free languagesJahurul Islam
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfadeepinderbedi
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauagesdanhumble
 
Automata
AutomataAutomata
AutomataGaditek
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler designRiazul Islam
 
Thoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's ClassificationThoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's ClassificationPrafullMisra
 
Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2Srimatre K
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Mohammad Ilyas Malik
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsingkunj desai
 

Mais procurados (20)

Optimization of dfa
Optimization of dfaOptimization of dfa
Optimization of dfa
 
context free language
context free languagecontext free language
context free language
 
CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR CONTEXT FREE GRAMMAR
CONTEXT FREE GRAMMAR
 
AUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTESAUTOMATA THEORY - SHORT NOTES
AUTOMATA THEORY - SHORT NOTES
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
Context free languages
Context free languagesContext free languages
Context free languages
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfa
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
 
Finite automata
Finite automataFinite automata
Finite automata
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Automata Theory
Automata TheoryAutomata Theory
Automata Theory
 
Automata
AutomataAutomata
Automata
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
Thoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's ClassificationThoery of Computaion and Chomsky's Classification
Thoery of Computaion and Chomsky's Classification
 
Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
 
Compiler Design QA
Compiler Design QACompiler Design QA
Compiler Design QA
 

Semelhante a Regular expression (20)

Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2
 
FLAT.pdf
FLAT.pdfFLAT.pdf
FLAT.pdf
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
Re1 (3)
Re1 (3)Re1 (3)
Re1 (3)
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
re1.ppt
re1.pptre1.ppt
re1.ppt
 
Unit2 Toc.pptx
Unit2 Toc.pptxUnit2 Toc.pptx
Unit2 Toc.pptx
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
UNIT_-_II.docx
UNIT_-_II.docxUNIT_-_II.docx
UNIT_-_II.docx
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
 
1LECTURE 8 Regular_Expressions.ppt
1LECTURE 8 Regular_Expressions.ppt1LECTURE 8 Regular_Expressions.ppt
1LECTURE 8 Regular_Expressions.ppt
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
 
QB104541.pdf
QB104541.pdfQB104541.pdf
QB104541.pdf
 
Regular expression
Regular expressionRegular expression
Regular expression
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 
Unit ii
Unit iiUnit ii
Unit ii
 
Regular Expressions To Finite Automata
Regular Expressions To Finite AutomataRegular Expressions To Finite Automata
Regular Expressions To Finite Automata
 
Compiler Design Material 2
Compiler Design Material 2Compiler Design Material 2
Compiler Design Material 2
 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdf
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
 

Último

Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 

Último (20)

Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 

Regular expression

  • 1. NORTH WESTERN UNIVERSITY Computer Science & Engineering Course Titel: Compiler Design Course Code: CSE-4103 Presentation on: REGULAR EXPRESSION Submitted by: Name : MD. MONIRUL ISLAM ID: 20151116010 Submitted to: Name : SAJIB CHATTERJEE Lecturer Computer Science & Engineering North Western University , Khulna
  • 2. INDEX: * General Introduction * Equivalence of FA and RE * DFA to RE: State Elimination * Converting a RE to an Automata * Algebra for Regular Expression’s * References.
  • 3. General Introduction ► Regular expression is an important notation for specifying patterns. Each pattern matches a set of strings, so regular expressions serve as names for a set of strings. Programming language tokens can be described by regular languages.[1]
  • 4. R is a regular expression if it is: 1. a for some a in the alphabet , standing for the language {a} 2. ε, standing for the language {ε} 3. Ø, standing for the empty language 4. R1+R2 where R1 and R2 are regular expressions, and + signifies union (sometimes | is used) 5. R1R2 where R1 and R2 are regular expressions and this signifies concatenation 6. R* where R is a regular expression and signifies closure 7. (R) where R is a regular expression, then a parenthesized R is also a regular expression This definition may seem circular, but 1-3 form the basis Precedence: Parentheses have the highest precedence, followed by *, concatenation, and then union.
  • 5. RE Examples • L(001) = {001} • L(0+10*) = { 0, 1, 10, 100, 1000, 10000, … } • L(0*10*) = {1, 01, 10, 010, 0010, …} i.e. {w | w has exactly a single 1} • L()* = {w | w is a string of even length} • L((0(0+1))*) = { ε, 00, 01, 0000, 0001, 0100, 0101, …} • L((0+ε)(1+ ε)) = {ε, 0, 1, 01} • L(1Ø) = Ø ; concatenating the empty set to any set yields the empty set. • R ε = R • R+Ø = R • Note that R + ε may or may not equal R (we are adding ε to the language) • Note that RØ will only equal R if R itself is the empty set.
  • 6. Equivalence of FA and RE Finite Automata and Regular Expressions are equivalent. To show this: - we can express a DFA as an equivalent RE - we can express a RE as an ε-NFA. Since the ε-NFA can be converted to a DFA and the DFA to an NFA, then RE will be equivalent to all the automata we have described.
  • 7. DFA to RE: State Elimination  Eliminates states of the automaton and replaces the edges with regular expressions that includes the behavior of the eliminated states.  Eventually we get down to the situation with just a start and final node, and this is easy to express as a RE
  • 8. State Elimination  Consider the figure below, which shows a generic state s about to be eliminated. The labels on all edges are regular expressions.  To remove s, we must make labels from each qi to p1 up to pm that include the paths we could have made through s. q1 qk s p1 pm . . . . . . R1m R11 SQ1 QK Rkm Rk1 P1 Pm q1 qk p1 pm . . . R11+Q1S*P1 Rkm+QkS*Pm . . . Rk1+QkS*P1 R1m+Q1S*Pm
  • 9. DFA to RE via State Elimination  Starting with intermediate states and then moving to accepting states, apply the state elimination process to produce an equivalent automaton with regular expression labels on the edges. The result will be a one or two state automaton with a start state and accepting state.  If the two states are different, we will have an automaton that looks like the following: Start S R T U Figure 01 : (R+SU*T)*SU*
  • 10.  If the start state is also an accepting state, then we must also perform a state elimination from the original automaton that gets rid of every state but the start state. This leaves the following: Start R Figure 02: R*.  If there are n accepting states, we must repeat the above steps for each accepting states to get n different regular expressions, R1, R2, … Rn. For each repeat we turn any other accepting state to non-accepting. The desired regular expression for the automaton is then the union of each of the n regular expressions: R1 R2…  RN
  • 11. DFARE Example Convert the following to a RE Figure 03: Convert to RE First convert the edges to RE’s: 3Start 1 2 1 1 0 0 0,1 3Start 1 2 1 1 0 0 0+1
  • 12. Eliminate State 1: To: 3Start 1 2 1 1 0 Figure 04: Convert to RE 0+1 3Start 2 11 0+10 0+1 Note edge from 33 Figure 05: (0+10)*11(0+1)*
  • 13. Converting a RE to an Automata  we can convert an automata to a RE. To show equivalence we must also go the other direction, convert a RE to an automaton.  We can do this easiest by converting a RE to an ε-NFA -Inductive construction -Start with a simple basis, use that to build more complex parts of the NFA Basis: R=a R=ε a ε R=Ø
  • 14. R=S+T S T ε ε ε ε R=ST S ε ε ε T R=S* S ε Figure 06: RE to an Automata Figure 07: RE to an Automata Figure 08: RE to an Automata
  • 15. RE to ε-NFA Example Convert R= (ab+a)* to an NFA We proceed in stages, starting from simple elements and working our way up a a b b ab a bε
  • 17. Algebraic Laws for RE’s Just like we have an algebra for arithmetic, we also have an algebra for regular expressions. -While there are some similarities to arithmetic algebra, it is a bit different with regular expressions.
  • 18. Algebra for RE’s Commutative law for union: L + M = M + L Associative law for union: (L + M) + N = L + (M + N) Associative law for concatenation: (LM)N = L(MN) Note that there is no commutative law for concatenation, i.e. LM  ML The identity for union is: L + Ø = Ø + L = L The identity for concatenation is: L ε = ε L = L The annihilator for concatenation is: ØL = LØ = Ø Left distributive law: L(M + N) = LM + LN Right distributive law: (M + N)L = LM + LN Idempotent law: L + L = L
  • 19. Laws Involving Closure (L*)* = L* i.e. closing an already closed expression does not change the language Ø* = ε ε* = ε L+ = LL* = L*L more of a definition than a law L* = L+ + ε L? = ε + L more of a definition than a law
  • 20. References [1] Compiler Design - Regular Expressions ,tutorialspoint. [2] Wikipedia. [3] Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman-Compilers - Principles, Techniques, and Tools-Pearson_Addison Wesley (2006).