Regular Expressions

Download Report

Transcript Regular Expressions

COT 4210
Lecture Notes - 3
By Njegos and Monika
R is a regular expression if R is
1. aЄΣ, a for some a in the alphabet Σ.
2. ε
3. Ø
4. R1 U R2, where R1 and R2 are regular
expression
5. R1o R2, where R1 and R2 are regular
expressions
6. R1*, where R1 is a regular expression
If A1 and A2 are regular then
• A1 U A2
• A1 o A2
• A1*
All are regular too.
Regular Expression
• 0*10*:- zero or more 0’s followed by one 1
and followed by any number of 0’s or no 0
• (0 U ε) 1*:- 0 followed by any number of
1’s or any number of 1’s
• 1* Ø :- Take zero or more 1’s and
concatenated by empty set. 1* Ø = Ø
• Ø*:- {ε} ; Empty string
N1 U N2
N
ε
N1
ε
N2
A1*
ε
ε
ε
0U1
ε
ε
0
1
(0 U 1)*
ε
ε
0
ε
ε
ε
1
0 (0 U 1)* 0
ε
0
ε
ε
0
ε
0
ε
ε
ε
1
ε
0 U 0 (0 U 1)* 0
0
ε
ε
ε
ε
0
ε
0
ε
0
ε
ε
ε
1
ε
Qi
R4
Qj
R3
R1
Qrip
R1 R2* R3 U R4
Qi
Qj
GNFA
• GNFA stands for Generalized
Nondeterministic Finite Automaton.
• GNFA are simply nondeterministic finite
automaton wherein the transition arrows
may have any regular expressions as
labels, instead of only members of the
alphabet.
Restricted GNFA
• The start state has transition arrows going to
every other state but no arrows coming in from
any other state.
• There is only a single accept state, and it has
arrows coming in from every other state but no
arrows going to any other state. Accept state is
not the same as the start state.
• Except for the start and accept states, one arrow
goes from every state to every other state and
also from each state to itself.
EXAMPLE
0
S
ε
1
1
Q1
ε
F
1
Q2
0
0
Q3
After Ripping Q3
0
S
ε
1
Q1
Q2
1
01*0
ε
F
10*1 U 01*0
R2
0*1
S
Q2
0*
R4
10* R3
F
0*1(10*1 U 01*0)*10* U 0*
• If we have n states in DFA then restricted
GNFA is going to have (n+2) states.