aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Smurf.icl11
-rw-r--r--reverse.smf1
-rw-r--r--tree.icl18
3 files changed, 23 insertions, 7 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
diff --git a/reverse.smf b/reverse.smf
new file mode 100644
index 0000000..29bc6e3
--- /dev/null
+++ b/reverse.smf
@@ -0,0 +1 @@
+"+"i+""p""gtg""gt"i"p"\"\"p\"i\"gh\"o\"g+\"o\"p\"i\"gt\"i\"p\"\\\"+\\\"\\\"\\\"p\"\"i\"gq+\"tg\"+\"i\"gq+\"\\\"i\\\"p\"+\"o\"gq+\"\\\"o\\\"p\"+\"\"gq+\"\"g+\"\"p\"o\"gq\"o\"+\"+\"pgx"""p"\"+\"\"\"p""i"gq+"tg"+"i"gq+"\"i\"p\"\""+""gq+""g+""p"""+""i"g+pgx
diff --git a/tree.icl b/tree.icl
index 82e0ae9..c7cdc77 100644
--- a/tree.icl
+++ b/tree.icl
@@ -10,7 +10,19 @@ import System.CommandLine, System.GetOpt
import Smurf
import SmurfParse
-Start = toString devtree
+Start w
+# (_,f,w) = fopen "reverse.smf" FReadText w
+# (pgm,f) = readFile f
+# (ok,w) = fclose f w
+# (Just pgm) = parse [c \\ c <-: pgm]
+= toString (devtree pgm)
where
- (Just devtree) = tree pgm zero zero listIO
- (Just pgm) = parse ['"abc""123"+o']
+ devtree pgm = fromJust (tree pgm zero {zero & input = ["reverse"]} listIO)
+
+ readFile :: !*File -> *(!String, !*File)
+ readFile f
+ # (end,f) = fend f
+ | end = ("", f)
+ # (s,f) = freadline f
+ # (ss,f) = readFile f
+ = (s +++ ss, f)