Docsity

Converting Regular Expressions to DFAs: NFA to DFA and RE to NFA - Prof. Elsa Gunter, Study notes of Computer Science

Partial preview of the text

Download Converting Regular Expressions to DFAs: NFA to DFA and RE to NFA - Prof. Elsa Gunter and more Study notes Computer Science in PDF only on Docsity!

Using Regular ExpressionsNFA to DFA RE to NFA Activity

CS421 Lecture 10: Converting Regular

Expressions to DFAs^1

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

Subset Construction

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

ǫ Closure

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

Performing the Subset Construction

◮ (^) 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

Example 1

A B

Using Regular Expressions NFA to DFA RE to NFA Activity

Subset Construction Example 1 Example 2

Example 1

A B

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

Example 1

A B

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

Example 1

A B

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

Example 1

A B

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

Example 1

A B

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

Example 1

{A} {A, B}

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

Example 2

A B

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

Example 2

A B

New states: {A, B} New edges: ({A, B}, 0 , {A}(ǫ)), ({A, B}, 1 , )