]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/ExpressionParsing.scl
Merge commit 'bf75fd9'
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / ExpressionParsing.scl
1 import "Prelude"\r
2 \r
3 data Exp = Exp String\r
4 \r
5 expToString :: Exp -> String\r
6 expToString (Exp s) = s\r
7 \r
8 instance Additive Exp where\r
9     zero = Exp "0"\r
10     Exp a + Exp b = Exp ("(" + a + " + " + b + ")")\r
11 \r
12 instance Ring Exp where\r
13     one = Exp "1"\r
14     neg (Exp a) = Exp ("(-" + a + ")")\r
15     Exp a * Exp b = Exp ("(" + a + " * " + b + ")")\r
16     Exp a - Exp b = Exp ("(" + a + " - " + b + ")")\r
17     fromInteger x = Exp (show x)\r
18     \r
19 a = Exp "a"\r
20 b = Exp "b"\r
21 c = Exp "c"\r
22 d = Exp "d"\r
23 e = Exp "e"\r
24 \r
25 main = expToString (a + b*c + d*e)\r
26 --\r
27 ((a + (b * c)) + (d * e))