Regular Expressions: Reading: Chapter 3
Regular Expressions: Reading: Chapter 3
Regular Expressions: Reading: Chapter 3
Reading: Chapter 3
Regular Expressions
Regular
expressions
Finite Automata
(DFA, NFA, -NFA)
Syntactical
expressions
Automata/machines
Regular
Languages
Formal language
classes
3
Language Operators
L0= {}
Example:
Let L = { 1, 00}
L0= {}
L1= {1,00}
L2= {11,100,001,0000}
L3= {111,1100,1001,10000,000000,00001,00100,0011}
L* = L0 U L1 U L2 U
5
L *
Why?
(E) = E
L(E + F) = L(E) U L(F)
L(E F) = L(E) L(F)
L(E*) = (L(E))*
Case A:
Case B:
Case C:
Case D:
(01)*
(10)*
0(10)*
1(01)*
Precedence of Operators
Highest to lowest
* operator (star)
(concatenation)
+ operator
Example:
01* + 1 = ( 0 . ((1)*) ) + 1
9
Proofs
in the book
NFA
Kleene Theorem
Theorem 2
Reg Ex
DFA
Theorem 1
10
DFA
Theorem 1
Reg Ex
DFA to RE construction
Informally, trace all distinct paths (traversing cycles only once)
from the start state to each of the final states
and enumerate all the expressions along the way
Example:
1
q0
(1*) 0
1*
0,1
0
q1
q2
(0*) 1
(0 + 1)*
(0+1)*
00*
11
Reg Ex
-NFA
Theorem 2
RE to -NFA construction
(0+1)*01(0+1)*
Example:
(0+1)*
01
(0+1)*
12
Commutative:
Associative:
(E+F)+G = E+(F+G)
(EF)G = E(FG)
Identity:
E+F = F+E
E+ = E
E=E=E
Annihilator:
E = E =
13
Algebraic Laws
Distributive:
E(F+G) = EF + EG
(F+G)E = FE+GE
Idempotent: E + E = E
Involving Kleene closures:
(E*)* = E*
* =
* =
E+ =EE*
E?
= +E
14
True or False?
Let R and S be two regular expressions. Then:
1.
((R*)*)* = R*
2.
(R+S)* = R* + S*
3.
15
Summary
Regular expressions
Equivalence to finite automata
DFA to regular expression conversion
Regular expression to -NFA conversion
Algebraic laws of regular expressions
Unix regular expressions and Lexical
Analyzer
16