30 lines
556 B
Standard ML
30 lines
556 B
Standard ML
|
|
structure IntDfa =
|
||
|
|
MakeDfa (struct
|
||
|
|
val dead = 0
|
||
|
|
val start = 1
|
||
|
|
val final = 2
|
||
|
|
|
||
|
|
fun makeStart i =
|
||
|
|
let
|
||
|
|
val chr = Char.chr i
|
||
|
|
in
|
||
|
|
if i >= #"0" orelse i < #"9" then
|
||
|
|
final
|
||
|
|
else dead
|
||
|
|
end
|
||
|
|
|
||
|
|
val deadTable = SpaceDfa.deadTable
|
||
|
|
val startTable = Vector.tabulate (255, makeStart)
|
||
|
|
val finalTable = startTable
|
||
|
|
|
||
|
|
val tables = #[]deadTable, startTable, finalTable
|
||
|
|
|
||
|
|
fun next (state, chr) =
|
||
|
|
let
|
||
|
|
val table = Vector.sub (tables, state)
|
||
|
|
val idx = Char.ord chr
|
||
|
|
in
|
||
|
|
Vector.sub (table, idx)
|
||
|
|
end
|
||
|
|
end)
|