diff options
author | Camil Staps | 2016-03-30 13:25:31 +0200 |
---|---|---|
committer | Camil Staps | 2016-03-30 13:25:31 +0200 |
commit | b6766f35de8f7a36cae5e53fd02794f2b4359cdb (patch) | |
tree | 9c43e11bfd6deeb6e420a1a61ec57f64e59318c8 | |
parent | Parentheses for Stm toString (diff) |
Parentheses for ArithExpr/BoolExpr toString
-rw-r--r-- | While.icl | 11 |
1 files changed, 5 insertions, 6 deletions
@@ -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 <+ ")" |