Documentation

This commit is contained in:
joachimschmidt557 2019-02-20 19:00:48 +01:00
parent 887e2d63c7
commit 0f5d632388
2 changed files with 31 additions and 3 deletions

11
DFA.fs
View file

@ -8,10 +8,16 @@ type State = { name: String }
/// A deterministic finite automaton
///
type DFA = {
/// All possible characters
sigma: Char list
/// All possible states
states: State list
/// All possible transitions
delta: State -> Char -> State
/// The state this DFA begins in
beginState: State
/// The states in which this DFA accepts
/// the word
acceptingStates: State list
}
@ -43,14 +49,19 @@ let validateDFA (dfa:DFA) =
allAcceptingStatesAreStates ||
deltaIsComplete
/// Returns the state the DFA is in after
/// reading this character
let processChar (dfa: DFA) (state: State) (char: Char) =
dfa.delta state char
/// Returns the state the DFA is in after
/// reading this character array
let rec processCharArray (dfa: DFA) (state: State) (charArr: Char list) =
match charArr with
| [] -> state
| head :: tail -> processCharArray dfa (processChar dfa state head) tail
/// Returns whether the DFA accepts this word
let acceptsWord (dfa: DFA) (word: String) =
dfa.acceptingStates
|> List.contains (processCharArray dfa dfa.beginState (Seq.toList word))