|
1 | 1 | type Id = String
|
2 | 2 | --type Env = [(Id,Expr)]
|
3 | 3 |
|
4 |
| - |
5 |
| - |
6 |
| --- Remember that "|" = Alternative options |
7 |
| --- The expression in Haskell "deriving Show" = Print to console |
8 |
| --- Right is name of type being defined, left is what is in that type. |
9 |
| - |
10 |
| - |
11 |
| - |
12 | 4 | -- <program> ::=
|
13 | 5 | -- "program" <id> ":" <pars> "." (Skel program)
|
14 | 6 | -- Program type is defined = takes the following expressions of "Id" or "Pars"
|
@@ -108,48 +100,39 @@ data Op = OpAdd
|
108 | 100 |
|
109 | 101 |
|
110 | 102 |
|
111 |
| --- Abstract syntax tree expressions: |
| 103 | +-- Abstract syntax expression tests: |
112 | 104 |
|
113 | 105 | -- program printInt : string "int" and ExprInt of '42' int
|
114 |
| --- test = Program "printInt" ( Par ( ParId "Int" ( Struct ( StructExp ( Expression ( ExprInt 42 ) ) ) ) ) ) |
| 106 | +-- printInt = Program "printInt" ( Par ( ParId "Int" ( Struct ( StructExp ( Expression ( ExprInt 42 ) ) ) ) ) ) |
115 | 107 |
|
116 | 108 | -- program printString : func String "Hello World!".
|
117 |
| --- test2 = Program "printString" ( Par ( ParId "String" ( Struct ( StructExp ( Expression ( ExprString "Hello World!" ) ) ) ) ) ) |
| 109 | +-- printString = Program "printString" ( Par ( ParId "String" ( Struct ( StructExp ( Expression ( ExprString "Hello World!" ) ) ) ) ) ) |
118 | 110 |
|
119 |
| --- program assignBoolTrue : func Bool True. |
120 |
| --- test3 = Program "assignBoolTrue" ( Par ( ParId "Bool" ( Struct ( StructExp ( Expression ( ExprBool True ) ) ) ) ) ) |
| 111 | +-- program returnBoolTrue : func Bool True. |
| 112 | +-- returnBoolTrue = Program "returnBoolTrue" ( Par ( ParId "Bool" ( Struct ( StructExp ( Expression ( ExprBool True ) ) ) ) ) ) |
121 | 113 |
|
122 |
| --- program assignBoolTrue : func Bool True. |
123 |
| --- test4 = Program "assignBoolFalse" ( Par ( ParId "Bool" ( Struct ( StructExp ( Expression ( ExprBool False ) ) ) ) ) ) |
| 114 | +-- program returnBoolFalse : func Bool True. |
| 115 | +-- returnBoolFalse = Program "returnBoolFalse" ( Par ( ParId "Bool" ( Struct ( StructExp ( Expression ( ExprBool False ) ) ) ) ) ) |
124 | 116 |
|
125 | 117 | -- program opAddInts : func OpAdd ExprInt 10, OpAdd ExprInt 10
|
126 |
| ---test5 = Program "opAddInts" ( Par ( ParId "OpAdd" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 10) ) (OpAdd) (Expression (ExprInt 5) ) ) ) ) ) ) ) |
| 118 | +-- opAddInts = Program "opAddInts" ( Par ( ParId "OpAdd" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 10) ) (OpAdd) (Expression (ExprInt 5) ) ) ) ) ) ) ) |
127 | 119 |
|
128 | 120 | -- program opMinusInts : func OpMinus ExprInt 100, OpMinus ExprInt 35
|
129 |
| --- test6 = Program "opMinusInts" ( Par ( ParId "OpMinus" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpMinus) (Expression (ExprInt 35) ) ) ) ) ) ) ) |
| 121 | +-- opMinusInts = Program "opMinusInts" ( Par ( ParId "OpMinus" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpMinus) (Expression (ExprInt 35) ) ) ) ) ) ) ) |
130 | 122 |
|
131 | 123 | -- program opDivideInts : func OpMinus ExprInt 100, OpDivide ExprInt 35
|
132 |
| --- test7 = Program "opDivideInts" ( Par ( ParId "OpDivide" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpDivide) (Expression (ExprInt 35) ) ) ) ) ) ) ) |
| 124 | +opDivideInts = Program "opDivideInts" ( Par ( ParId "OpDivide" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpDivide) (Expression (ExprInt 35) ) ) ) ) ) ) ) |
133 | 125 |
|
134 |
| --- program printStringInts : func String "Hello World!" func Int 42. return |
135 |
| --- test8 = Program "printStringInts" ( Par ( ParId "ExprSeperator" ( Struct ( StructExp ( ExprSeperator ( ( ExprString "Hello World!" ) ) ( Expression ( ExprInt 42 ) ) ) ) ) ) ) |
| 126 | +-- program opMultiplyInts : func String "Hello World!" func Int 42. return |
| 127 | +-- opMultiplyInts = Program "opMultiplyInts" ( Par ( ParId "OpMultiply" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 235) ) (OpMultiply) (Expression (ExprInt 19) ) ) ) ) ) ) ) |
136 | 128 |
|
137 |
| --- program printStringBool : func String "Hello World!" func Int 42. return |
138 |
| --- test9 = Program "printStringBool" ( Par ( ParId "ExprSeperator" ( Struct ( StructExp ( ExprSeperator ( ( ExprString "Hello World!" ) ) ( Expression ( ExprBool True ) ) ) ) ) ) ) |
| 129 | +-- program printStringInts : func String "Hello World!" func Int 42. return |
| 130 | +-- printStringInts = Program "printStringInts" ( Par ( ParId "ExprSeperator" ( Struct ( StructExp ( ExprSeperator ( ( ExprString "Hello World!" ) ) ( Expression ( ExprInt 42 ) ) ) ) ) ) ) |
139 | 131 |
|
140 | 132 | -- program printStringBool : func String "Hello World!" func Int 42. return
|
141 |
| -test10 = Program "opMultiplyInts" ( Par ( ParId "OpMultiply" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 235) ) (OpMultiply) (Expression (ExprInt 19) ) ) ) ) ) ) ) |
142 |
| - |
143 |
| - |
144 |
| - |
145 |
| - |
146 |
| - |
147 |
| - |
148 |
| - |
149 |
| - |
150 |
| - |
| 133 | +-- printStringBool = Program "printStringBool" ( Par ( ParId "ExprSeperator" ( Struct ( StructExp ( ExprSeperator ( ( ExprString "Hello World!" ) ) ( Expression ( ExprBool True ) ) ) ) ) ) ) |
151 | 134 |
|
152 | 135 |
|
153 |
| --- Print out test program above using AST declarations |
154 |
| -main = print test10 |
| 136 | +-- Print out programs above using AST declarations |
| 137 | +main = print opDivideInts |
155 | 138 |
|
0 commit comments