1-- ----------------------------------------------------------------------------- 2-- 3-- Info.hs, part of Alex 4-- 5-- (c) Simon Marlow 2003 6-- 7-- Generate a human-readable rendition of the state machine. 8-- 9-- ----------------------------------------------------------------------------} 10 11module Info (infoDFA) where 12 13import AbsSyn 14import qualified Map 15import qualified Data.IntMap as IntMap 16import Util 17 18-- ----------------------------------------------------------------------------- 19-- Generate a human readable dump of the state machine 20 21infoDFA :: Int -> String -> DFA SNum Code -> ShowS 22infoDFA _ func_nm dfa 23 = str "Scanner : " . str func_nm . nl 24 . str "States : " . shows (length dfa_list) . nl 25 . nl . infoDFA' 26 where 27 dfa_list = Map.toAscList (dfa_states dfa) 28 29 infoDFA' = interleave_shows nl (map infoStateN dfa_list) 30 31 infoStateN (i,s) = str "State " . shows i . nl . infoState s 32 33 infoState :: State SNum Code -> ShowS 34 infoState (State accs out) 35 = foldr (.) id (map infoAccept accs) 36 . infoArr out . nl 37 38 infoArr out 39 = char '\t' . interleave_shows (str "\n\t") 40 (map infoTransition (IntMap.toAscList out)) 41 42 infoAccept (Acc p act lctx rctx) 43 = str "\tAccept" . paren (shows p) . space 44 . outputLCtx lctx . space 45 . showRCtx rctx 46 . (case act of 47 Nothing -> id 48 Just code -> str " { " . str code . str " }") 49 . nl 50 51 infoTransition (char',state) 52 = str (ljustify 8 (show char')) 53 . str " -> " 54 . shows state 55 56 outputLCtx Nothing 57 = id 58 outputLCtx (Just set) 59 = paren (show set ++) . char '^' 60 61 -- outputArr arr 62 -- = str "Array.array " . shows (bounds arr) . space 63 -- . shows (assocs arr) 64