interpret concatenation and alternation in nfa
This commit is contained in:
@@ -16,6 +16,28 @@ struct
|
|||||||
val concatLevel = 3
|
val concatLevel = 3
|
||||||
val altLevel = 4
|
val altLevel = 4
|
||||||
|
|
||||||
|
local
|
||||||
|
fun loop (tl, maxValid) =
|
||||||
|
case tl of
|
||||||
|
(_, VALID curValid) :: tl => loop (tl, Int.max (maxValid, curValid))
|
||||||
|
| (_, UNTESTED) :: _ => UNTESTED
|
||||||
|
| (_, INVALID) :: _ =>
|
||||||
|
raise Fail
|
||||||
|
"nfa.sml 24: \
|
||||||
|
\should not have INVALID state in acc"
|
||||||
|
| [] => VALID maxValid
|
||||||
|
in
|
||||||
|
fun getAlternationState acc =
|
||||||
|
case acc of
|
||||||
|
(_, VALID maxValid) :: tl => loop (tl, maxValid)
|
||||||
|
| (_, UNTESTED) :: _ => UNTESTED
|
||||||
|
| (_, INVALID) :: _ =>
|
||||||
|
raise Fail
|
||||||
|
"nfa.sml 26: \
|
||||||
|
\should not have INVALID state in acc"
|
||||||
|
| [] => UNTESTED
|
||||||
|
end
|
||||||
|
|
||||||
local
|
local
|
||||||
fun rebuildConcat (lst, chr, idx) =
|
fun rebuildConcat (lst, chr, idx) =
|
||||||
case lst of
|
case lst of
|
||||||
@@ -61,9 +83,9 @@ struct
|
|||||||
VALID _ => (hd, state) :: acc
|
VALID _ => (hd, state) :: acc
|
||||||
| UNTESTED => (hd, state) :: acc
|
| UNTESTED => (hd, state) :: acc
|
||||||
| INVALID => acc
|
| INVALID => acc
|
||||||
(* todo: check if all are valid, and get max valid pos *)
|
val state = getAlternationState acc
|
||||||
in
|
in
|
||||||
(ALTERNATION (acc, UNTESTED), UNTESTED)
|
(ALTERNATION (acc, state), state)
|
||||||
end
|
end
|
||||||
| (hd, _) :: tl =>
|
| (hd, _) :: tl =>
|
||||||
let
|
let
|
||||||
@@ -88,7 +110,7 @@ struct
|
|||||||
| CONCAT (lst, UNTESTED) => rebuildConcat (lst, chr, idx)
|
| CONCAT (lst, UNTESTED) => rebuildConcat (lst, chr, idx)
|
||||||
| CONCAT (_, state) => (nfa, state)
|
| CONCAT (_, state) => (nfa, state)
|
||||||
|
|
||||||
| ALTERNATION (lst, UNTESTED) => rebuildAlternation (lst, chr, idx)
|
| ALTERNATION (lst, UNTESTED) => rebuildAlternation (lst, chr, idx, [])
|
||||||
| ALTERNATION (_, state) => (nfa, state)
|
| ALTERNATION (_, state) => (nfa, state)
|
||||||
|
|
||||||
| _ => raise Fail "nfa.sml 69: not char literal or concat"
|
| _ => raise Fail "nfa.sml 69: not char literal or concat"
|
||||||
|
|||||||
Reference in New Issue
Block a user