Regular Expression & Autometa
Regular Expression & Autometa
Regular Expression & Autometa
Processing
Definitions
a, b, c,, z
2
Alphabets and Strings
5
Basic Regular Expression Patterns
6
Disjunction, Grouping, and Precedence
• Disjunction
• /cat|dog
• Precedence
• /gupp(y|ies)
• To find the English article the
• /the/
• /[tT]he/
• /[^a-zA-Z][tT]he[^a-zA-Z]/
7
Aliases for common sets of characters
8
Regular expression operators for counting
9
Some characters that need to be backslashed
10
Finite State Automata
q0 q1 q2 q3 q4
11
Formally
q0 q1 q2 q3 q4
12
• FSA recognizes (accepts) strings of a
regular language
baa! a
baaa! b a a !
q0 q1 q2 q3 q4
baaaa!
…
• Tape Input: a rejected input
a b a ! b
13
State Transition Table for SheepTalk
Input
State
baa! b a !
baaa!
baaaa!
0 1 Ø Ø
baaaaa
! 1 Ø 2 Ø
...
2 Ø 3 Ø
a 3 Ø 3 4
b a a !
4 Ø Ø Ø
q0 q1 q2 q3 q4
14
Non-Deterministic FSAs for SheepTalk
b a a a !
q0 q1 q2 q3 q4
b a a !
q0 q1 q2 q3 q4
15
Finite Accepter
• Input
String
Output
“Accept”
Finite
or
Automata
“Reject”
16
Transition Graph
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
initial final
state state
transition
state “accept”
17
Initial Configuration
• Input String
a b b a
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
18
Reading the Input
• a b b a
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 19
• a b b a
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 20
• a b b a
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 21
• a b b a
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 22
a b b a
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
Output: “accept”
2/5/2020 23
Rejection
• a b a
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 24
• a b a
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 25
• a b a
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 26
• a b a
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 27
a b a
a, b
Output:
q5 “reject”
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 28
Another Example
a a b
a a, b
q0 b q1 a, b q2
2/5/2020 29
a a b
a a, b
q0 b q1 a, b q2
2/5/2020 30
a a b
a a, b
q0 b q1 a, b q2
2/5/2020 31
a a b
a a, b
q0 b q1 a, b q2
2/5/2020 32
a a b
a a, b
Output: “accept”
q0 b q1 a, b q2
2/5/2020 33
Rejection
b a b
a a, b
q0 b q1 a, b q2
2/5/2020 34
b a b
a a, b
q0 b q1 a, b q2
2/5/2020 35
b a b
a a, b
q0 b q1 a, b q2
2/5/2020 36
b a b
a a, b
q0 b q1 a, b q2
2/5/2020 37
b a b
a a, b
q0 b q1 a, b q2
Output: “reject”
2/5/2020 38
Formalities
M Q, , , q0 , F
Q : set of states
: input alphabet
: transition function
q0 : initial state
2/5/2020 40
Input Aplhabet
• a, b
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2/5/2020 41
Set of States
Q
Q q0 , q1, q2 , q3 , q4 , q5
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 42
Initial State
q0
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 43
Set of Final States
F
F q4
a, b
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4
2/5/2020 44
Transition Function
:Q Q
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2/5/2020 45
q0 , a q1
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2/5/2020 46
q0 , b q5
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2/5/2020 47
q2 , b q3
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2/5/2020 48
Transition Function
a b
q0 q1 q5
q1 q5 q2
q2 q2 q3 a, b
q3 q4 q5
q4 q5 q5 q5
q5 q5 q5 a, b
b a a b
q0 a q1 b q2 b q3 a q4
2/5/2020 49
Extended Transition Function
(Reads the entire string) *
* : Q * Q
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2/5/2020 50
* q0 , ab q2
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2/5/2020 51
* q0 , abba q4
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2/5/2020 52
* q0 , abbbaa q5
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2/5/2020 53
Observation: There is a walk from q0 to q 5
with label abbbaa
* q0 , abbbaa q5
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
2/5/2020 54
Example
LM abba M
a, b
q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4
accept
2/5/2020 55
Another Example
a, b
q5
b a a a, b
b
q0 a q1 b q2 b q3 a q4
2/5/2020 56
More Examples
LM {a b : n 0}
n
a a, b
q0 b q1 a, b q2
2/5/2020 57
LM = { all substrings with prefix ab }
a, b
q0 a q1 b q2
b a accept
q3 a, b
2/5/2020 58
LM = { all strings without
substring 001 }
1 0 0,1
1
0 1
0 00 001
0
2/5/2020 59
Regular Languages
2/5/2020 60
Example
b a
q4
a, b
2/5/2020 61
Dollars and Cents
2/5/2020 62