Maybe finished NFAs

This commit is contained in:
joachimschmidt557 2019-02-20 18:49:45 +01:00
parent bb641e26f1
commit 887e2d63c7
3 changed files with 45 additions and 2 deletions

26
NFA.fs
View file

@ -14,4 +14,28 @@ type NFA = {
}
let processChar (nfa: NFA) (state: State) (char: Char) =
nfa.delta state char
nfa.delta state char
let rec processCharArray (nfa: NFA) (states: State list) (charArr: Char list) : State list =
match charArr with
| [] -> states
| head :: tail ->
processCharArray
nfa
(
states
|> List.map (fun x -> processChar nfa x head)
|> List.filter (List.isEmpty >> not)
|> (fun x ->
if not (List.isEmpty x) then
List.reduce List.append x
else [])
)
tail
let acceptsWord nfa word =
match processCharArray nfa [nfa.beginState] (Seq.toList word) with
| [] -> false
| x -> x
|> List.map (fun x -> List.contains x nfa.acceptingStates)
|> List.exists id