From 9cd074db4da194630b223a988b25fd015b527d38 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 26 May 2016 17:42:14 +0200 Subject: Improved tree toString; reverse.smf --- Smurf.icl | 11 +++++++---- reverse.smf | 1 + tree.icl | 18 +++++++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 reverse.smf 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) -- cgit v1.2.3