







































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!








































Using Regular ExpressionsNFA to DFA RE to NFA Activity
Mark Hills [email protected]
University of Illinois at Urbana-Champaign
June 26, 2006
(^1) Based on slides by Mattox Beckman, as updated by Vikram Adve, Gul Agha, and Elsa Gunter
Using Regular ExpressionsNFA to DFA RE to NFA Activity
Using Regular Expressions
NFA to DFA
RE to NFA
Activity
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset Construction Example 1 Example 2
To convert from an NFA to a DFA, we somehow need to account for multiple paths with the same label. ◮ (^) Key Concept: All states reachable in NFA along a given path should be same state in DFA ◮ (^) DFA states will thus be subsets of set of NFA states
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset Construction Example 1 Example 2
Also, we don’t have ǫ in DFAs – how do we eliminate this? ◮ (^) The ǫ closure S(ǫ) of S, a set of states, is the smallest set ◮ (^) containing S ◮ (^) for all s ∈ S and all states t, if (s, ǫ, t) is an edge then t ∈ S
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset Construction Example 1 Example 2
◮ (^) Begin with S = {s 0 }(ǫ), the ǫ-closure of the set containing just the NFA start state – this is our DFA start state ◮ (^) While our states keep changing ◮ (^) for each new state S and letter α, add state S(α)(ǫ), the ǫ closure of all states α-reachable from S ◮ (^) add edge (S, α, S(α)(ǫ)) ◮ (^) Mark as final states any set of states in the DFA containing a final state from the NFA Any problems? ◮ (^) Potentially exponential in the number of NFA states
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset Construction Example 1 Example 2
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset Construction Example 1 Example 2
New states: {A} New edges: ({A}, 0 , ), ({A}, 1 , )
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset Construction Example 1 Example 2
New states: {A} New edges: ({A}, 0 , {A}), ({A}, 1 , )
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset Construction Example 1 Example 2
New states: {A}, {A, B} New edges: ({A}, 0 , {A}), ({A}, 1 , {A, B}), ({A, B}, 0 , ), ({A, B}, 1 , )
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset Construction Example 1 Example 2
New states: {A}, {A, B} New edges: ({A}, 0 , {A}), ({A}, 1 , {A, B}), ({A, B}, 0 , {A}), ({A, B}, 1 , )
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset Construction Example 1 Example 2
New states: {A}, {A, B} New edges: ({A}, 0 , {A}), ({A}, 1 , {A, B}), ({A, B}, 0 , {A}), ({A, B}, 1 , {A, B}) Final states: {A, B}
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset Construction Example 1 Example 2
New states: {A}, {A, B} New edges: ({A}, 0 , {A}), ({A}, 1 , {A, B}), ({A, B}, 0 , {A}), ({A, B}, 1 , {A, B}) Final states: {A, B}
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset ConstructionExample 1 Example 2
New states: {A}(ǫ) = {A, B} New edges: ({A, B}, 0 , ), ({A, B}, 1 , )
Using Regular Expressions NFA to DFA RE to NFA Activity
Subset ConstructionExample 1 Example 2
New states: {A, B} New edges: ({A, B}, 0 , {A}(ǫ)), ({A, B}, 1 , )