Created
February 9, 2011 10:44
-
-
Save t0yv0/818289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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