Skip to content

Instantly share code, notes, and snippets.

@t0yv0
Created February 9, 2011 10:44
Show Gist options
  • Select an option

  • Save t0yv0/818289 to your computer and use it in GitHub Desktop.

Select an option

Save t0yv0/818289 to your computer and use it in GitHub Desktop.
module DFA =
let rec nextState current token =
match current.Transitions.TryGetValue token with
| true, state -> state
| _ ->
let rec loop current next =
if Set.isEmpty current then getState next else
let min = Set.minElement current
let current = Set.remove min current
match min with
| NFA.Branch br ->
loop (current.Add(br.x).Add(br.y)) next
| NFA.Read (_, f, n) ->
if f token
then loop current (next.Add n)
else loop current next
| NFA.Match ->
loop current next
let next = loop current.States Set.empty
current.Transitions.[token] <- next
next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment