aboutsummaryrefslogtreecommitdiff
path: root/Smurf.icl
diff options
context:
space:
mode:
authorCamil Staps2016-05-26 17:42:14 +0200
committerCamil Staps2016-05-26 17:42:14 +0200
commit9cd074db4da194630b223a988b25fd015b527d38 (patch)
treebbd5fd135d014e2ec1d4a14d3b735c7ef41dfbc3 /Smurf.icl
parentOverloading IO functions in step; POC derivation tree generation (diff)
Improved tree toString; reverse.smf
Diffstat (limited to 'Smurf.icl')
-rw-r--r--Smurf.icl11
1 files changed, 7 insertions, 4 deletions
diff --git a/Smurf.icl b/Smurf.icl
index 7223ce7..d4fbcb6 100644
--- a/Smurf.icl
+++ b/Smurf.icl
@@ -57,6 +57,9 @@ where
fromChar 'g' = Get
fromChar 'x' = Exec
+printList :: [a] -> String | toString a
+printList xs = "[" <+ concat (intersperse ":" (map (\s->'"' <+ s <+ '"') xs)) <+ "]"
+
instance zero State where zero = { stack = zero, store = zero }
instance zero ListIO where zero = {input=[], output=[]}
@@ -68,14 +71,14 @@ where
instance toString Transition
where
toString ((p1, ip1, st1) --> (ip2, op, st2))
- = "<" <+ simple 2 p1 <+ "," <+ st1 <+ "," <+ printToString ip1 <+ "> -> ("
- <+ printToString ip2 <+ "," <+ printToString op <+ "," <+ st2 <+ ")"
+ = "<" <+ simple 2 p1 <+ "," <+ st1 <+ "," <+ printList ip1 <+ "> -> ("
+ <+ printList ip2 <+ "," <+ printList op <+ "," <+ st2 <+ ")"
where
simple :: !Int !Program -> String
simple _ [] = "λ"
simple i pgm
- | i <= length pgm = concat $ intersperse ":" $ map toString pgm
- = concat $ intersperse ":" $ map toString (take i pgm)
+ | i >= length pgm = concat $ intersperse ":" $ map toString pgm
+ = simple i (take i pgm) +++ ":..."
instance toString DerivationTree
where