begin parser to load from file
This commit is contained in:
34
fcore/parsing/space-dfa.sml
Normal file
34
fcore/parsing/space-dfa.sml
Normal file
@@ -0,0 +1,34 @@
|
||||
structure SpaceDfa =
|
||||
struct
|
||||
val dead = 0
|
||||
val start = 1
|
||||
val final = 2
|
||||
|
||||
fun makeDead _ = 0
|
||||
|
||||
fun makeStart i =
|
||||
let
|
||||
val chr = Char.chr i
|
||||
in
|
||||
if chr = #" " orelse chr = #"\n"
|
||||
then final
|
||||
else dead
|
||||
end
|
||||
|
||||
val deadTable = Vector.tabulate (255, makeDead)
|
||||
val startTable = Vector.tabulate (255, makeStart)
|
||||
val finalTable = startTable
|
||||
|
||||
val tables = #[deadTable, startTable, finalTable]
|
||||
|
||||
fun isFinal state =
|
||||
state = final
|
||||
|
||||
fun next (state, chr) =
|
||||
let
|
||||
val table = Vector.sub (tables, state)
|
||||
val idx = Char.ord chr
|
||||
in
|
||||
Vector.sub (table, idx)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user