aboutsummaryrefslogtreecommitdiff
path: root/Smurf.icl
diff options
context:
space:
mode:
Diffstat (limited to 'Smurf.icl')
-rw-r--r--Smurf.icl105
1 files changed, 104 insertions, 1 deletions
diff --git a/Smurf.icl b/Smurf.icl
index d4fbcb6..9afefb8 100644
--- a/Smurf.icl
+++ b/Smurf.icl
@@ -18,6 +18,7 @@ import GenEq
import GenPrint
import SmurfParse
+import LaTeX
derive gEq Stm
derive gPrint (,)
@@ -81,8 +82,110 @@ where
= simple i (take i pgm) +++ ":..."
instance toString DerivationTree
+where toString ts = concat $ intersperse "\n" $ map toString $ reverse ts
+
+instance toLaTeX Stm
+where
+ toLaTeX (Push s) = List [Command "StmPush" [], Raw "~", sToLaTeX s]
+ toLaTeX Input = Command "StmInput" []
+ toLaTeX Output = Command "StmOutput" []
+ toLaTeX Cat = Command "StmCat" []
+ toLaTeX Head = Command "StmHead" []
+ toLaTeX Tail = Command "StmTail" []
+ toLaTeX Quotify = Command "StmQuotify" []
+ toLaTeX Put = Command "StmPut" []
+ toLaTeX Get = Command "StmGet" []
+ toLaTeX Exec = Command "StmExec" []
+
+instance toLaTeX Program
+where
+ toLaTeX [] = Command "lambda" []
+ toLaTeX pgm = List $ intersperse (Text ":") (map toLaTeX pgm)
+
+instance toLaTeX String where toLaTeX s = Text s
+
+instance toLaTeX Store
+where
+ toLaTeX [] = Command "emptyset" []
+ toLaTeX ass
+ = List
+ ([Command "{" []] ++
+ intersperse (Raw ",") (map assToLaTeX ass) ++
+ [Command "}" []])
+ where
+ assToLaTeX :: (String,String) -> LaTeX
+ assToLaTeX (var,val)
+ = List
+ [ sToLaTeX var
+ , Command "mapsto" []
+ , sToLaTeX val
+ ]
+
+instance toLaTeX State
+where
+ toLaTeX {stack,store}
+ = List
+ [ Command "left" []
+ , Raw "("
+ , stackToLaTeX stack
+ , Raw ","
+ , toLaTeX store
+ , Command "right" []
+ , Raw ")"
+ ]
+
+instance toLaTeX Transition
+where
+ toLaTeX ((p1,ip1,st1) --> (ip2,op,st2))
+ = Command "trans"
+ [ toLaTeX p1
+ , stackToLaTeX ip1
+ , toLaTeX st1
+ , stackToLaTeX ip2
+ , stackToLaTeX op
+ , toLaTeX st2
+ ]
+
+stackToLaTeX :: [String] -> LaTeX
+stackToLaTeX ss
+ = List $ intersperse (Text ":") (map sToLaTeX ss ++ [Command "Nil" []])
+
+sToLaTeX :: String -> LaTeX
+sToLaTeX s = Command "texttt" [List [Raw "\"", Text s, Raw "\""]]
+
+instance toLaTeX DerivationTree
where
- toString ts = concat $ intersperse "\n" $ map toString $ reverse ts
+ toLaTeX ts = toL ts
+ where
+ toL :: DerivationTree -> LaTeX
+ toL [] = List []
+ toL [t]
+ = List
+ [ Command "axjustifies" []
+ , toLaTeX t
+ , Command "using" [Command "rlambdans" []]
+ ]
+ toL [t=:((p1,_,_)-->_):ts]
+ = List
+ [ Command "[" []
+ , toL ts
+ , Command "]" []
+ , Command "justifies" []
+ , toLaTeX t
+ , Command "using" [Command rule []]
+ ]
+ where
+ rule = case p1 of
+ [Push _:_] = "rpushns"
+ [Input:_] = "rinputns"
+ [Output:_] = "routputns"
+ [Cat:_] = "rcatns"
+ [Head:_] = "rheadns"
+ [Tail:_] = "rtailns"
+ [Quotify:_] = "rquotifyns"
+ [Put:_] = "rputns"
+ [Get:_] = "rgetns"
+ [Exec:_] = "rexecns"
run :: !Program State io (IO io) -> (Maybe State, io)
run prog st io iofuncs