aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2016-03-30 13:18:02 +0200
committerCamil Staps2016-03-30 13:18:02 +0200
commite452daceb395c4ea68bc67bd70f355f59867618b (patch)
treebf235fd22db5d4880685e83fc18dc6e6332f56e0
parentOverloaded state, more boolean ops, unaliased Var (diff)
Parentheses for Stm toString
-rw-r--r--While.icl9
-rw-r--r--test.icl1
2 files changed, 8 insertions, 2 deletions
diff --git a/While.icl b/While.icl
index efa1c92..6d34a26 100644
--- a/While.icl
+++ b/While.icl
@@ -107,8 +107,13 @@ where
toString Skip = "skip"
toString (s1 :. s2) = s1 <+ "; " <+ s2
toString (v := a) = v <+ ":=" <+ a
- toString (If b s1 s2) = "if " <+ b <+ " then " <+ s1 <+ " else " <+ s2
- toString (While b s) = "while " <+ b <+ " do " <+ s <+ " done"
+ toString (While b s) = "while " <+ b <+ " do " <+ parens s
+ toString (If b s1 s2)
+ = "if " <+ b <+ " then " <+ parens s1 <+ " else " <+ parens s2
+
+parens :: Stm -> String
+parens (s1 :. s2) = "(" <+ s1 <+ "; " <+ s2 <+ ")"
+parens stm = toString stm
instance toString Var where toString (Var v) = {v}
diff --git a/test.icl b/test.icl
index fe689fc..7d5a118 100644
--- a/test.icl
+++ b/test.icl
@@ -25,6 +25,7 @@ Start :: Int // Value of z after execution of sqrt in st
Start = eval NS sqrt st z
//Start = toString (seq sqrt st) // Derivation sequence of sqrt in st
//Start = toString (tree sqrt st) // Derivation tree of sqrt in st
+//Start = toString sqrt // The statement itself
where
st :: Char -> Int
st 'x' = 9