]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ExpressionParsing.scl
Automatic execution of SCL tests in Maven
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / ExpressionParsing.scl
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ExpressionParsing.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ExpressionParsing.scl
new file mode 100644 (file)
index 0000000..6719bf9
--- /dev/null
@@ -0,0 +1,27 @@
+import "Prelude"\r
+\r
+data Exp = Exp String\r
+\r
+expToString :: Exp -> String\r
+expToString (Exp s) = s\r
+\r
+instance Additive Exp where\r
+    zero = Exp "0"\r
+    Exp a + Exp b = Exp ("(" + a + " + " + b + ")")\r
+\r
+instance Ring Exp where\r
+    one = Exp "1"\r
+    neg (Exp a) = Exp ("(-" + a + ")")\r
+    Exp a * Exp b = Exp ("(" + a + " * " + b + ")")\r
+    Exp a - Exp b = Exp ("(" + a + " - " + b + ")")\r
+    fromInteger x = Exp (show x)\r
+    \r
+a = Exp "a"\r
+b = Exp "b"\r
+c = Exp "c"\r
+d = Exp "d"\r
+e = Exp "e"\r
+\r
+main = expToString (a + b*c + d*e)\r
+--\r
+((a + (b * c)) + (d * e)) 
\ No newline at end of file