



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















q
q2 q
q
Is this a DFA or NFA? What strings does it recognize?
Regular Expressions
C code
Some kind of DFAs and NFAs stuff going on inside
s
f
general machine
ε
empty string transition
x
alphabet symbol transition
Concatenation:
ε
ε
ε
ε
•New start state S
ε
-transition to the start state of E
ε
-transition from final/accepting state of E1 to A,
ε
-transition from A to start
state of E2•
ε
-transitions from the final/accepting state E2 to the new final state F
ε
ε
ε
ε
Develop an NFA for the RE: (x | y)*
x y
First create NFA for (x | y)
ε
ε
ε
ε
x y
ε
ε
ε
ε
Then add in the closure operator
Develop an NFA for the RE: (+? | -?) d+
» Solve by subset construction » Build new DFA based upon the power set of states on
the NFA
» Move (S,a) is relabeled to target a new state whenever
single input goes to multiple states
a
a
b
a+ b*
(1,a)
Æ
1 or 2, create new state 1/
(1/2,a)
Æ
1/
(1/2,b)
Æ
2
a
a
start
start
b
b
(2,a)
Æ
ERROR
(2,b)
Æ
2
Any state with “2” in name is a final state
» Any state reachable by an
ε
transition is “part of the
state”
»
ε
-closure - Any state reachable from S by
ε
transitions
is in the
ε
-closure; treat
ε
-closure as 1 big state,
always include
ε
-closure as part of the state
a
b
start
ε
ε
ε
-closure(1) = {1,2,3} ε
-closure(2) = {2,3} create new state 1/2/3create new state 2/
2/
3
a
b
start
1/2/
a
b
(1/2/3, a)
Æ
2/
(1/2/3, b)
Æ
3
(2/3, a)
Æ
2/
(2/3, b)
Æ
3
ab
0
1
(^24)
6
(^35)
9
7
ε
ε
ε ε
ε ε
a
b
ε^ ε a
8
b
Convert this NFA to a DFA
» Combine nodes that
comprise cycle
» Combine 2 and 3
» Remove state 4,
change transition 2-4to 2-
a
c
start
ε ε
ε ε
ε
ε
b
start
a
ε
c
ε
» All transitions from states in group G1 go to states in
another group G
» Construct minimized DFA such that there is 1 state for
each group of states
b
start
b a
b
a
a
b
a
Basic strategy: identifydistinguishing transitions
Optimize DFA DFA Simulation
Character Stream
REs for Tokens
Token stream (and errors)
Flex
Remaining issues: how to Simulate, multiple REs, producing a token stream, longest match, rule priority