Matt Coles 8 anos atrás
pai
commit
db96312cee
4 arquivos alterados com 11 adições e 7 exclusões
  1. 2 2
      cw/main.c
  2. 2 1
      cw/simple.c
  3. 2 2
      cw/tests/twice.c
  4. 5 2
      cw/tests/var_maths.c

+ 2 - 2
cw/main.c

256
       if(debug)printf("I got: ");
256
       if(debug)printf("I got: ");
257
       if (var_bind->tree->type == CONSTANT) {
257
       if (var_bind->tree->type == CONSTANT) {
258
         if(debug){
258
         if(debug){
259
-          printf("CONSTANT\n");
260
           print_leaf(var_bind->tree, 0);
259
           print_leaf(var_bind->tree, 0);
261
         }
260
         }
262
       } else {
261
       } else {
315
       return ret_val;
314
       return ret_val;
316
     } else {
315
     } else {
317
       printf("HELP called a function with no return!!\n");
316
       printf("HELP called a function with no return!!\n");
317
+      exit(1);
318
     }
318
     }
319
   }
319
   }
320
   if (tree->type == IF) {
320
   if (tree->type == IF) {
376
     if (debug) printf("Adding %d and %d\n", lhs->value, rhs->value);
376
     if (debug) printf("Adding %d and %d\n", lhs->value, rhs->value);
377
     int result = lhs->value + rhs->value;
377
     int result = lhs->value + rhs->value;
378
     return anon_binding((NODE*) get_int_token(result));
378
     return anon_binding((NODE*) get_int_token(result));
379
-  }
379
+ }
380
   if (tree->type == '-') {
380
   if (tree->type == '-') {
381
     TOKEN* lhs = (TOKEN*) recursive_interpret(tree->left, env_ptr)->tree;
381
     TOKEN* lhs = (TOKEN*) recursive_interpret(tree->left, env_ptr)->tree;
382
     TOKEN* rhs = (TOKEN*) recursive_interpret(tree->right, env_ptr)->tree;
382
     TOKEN* rhs = (TOKEN*) recursive_interpret(tree->right, env_ptr)->tree;

+ 2 - 1
cw/simple.c

1
 int whammy(int a) {
1
 int whammy(int a) {
2
-  return a + 5;
2
+  int x = a;
3
+  return x + 5;
3
 }
4
 }
4
 
5
 
5
 function twice(function f) {
6
 function twice(function f) {

+ 2 - 2
cw/tests/twice.c

9
 }
9
 }
10
 
10
 
11
 int main() {
11
 int main() {
12
-  x = twice(whammy);
12
+  doublewhammy = twice(whammy);
13
 
13
 
14
-  return x(2);
14
+  return doublewhammy(2);
15
 }
15
 }
16
 
16
 

+ 5 - 2
cw/tests/var_maths.c

1
-/* ##answer: 11*/
1
+/* ##answer: 30*/
2
 int main() {
2
 int main() {
3
   int x = 5;
3
   int x = 5;
4
+  int y = x - 4;
5
+  int z = 10 - x;
6
+  int w = x % z;
4
 
7
 
5
-  return x + 3 * 2;
8
+  return x*x + z / (w + y);
6
 }
9
 }