Files
sml-projects/dotscape/fcore/parser/int-dfa.sml

28 lines
564 B
Standard ML
Raw Normal View History

2025-07-12 02:02:21 +01:00
structure IntDfa =
struct
2025-07-12 02:02:21 +01:00
val dead = 0
val start = 1
val final = 2
fun makeStart i =
2025-07-12 07:19:34 +01:00
let val chr = Char.chr i
in if Char.isDigit chr then final else dead
2025-07-12 02:02:21 +01:00
end
val deadTable = Vector.tabulate (255, fn _ => dead)
2025-07-12 07:19:34 +01:00
val startTable = Vector.tabulate (255, makeStart)
2025-07-12 02:02:21 +01:00
val finalTable = startTable
val tables = #[deadTable, startTable, finalTable]
2025-07-12 07:19:34 +01:00
fun isFinal state = state = final
2025-07-12 02:02:21 +01:00
fun next (state, chr) =
let
val table = Vector.sub (tables, state)
val idx = Char.ord chr
in
Vector.sub (table, idx)
end
end