DFA foundation finished
This commit is contained in:
parent
2407dce1a6
commit
bb70c3df19
5 changed files with 287 additions and 13 deletions
25
DFA.fs
Normal file
25
DFA.fs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
module DFA
|
||||
|
||||
open System
|
||||
|
||||
type State = { name: String }
|
||||
|
||||
type DFA = {
|
||||
sigma: Char list
|
||||
states: State list
|
||||
delta: State -> Char -> State
|
||||
beginState: State
|
||||
acceptingStates: State list
|
||||
}
|
||||
|
||||
let processChar (dfa: DFA) (state: State) (char: Char) =
|
||||
dfa.delta state char
|
||||
|
||||
let rec processCharArray (dfa: DFA) (state: State) (charArr: Char list) =
|
||||
match charArr with
|
||||
| [] -> state
|
||||
| _ -> processCharArray dfa (processChar dfa state charArr.Head) charArr.Tail
|
||||
|
||||
let acceptsWord (dfa: DFA) (word: String) =
|
||||
dfa.acceptingStates
|
||||
|> List.contains (processCharArray dfa dfa.beginState (Seq.toList word))
|
||||
Loading…
Add table
Add a link
Reference in a new issue