| 1 |
(* dump-output.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2005 |
| 4 |
* John Reppy (http://www.cs.uchicago.edu/~jhr) |
| 5 |
* Aaron Turon ([email protected]) |
| 6 |
* All rights reserved. |
| 7 |
* |
| 8 |
* Dump (to stderr) the complete DFA |
| 9 |
*) |
| 10 |
|
| 11 |
structure DumpOutput : OUTPUT = |
| 12 |
struct |
| 13 |
|
| 14 |
structure RE = RegExp |
| 15 |
structure LO = LexOutputSpec |
| 16 |
|
| 17 |
fun pr s = TextIO.output(TextIO.stdOut, s) |
| 18 |
fun prl ss = pr(concat ss) |
| 19 |
|
| 20 |
fun nameOf (LO.State{id, ...}) = "Q" ^ Int.toString id |
| 21 |
|
| 22 |
fun prState (s as LO.State{id, label, final, next, ...}) = let |
| 23 |
val name = (case final |
| 24 |
of [] => nameOf s |
| 25 |
| id::_ => concat[nameOf s, " (act ", Int.toString id, ")"] |
| 26 |
(* end case *)) |
| 27 |
fun prEdge (symSet, st) = prl[ |
| 28 |
" -- ", RE.toString (RE.mkSymSet symSet), " --> ", nameOf st, "\n" |
| 29 |
] |
| 30 |
fun prRE re = prl[" ", RE.toString re, "\n"] |
| 31 |
in |
| 32 |
prl[name, ": "(*, RE.toString label*), "\n"]; |
| 33 |
Vector.app prRE label; |
| 34 |
List.app prEdge (!next); |
| 35 |
pr "\n" |
| 36 |
end |
| 37 |
|
| 38 |
fun dumpDFA states = |
| 39 |
(List.app prState states; |
| 40 |
pr (Int.toString (List.length states)); |
| 41 |
pr " states\n\n") |
| 42 |
|
| 43 |
|
| 44 |
fun outSS (label, ss) = prl ["Start state: ", label, " => ", nameOf ss, "\n"] |
| 45 |
|
| 46 |
fun output (spec, _) = let |
| 47 |
val LO.Spec {dfa, startStates, ...} = spec |
| 48 |
in |
| 49 |
dumpDFA dfa; |
| 50 |
pr "\n"; |
| 51 |
List.app outSS startStates |
| 52 |
end |
| 53 |
|
| 54 |
end |