File tree 8 files changed +108
-3
lines changed
8 files changed +108
-3
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ data Expr = ExprInt Int
86
86
| ExprBool Bool
87
87
| ExprAssignment Id Exprs
88
88
| ExprRaise Id Exprs
89
- | ExprCacth Exprs Id Id Exprs
89
+ | ExprCatch Exprs Id Id Exprs
90
90
| ExprOp Exprs Op Exprs
91
91
| ExprGroup Exprs
92
92
deriving Show
@@ -126,7 +126,13 @@ data Op = OpAdd
126
126
-- test5 = Program "opAddInts" ( Par ( ParId "OpAdd" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 10) ) (OpAdd) (Expression (ExprInt 5) ) ) ) ) ) ) )
127
127
128
128
-- program opMinusInts : func OpMinus ExprInt 100, OpAdd ExprInt 35
129
- test6 = Program " opMinusInts" ( Par ( ParId " OpMinus" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100 ) ) (OpMinus ) (Expression (ExprInt 35 ) ) ) ) ) ) ) )
129
+ -- test6 = Program "opMinusInts" ( Par ( ParId "OpMinus" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpMinus) (Expression (ExprInt 35) ) ) ) ) ) ) )
130
+
131
+ -- program opDivideInts : func OpMinus ExprInt 100, OpAdd ExprInt 35
132
+ -- test7 = Program "opDivideInts" ( Par ( ParId "OpDivide" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 100) ) (OpDivide) (Expression (ExprInt 35) ) ) ) ) ) ) )
133
+
134
+ -- program opDivideInts : func OpMinus ExprInt 100, OpAdd ExprInt 35
135
+ -- test8 = Program "strComp" ( Par ( ParId "StructComp" ( Struct ( StructExp ( Expression ( ExprOp (Expression (ExprInt 20) ) (OpLess) (Expression (ExprInt 80) ) ) ) ) ) ) )
130
136
131
137
132
138
@@ -137,5 +143,5 @@ test6 = Program "opMinusInts" ( Par ( ParId "OpMinus" ( Struct ( StructExp ( Exp
137
143
138
144
139
145
-- Print out test program above using AST declarations
140
- main = print test6
146
+ main = print test8
141
147
Original file line number Diff line number Diff line change
1
+ .class public test6
2
+ .super java/lang/Object
3
+
4
+ ; standard initializer
5
+ ; default constructor
6
+
7
+ .method public <init> ()V
8
+ aload_0 ; push this
9
+ invokespecial java/lang/Object/<init>()V ; call super
10
+ return
11
+ .end method
12
+
13
+ .method public static main ([Ljava/lang/String; )V
14
+
15
+ ; allocate stack big enough to hold 3 items
16
+ .limit stack 3
17
+ .limit locals 2 ; should be fine with 2
18
+
19
+ ; push java.lang.System.out (type PrintStream)
20
+ getstatic java/lang/System/out Ljava/io/PrintStream;
21
+ ; push ints to be printed
22
+
23
+ ldc 100 ; load int
24
+ ldc 35 ; load int
25
+ isub ; subtract int
26
+ istore_0 ; store result in variable
27
+ iload 0 ; load variable, push to top of stack
28
+ ; invoke println
29
+ invokevirtual java/io/PrintStream/println(I )V ; int print result
30
+ ; terminate main
31
+ return
32
+
33
+ .end method
Original file line number Diff line number Diff line change
1
+ .class public test7
2
+ .super java/lang/Object
3
+
4
+ ; standard initializer
5
+ ; default constructor
6
+
7
+ .method public <init> ()V
8
+ aload_0 ; push this
9
+ invokespecial java/lang/Object/<init>()V ; call super
10
+ return
11
+ .end method
12
+
13
+ .method public static main ([Ljava/lang/String; )V
14
+
15
+ ; allocate stack big enough to hold 3 items
16
+ .limit stack 3
17
+ .limit locals 2 ; should be fine with 2
18
+
19
+ ; push java.lang.System.out (type PrintStream)
20
+ getstatic java/lang/System/out Ljava/io/PrintStream;
21
+ ; push ints to be printed
22
+
23
+ ldc 100 ; load int
24
+ ldc 35 ; load int
25
+ idiv ; divide int
26
+ istore_0 ; store result in variable
27
+ iload 0 ; load variable, push to top of stack
28
+ ; invoke println
29
+ invokevirtual java/io/PrintStream/println(I )V ; int print result
30
+ ; terminate main
31
+ return
32
+
33
+ .end method
Original file line number Diff line number Diff line change
1
+ .class public test7
2
+ .super java/lang/Object
3
+
4
+ ; standard initializer
5
+ ; default constructor
6
+
7
+ .method public <init> ()V
8
+ aload_0 ; push this
9
+ invokespecial java/lang/Object/<init>()V ; call super
10
+ return
11
+ .end method
12
+
13
+ .method public static main ([Ljava/lang/String; )V
14
+
15
+ ; allocate stack big enough to hold 3 items
16
+ .limit stack 3
17
+ .limit locals 2 ; should be fine with 2
18
+
19
+ ; push java.lang.System.out (type PrintStream)
20
+ getstatic java/lang/System/out Ljava/io/PrintStream;
21
+ ; push ints to be printed
22
+
23
+ ldc 20 ; load int
24
+ ldc 80 ; load int
25
+ if_icmple ; if less than int
26
+ istore_0 ; store result in variable
27
+ iload 0 ; load variable, push to top of stack
28
+ ; invoke println
29
+ invokevirtual java/io/PrintStream/println(I )V ; int print result
30
+ ; terminate main
31
+ return
32
+
33
+ .end method
You can’t perform that action at this time.
0 commit comments