aboutsummaryrefslogtreecommitdiff
path: root/While.icl
diff options
context:
space:
mode:
authorCamil Staps2016-03-30 13:25:31 +0200
committerCamil Staps2016-03-30 13:25:31 +0200
commitb6766f35de8f7a36cae5e53fd02794f2b4359cdb (patch)
tree9c43e11bfd6deeb6e420a1a61ec57f64e59318c8 /While.icl
parentParentheses for Stm toString (diff)
Parentheses for ArithExpr/BoolExpr toString
Diffstat (limited to 'While.icl')
-rw-r--r--While.icl11
1 files changed, 5 insertions, 6 deletions
diff --git a/While.icl b/While.icl
index 6d34a26..9b8efae 100644
--- a/While.icl
+++ b/While.icl
@@ -89,7 +89,7 @@ instance toString ArithExpr
where
toString (a1 + a2) = a1 <+ "+" <+ a2
toString (a1 - a2) = a1 <+ "-" <+ a2
- toString (a1 * a2) = a1 <+ "*" <+ a2
+ toString (a1 * a2) = "(" <+ a1 <+ "*" <+ a2 <+ ")"
instance toString BoolExpr
where
@@ -98,9 +98,9 @@ where
toString (a1 >= a2) = a1 <+ ">=" <+ a2
toString (a1 < a2) = a1 <+ "<" <+ a2
toString (a1 > a2) = a1 <+ ">" <+ a2
- toString (~ b) = "~" <+ toString b
- toString (b1 /\ b2) = b1 <+ "/\\" <+ b2
- toString (b1 \/ b2) = b1 <+ "\\/" <+ b2
+ toString (~ b) = "~(" <+ toString b <+ ")"
+ toString (b1 /\ b2) = "(" <+ b1 <+ "/\\" <+ b2 <+ ")"
+ toString (b1 \/ b2) = "(" <+ b1 <+ "\\/" <+ b2 <+ ")"
instance toString Stm
where
@@ -108,8 +108,7 @@ where
toString (s1 :. s2) = s1 <+ "; " <+ s2
toString (v := a) = v <+ ":=" <+ a
toString (While b s) = "while " <+ b <+ " do " <+ parens s
- toString (If b s1 s2)
- = "if " <+ b <+ " then " <+ parens s1 <+ " else " <+ parens s2
+ toString (If b s1 s2) = "if "<+b<+" then "<+parens s1<+" else "<+parens s2
parens :: Stm -> String
parens (s1 :. s2) = "(" <+ s1 <+ "; " <+ s2 <+ ")"