SlideShare a Scribd company logo
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

More Related Content

What's hot

Optimization of dfa
Optimization of dfaOptimization of dfa
Optimization of dfa
Kiran Acharya
 
context free language
context free languagecontext free language
context free language
khush_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 NOTES
suthi
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examplesankitamakin
 
Context free languages
Context free languagesContext free languages
Context free languages
Jahurul Islam
 
Introduction to fa and dfa
Introduction to fa  and dfaIntroduction to fa  and dfa
Introduction to fa and dfa
deepinderbedi
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
Dattatray Gandhmal
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauagesdanhumble
 
Automata theory
Automata theoryAutomata theory
Automata theory
Pardeep Vats
 
Automata Theory
Automata TheoryAutomata Theory
Automata
AutomataAutomata
Automata
Gaditek
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
Riazul Islam
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
Radhakrishnan Chinnusamy
 
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
PrafullMisra
 
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
Srimatre 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 Parsing
kunj desai
 

What's hot (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
 

Similar to Regular expression

Flat unit 2
Flat unit 2Flat unit 2
Flat unit 2
VenkataRaoS1
 
re1.ppt
re1.pptre1.ppt
re1.ppt
PEzhumalai
 
Re1 (3)
Re1 (3)Re1 (3)
Re1 (3)
pepe3059
 
re1.ppt
re1.pptre1.ppt
RegularExpressions-theory of computation and formal language
RegularExpressions-theory of computation and formal languageRegularExpressions-theory of computation and formal language
RegularExpressions-theory of computation and formal language
mohdfareeduddin5
 
Unit2 Toc.pptx
Unit2 Toc.pptxUnit2 Toc.pptx
Unit2 Toc.pptx
viswanath kani
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysisraosir123
 
UNIT_-_II.docx
UNIT_-_II.docxUNIT_-_II.docx
UNIT_-_II.docx
karthikeyan Muthusamy
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
gadisaAdamu
 
1LECTURE 8 Regular_Expressions.ppt
1LECTURE 8 Regular_Expressions.ppt1LECTURE 8 Regular_Expressions.ppt
1LECTURE 8 Regular_Expressions.ppt
Marvin886766
 
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
Rushabh2428
 
QB104541.pdf
QB104541.pdfQB104541.pdf
QB104541.pdf
MrRRajasekarCSE
 
Regular expression
Regular expressionRegular expression
Regular expression
Rajon
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
MDSayem35
 
Unit ii
Unit iiUnit ii
Unit ii
TPLatchoumi
 
Regular Expressions To Finite Automata
Regular Expressions To Finite AutomataRegular Expressions To Finite Automata
Regular Expressions To Finite Automata
International Institute of Information Technology (I²IT)
 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdf
ImranBhatti58
 

Similar to 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
 
RegularExpressions-theory of computation and formal language
RegularExpressions-theory of computation and formal languageRegularExpressions-theory of computation and formal language
RegularExpressions-theory of computation and formal language
 
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
 

Recently uploaded

Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 

Recently uploaded (20)

Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 

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).