3 Commits 890548e796 ... a059405928

Autor SHA1 Mensaje Fecha
  Matt Coles a059405928 woohoo hace 8 años
  Matt Coles f4f00926dc merging hace 8 años
  Matt Coles db96312cee blah hace 8 años
Se han modificado 25 ficheros con 1795 adiciones y 1352 borrados
  1. 2 2
      cw/main.c
  2. 10 0
      cw/simple.c
  3. 21 0
      cw/simple.c.orig
  4. 21 0
      cw/simple_BACKUP_23755.c
  5. 21 0
      cw/simple_BACKUP_24791.c
  6. 15 0
      cw/simple_BASE_23755.c
  7. 15 0
      cw/simple_BASE_24791.c
  8. 16 0
      cw/simple_LOCAL_23755.c
  9. 16 0
      cw/simple_LOCAL_24791.c
  10. 8 0
      cw/simple_REMOTE_23755.c
  11. 8 0
      cw/simple_REMOTE_24791.c
  12. 2 2
      cw/tests/twice.c
  13. 5 2
      cw/tests/var_maths.c
  14. 978 1027
      tac/C.tab.c
  15. 47 61
      tac/C.tab.h
  16. 138 124
      tac/lex.yy.c
  17. 11 6
      tac/list.c
  18. 4 4
      tac/list.h
  19. 188 95
      tac/main.c
  20. 54 0
      tac/mips.asm
  21. 155 0
      tac/recurse.asm
  22. 19 0
      tac/recursion.c
  23. 9 12
      tac/simple.c
  24. 24 15
      tac/test.asm
  25. 8 2
      tac/types.h

+ 2 - 2
cw/main.c

@@ -255,7 +255,6 @@ BIND* recursive_interpret(NODE *tree, ENV *env_ptr) {
255 255
       if(debug)printf("I got: ");
256 256
       if (var_bind->tree->type == CONSTANT) {
257 257
         if(debug){
258
-          printf("CONSTANT\n");
259 258
           print_leaf(var_bind->tree, 0);
260 259
         }
261 260
       } else {
@@ -310,6 +309,7 @@ BIND* recursive_interpret(NODE *tree, ENV *env_ptr) {
310 309
       return ret_val;
311 310
     } else {
312 311
       printf("HELP called a function with no return!!\n");
312
+      exit(1);
313 313
     }
314 314
   }
315 315
   if (tree->type == IF) {
@@ -371,7 +371,7 @@ BIND* recursive_interpret(NODE *tree, ENV *env_ptr) {
371 371
     if (debug) printf("Adding %d and %d\n", lhs->value, rhs->value);
372 372
     int result = lhs->value + rhs->value;
373 373
     return anon_binding((NODE*) get_int_token(result));
374
-  }
374
+ }
375 375
   if (tree->type == '-') {
376 376
     TOKEN* lhs = (TOKEN*) recursive_interpret(tree->left, env_ptr)->tree;
377 377
     TOKEN* rhs = (TOKEN*) recursive_interpret(tree->right, env_ptr)->tree;

+ 10 - 0
cw/simple.c

@@ -1,3 +1,13 @@
1
+int whammy(int a) {
2
+  int x = a;
3
+  return x + 5;
4
+}
5
+
6
+function twice(function f) {
7
+  int g(int x) { return f(f(x)); }
8
+  return g;
9
+}
10
+
1 11
 int main() {
2 12
   int b = 4;
3 13
 

+ 21 - 0
cw/simple.c.orig

@@ -0,0 +1,21 @@
1
+<<<<<<< HEAD
2
+int whammy(int a) {
3
+  int x = a;
4
+  return x + 5;
5
+}
6
+
7
+function twice(function f) {
8
+  int g(int x) { return f(f(x)); }
9
+  return g;
10
+}
11
+
12
+=======
13
+>>>>>>> 890548e7968c2e8be77eb6170819538f116397bd
14
+int main() {
15
+  int b = 4;
16
+
17
+  int a = b();
18
+
19
+  return x;
20
+}
21
+

+ 21 - 0
cw/simple_BACKUP_23755.c

@@ -0,0 +1,21 @@
1
+<<<<<<< HEAD
2
+int whammy(int a) {
3
+  int x = a;
4
+  return x + 5;
5
+}
6
+
7
+function twice(function f) {
8
+  int g(int x) { return f(f(x)); }
9
+  return g;
10
+}
11
+
12
+=======
13
+>>>>>>> 890548e7968c2e8be77eb6170819538f116397bd
14
+int main() {
15
+  int b = 4;
16
+
17
+  int a = b();
18
+
19
+  return x;
20
+}
21
+

+ 21 - 0
cw/simple_BACKUP_24791.c

@@ -0,0 +1,21 @@
1
+<<<<<<< HEAD
2
+int whammy(int a) {
3
+  int x = a;
4
+  return x + 5;
5
+}
6
+
7
+function twice(function f) {
8
+  int g(int x) { return f(f(x)); }
9
+  return g;
10
+}
11
+
12
+=======
13
+>>>>>>> 890548e7968c2e8be77eb6170819538f116397bd
14
+int main() {
15
+  int b = 4;
16
+
17
+  int a = b();
18
+
19
+  return x;
20
+}
21
+

+ 15 - 0
cw/simple_BASE_23755.c

@@ -0,0 +1,15 @@
1
+int whammy(int a) {
2
+  return a + 5;
3
+}
4
+
5
+function twice(function f) {
6
+  int g(int x) { return f(f(x)); }
7
+  return g;
8
+}
9
+
10
+int main() {
11
+  x = twice(whammy);
12
+
13
+  return x(2);
14
+}
15
+

+ 15 - 0
cw/simple_BASE_24791.c

@@ -0,0 +1,15 @@
1
+int whammy(int a) {
2
+  return a + 5;
3
+}
4
+
5
+function twice(function f) {
6
+  int g(int x) { return f(f(x)); }
7
+  return g;
8
+}
9
+
10
+int main() {
11
+  x = twice(whammy);
12
+
13
+  return x(2);
14
+}
15
+

+ 16 - 0
cw/simple_LOCAL_23755.c

@@ -0,0 +1,16 @@
1
+int whammy(int a) {
2
+  int x = a;
3
+  return x + 5;
4
+}
5
+
6
+function twice(function f) {
7
+  int g(int x) { return f(f(x)); }
8
+  return g;
9
+}
10
+
11
+int main() {
12
+  x = twice(whammy);
13
+
14
+  return x(2);
15
+}
16
+

+ 16 - 0
cw/simple_LOCAL_24791.c

@@ -0,0 +1,16 @@
1
+int whammy(int a) {
2
+  int x = a;
3
+  return x + 5;
4
+}
5
+
6
+function twice(function f) {
7
+  int g(int x) { return f(f(x)); }
8
+  return g;
9
+}
10
+
11
+int main() {
12
+  x = twice(whammy);
13
+
14
+  return x(2);
15
+}
16
+

+ 8 - 0
cw/simple_REMOTE_23755.c

@@ -0,0 +1,8 @@
1
+int main() {
2
+  int b = 4;
3
+
4
+  int a = b();
5
+
6
+  return x;
7
+}
8
+

+ 8 - 0
cw/simple_REMOTE_24791.c

@@ -0,0 +1,8 @@
1
+int main() {
2
+  int b = 4;
3
+
4
+  int a = b();
5
+
6
+  return x;
7
+}
8
+

+ 2 - 2
cw/tests/twice.c

@@ -9,8 +9,8 @@ function twice(function f) {
9 9
 }
10 10
 
11 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,6 +1,9 @@
1
-/* ##answer: 11*/
1
+/* ##answer: 30*/
2 2
 int main() {
3 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
 }

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 978 - 1027
tac/C.tab.c


+ 47 - 61
tac/C.tab.h

@@ -1,14 +1,13 @@
1
-/* A Bison parser, made by GNU Bison 2.3.  */
1
+/* A Bison parser, made by GNU Bison 3.0.4.  */
2 2
 
3
-/* Skeleton interface for Bison's Yacc-like parsers in C
3
+/* Bison interface for Yacc-like parsers in C
4 4
 
5
-   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6
-   Free Software Foundation, Inc.
5
+   Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
7 6
 
8
-   This program is free software; you can redistribute it and/or modify
7
+   This program is free software: you can redistribute it and/or modify
9 8
    it under the terms of the GNU General Public License as published by
10
-   the Free Software Foundation; either version 2, or (at your option)
11
-   any later version.
9
+   the Free Software Foundation, either version 3 of the License, or
10
+   (at your option) any later version.
12 11
 
13 12
    This program is distributed in the hope that it will be useful,
14 13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,9 +15,7 @@
16 15
    GNU General Public License for more details.
17 16
 
18 17
    You should have received a copy of the GNU General Public License
19
-   along with this program; if not, write to the Free Software
20
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
-   Boston, MA 02110-1301, USA.  */
18
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22 19
 
23 20
 /* As a special exception, you may create a larger work that contains
24 21
    part or all of the Bison parser skeleton and distribute that work
@@ -33,65 +30,54 @@
33 30
    This special exception was added by the Free Software Foundation in
34 31
    version 2.2 of Bison.  */
35 32
 
36
-/* Tokens.  */
33
+#ifndef YY_YY_C_TAB_H_INCLUDED
34
+# define YY_YY_C_TAB_H_INCLUDED
35
+/* Debug traces.  */
36
+#ifndef YYDEBUG
37
+# define YYDEBUG 1
38
+#endif
39
+#if YYDEBUG
40
+extern int yydebug;
41
+#endif
42
+
43
+/* Token type.  */
37 44
 #ifndef YYTOKENTYPE
38 45
 # define YYTOKENTYPE
39
-   /* Put the tokens into the symbol table, so that GDB and other debuggers
40
-      know about them.  */
41
-   enum yytokentype {
42
-     IDENTIFIER = 258,
43
-     CONSTANT = 259,
44
-     STRING_LITERAL = 260,
45
-     LE_OP = 261,
46
-     GE_OP = 262,
47
-     EQ_OP = 263,
48
-     NE_OP = 264,
49
-     EXTERN = 265,
50
-     AUTO = 266,
51
-     INT = 267,
52
-     VOID = 268,
53
-     FUNCTION = 269,
54
-     APPLY = 270,
55
-     LEAF = 271,
56
-     IF = 272,
57
-     ELSE = 273,
58
-     WHILE = 274,
59
-     CONTINUE = 275,
60
-     BREAK = 276,
61
-     RETURN = 277
62
-   };
46
+  enum yytokentype
47
+  {
48
+    IDENTIFIER = 258,
49
+    CONSTANT = 259,
50
+    STRING_LITERAL = 260,
51
+    LE_OP = 261,
52
+    GE_OP = 262,
53
+    EQ_OP = 263,
54
+    NE_OP = 264,
55
+    EXTERN = 265,
56
+    AUTO = 266,
57
+    INT = 267,
58
+    VOID = 268,
59
+    FUNCTION = 269,
60
+    APPLY = 270,
61
+    LEAF = 271,
62
+    IF = 272,
63
+    ELSE = 273,
64
+    WHILE = 274,
65
+    CONTINUE = 275,
66
+    BREAK = 276,
67
+    RETURN = 277
68
+  };
63 69
 #endif
64
-/* Tokens.  */
65
-#define IDENTIFIER 258
66
-#define CONSTANT 259
67
-#define STRING_LITERAL 260
68
-#define LE_OP 261
69
-#define GE_OP 262
70
-#define EQ_OP 263
71
-#define NE_OP 264
72
-#define EXTERN 265
73
-#define AUTO 266
74
-#define INT 267
75
-#define VOID 268
76
-#define FUNCTION 269
77
-#define APPLY 270
78
-#define LEAF 271
79
-#define IF 272
80
-#define ELSE 273
81
-#define WHILE 274
82
-#define CONTINUE 275
83
-#define BREAK 276
84
-#define RETURN 277
85
-
86
-
87
-
88 70
 
71
+/* Value type.  */
89 72
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
90 73
 typedef int YYSTYPE;
91
-# define yystype YYSTYPE /* obsolescent; will be withdrawn */
92
-# define YYSTYPE_IS_DECLARED 1
93 74
 # define YYSTYPE_IS_TRIVIAL 1
75
+# define YYSTYPE_IS_DECLARED 1
94 76
 #endif
95 77
 
78
+
96 79
 extern YYSTYPE yylval;
97 80
 
81
+int yyparse (void);
82
+
83
+#endif /* !YY_YY_C_TAB_H_INCLUDED  */

+ 138 - 124
tac/lex.yy.c

@@ -7,8 +7,8 @@
7 7
 
8 8
 #define FLEX_SCANNER
9 9
 #define YY_FLEX_MAJOR_VERSION 2
10
-#define YY_FLEX_MINOR_VERSION 5
11
-#define YY_FLEX_SUBMINOR_VERSION 35
10
+#define YY_FLEX_MINOR_VERSION 6
11
+#define YY_FLEX_SUBMINOR_VERSION 1
12 12
 #if YY_FLEX_SUBMINOR_VERSION > 0
13 13
 #define FLEX_BETA
14 14
 #endif
@@ -46,7 +46,6 @@ typedef int16_t flex_int16_t;
46 46
 typedef uint16_t flex_uint16_t;
47 47
 typedef int32_t flex_int32_t;
48 48
 typedef uint32_t flex_uint32_t;
49
-typedef uint64_t flex_uint64_t;
50 49
 #else
51 50
 typedef signed char flex_int8_t;
52 51
 typedef short int flex_int16_t;
@@ -54,7 +53,6 @@ typedef int flex_int32_t;
54 53
 typedef unsigned char flex_uint8_t; 
55 54
 typedef unsigned short int flex_uint16_t;
56 55
 typedef unsigned int flex_uint32_t;
57
-#endif /* ! C99 */
58 56
 
59 57
 /* Limits of integral types. */
60 58
 #ifndef INT8_MIN
@@ -85,27 +83,17 @@ typedef unsigned int flex_uint32_t;
85 83
 #define UINT32_MAX             (4294967295U)
86 84
 #endif
87 85
 
88
-#endif /* ! FLEXINT_H */
89
-
90
-#ifdef __cplusplus
91
-
92
-/* The "const" storage-class-modifier is valid. */
93
-#define YY_USE_CONST
94
-
95
-#else	/* ! __cplusplus */
96
-
97
-/* C99 requires __STDC__ to be defined as 1. */
98
-#if defined (__STDC__)
99
-
100
-#define YY_USE_CONST
86
+#endif /* ! C99 */
101 87
 
102
-#endif	/* defined (__STDC__) */
103
-#endif	/* ! __cplusplus */
88
+#endif /* ! FLEXINT_H */
104 89
 
105
-#ifdef YY_USE_CONST
90
+/* TODO: this is always defined, so inline it */
106 91
 #define yyconst const
92
+
93
+#if defined(__GNUC__) && __GNUC__ >= 3
94
+#define yynoreturn __attribute__((__noreturn__))
107 95
 #else
108
-#define yyconst
96
+#define yynoreturn
109 97
 #endif
110 98
 
111 99
 /* Returned upon end-of-file. */
@@ -141,7 +129,15 @@ typedef unsigned int flex_uint32_t;
141 129
 
142 130
 /* Size of default input buffer. */
143 131
 #ifndef YY_BUF_SIZE
132
+#ifdef __ia64__
133
+/* On IA-64, the buffer size is 16k, not 8k.
134
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
135
+ * Ditto for the __ia64__ case accordingly.
136
+ */
137
+#define YY_BUF_SIZE 32768
138
+#else
144 139
 #define YY_BUF_SIZE 16384
140
+#endif /* __ia64__ */
145 141
 #endif
146 142
 
147 143
 /* The state buf must be large enough to hold one state per character in the main buffer.
@@ -158,7 +154,7 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
158 154
 typedef size_t yy_size_t;
159 155
 #endif
160 156
 
161
-extern yy_size_t yyleng;
157
+extern int yyleng;
162 158
 
163 159
 extern FILE *yyin, *yyout;
164 160
 
@@ -167,6 +163,7 @@ extern FILE *yyin, *yyout;
167 163
 #define EOB_ACT_LAST_MATCH 2
168 164
 
169 165
     #define YY_LESS_LINENO(n)
166
+    #define YY_LINENO_REWIND_TO(ptr)
170 167
     
171 168
 /* Return all but the first "n" matched characters back to the input stream. */
172 169
 #define yyless(n) \
@@ -196,12 +193,12 @@ struct yy_buffer_state
196 193
 	/* Size of input buffer in bytes, not including room for EOB
197 194
 	 * characters.
198 195
 	 */
199
-	yy_size_t yy_buf_size;
196
+	int yy_buf_size;
200 197
 
201 198
 	/* Number of characters read into yy_ch_buf, not including EOB
202 199
 	 * characters.
203 200
 	 */
204
-	yy_size_t yy_n_chars;
201
+	int yy_n_chars;
205 202
 
206 203
 	/* Whether we "own" the buffer - i.e., we know we created it,
207 204
 	 * and can realloc() it to grow it, and should free() it to
@@ -224,7 +221,7 @@ struct yy_buffer_state
224 221
 
225 222
     int yy_bs_lineno; /**< The line count. */
226 223
     int yy_bs_column; /**< The column count. */
227
-    
224
+
228 225
 	/* Whether to try to fill the input buffer when we reach the
229 226
 	 * end of it.
230 227
 	 */
@@ -252,7 +249,7 @@ struct yy_buffer_state
252 249
 /* Stack of input buffers. */
253 250
 static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
254 251
 static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
255
-static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
252
+static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
256 253
 
257 254
 /* We provide macros for accessing buffer states in case in the
258 255
  * future we want to put the buffer states in a more general
@@ -271,11 +268,11 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
271 268
 
272 269
 /* yy_hold_char holds the character lost when yytext is formed. */
273 270
 static char yy_hold_char;
274
-static yy_size_t yy_n_chars;		/* number of characters read into yy_ch_buf */
275
-yy_size_t yyleng;
271
+static int yy_n_chars;		/* number of characters read into yy_ch_buf */
272
+int yyleng;
276 273
 
277 274
 /* Points to current character in buffer. */
278
-static char *yy_c_buf_p = (char *) 0;
275
+static char *yy_c_buf_p = NULL;
279 276
 static int yy_init = 0;		/* whether we need to initialize */
280 277
 static int yy_start = 0;	/* start state number */
281 278
 
@@ -300,7 +297,7 @@ static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file  );
300 297
 
301 298
 YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size  );
302 299
 YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str  );
303
-YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len  );
300
+YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len  );
304 301
 
305 302
 void *yyalloc (yy_size_t  );
306 303
 void *yyrealloc (void *,yy_size_t  );
@@ -334,7 +331,7 @@ void yyfree (void *  );
334 331
 
335 332
 typedef unsigned char YY_CHAR;
336 333
 
337
-FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
334
+FILE *yyin = NULL, *yyout = NULL;
338 335
 
339 336
 typedef int yy_state_type;
340 337
 
@@ -343,19 +340,22 @@ extern int yylineno;
343 340
 int yylineno = 1;
344 341
 
345 342
 extern char *yytext;
343
+#ifdef yytext_ptr
344
+#undef yytext_ptr
345
+#endif
346 346
 #define yytext_ptr yytext
347 347
 
348 348
 static yy_state_type yy_get_previous_state (void );
349 349
 static yy_state_type yy_try_NUL_trans (yy_state_type current_state  );
350 350
 static int yy_get_next_buffer (void );
351
-static void yy_fatal_error (yyconst char msg[]  );
351
+static void yynoreturn yy_fatal_error (yyconst char* msg  );
352 352
 
353 353
 /* Done after the current pattern has been matched and before the
354 354
  * corresponding action - sets up yytext.
355 355
  */
356 356
 #define YY_DO_BEFORE_ACTION \
357 357
 	(yytext_ptr) = yy_bp; \
358
-	yyleng = (yy_size_t) (yy_cp - yy_bp); \
358
+	yyleng = (int) (yy_cp - yy_bp); \
359 359
 	(yy_hold_char) = *yy_cp; \
360 360
 	*yy_cp = '\0'; \
361 361
 	(yy_c_buf_p) = yy_cp;
@@ -384,7 +384,7 @@ static yyconst flex_int16_t yy_accept[98] =
384 384
 
385 385
     } ;
386 386
 
387
-static yyconst flex_int32_t yy_ec[256] =
387
+static yyconst YY_CHAR yy_ec[256] =
388 388
     {   0,
389 389
         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
390 390
         2,    2,    1,    1,    1,    1,    1,    1,    1,    1,
@@ -416,7 +416,7 @@ static yyconst flex_int32_t yy_ec[256] =
416 416
         1,    1,    1,    1,    1
417 417
     } ;
418 418
 
419
-static yyconst flex_int32_t yy_meta[46] =
419
+static yyconst YY_CHAR yy_meta[46] =
420 420
     {   0,
421 421
         1,    1,    1,    1,    1,    1,    2,    1,    1,    1,
422 422
         1,    1,    1,    1,    3,    1,    1,    1,    1,    1,
@@ -425,7 +425,7 @@ static yyconst flex_int32_t yy_meta[46] =
425 425
         3,    3,    3,    1,    1
426 426
     } ;
427 427
 
428
-static yyconst flex_int16_t yy_base[101] =
428
+static yyconst flex_uint16_t yy_base[101] =
429 429
     {   0,
430 430
         0,    0,  130,  131,  131,  131,  110,   41,  131,  104,
431 431
       131,  131,  131,  131,  131,  131,  117,   32,  131,  131,
@@ -455,7 +455,7 @@ static yyconst flex_int16_t yy_def[101] =
455 455
 
456 456
     } ;
457 457
 
458
-static yyconst flex_int16_t yy_nxt[177] =
458
+static yyconst flex_uint16_t yy_nxt[177] =
459 459
     {   0,
460 460
         4,    5,    6,    7,    8,    9,   10,   11,   12,   13,
461 461
        14,   15,   16,   17,   18,   19,   20,   21,   22,   23,
@@ -567,19 +567,19 @@ void yyset_extra (YY_EXTRA_TYPE user_defined  );
567 567
 
568 568
 FILE *yyget_in (void );
569 569
 
570
-void yyset_in  (FILE * in_str  );
570
+void yyset_in  (FILE * _in_str  );
571 571
 
572 572
 FILE *yyget_out (void );
573 573
 
574
-void yyset_out  (FILE * out_str  );
574
+void yyset_out  (FILE * _out_str  );
575 575
 
576
-yy_size_t yyget_leng (void );
576
+			int yyget_leng (void );
577 577
 
578 578
 char *yyget_text (void );
579 579
 
580 580
 int yyget_lineno (void );
581 581
 
582
-void yyset_lineno (int line_number  );
582
+void yyset_lineno (int _line_number  );
583 583
 
584 584
 /* Macros after this point can all be overridden by user definitions in
585 585
  * section 1.
@@ -593,8 +593,12 @@ extern int yywrap (void );
593 593
 #endif
594 594
 #endif
595 595
 
596
+#ifndef YY_NO_UNPUT
597
+    
596 598
     static void yyunput (int c,char *buf_ptr  );
597 599
     
600
+#endif
601
+
598 602
 #ifndef yytext_ptr
599 603
 static void yy_flex_strncpy (char *,yyconst char *,int );
600 604
 #endif
@@ -615,7 +619,12 @@ static int input (void );
615 619
 
616 620
 /* Amount of stuff to slurp up with each read. */
617 621
 #ifndef YY_READ_BUF_SIZE
622
+#ifdef __ia64__
623
+/* On IA-64, the buffer size is 16k, not 8k */
624
+#define YY_READ_BUF_SIZE 16384
625
+#else
618 626
 #define YY_READ_BUF_SIZE 8192
627
+#endif /* __ia64__ */
619 628
 #endif
620 629
 
621 630
 /* Copy whatever the last rule matched to the standard output. */
@@ -623,7 +632,7 @@ static int input (void );
623 632
 /* This used to be an fputs(), but since the string might contain NUL's,
624 633
  * we now use fwrite().
625 634
  */
626
-#define ECHO fwrite( yytext, yyleng, 1, yyout )
635
+#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
627 636
 #endif
628 637
 
629 638
 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
@@ -634,7 +643,7 @@ static int input (void );
634 643
 	if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
635 644
 		{ \
636 645
 		int c = '*'; \
637
-		yy_size_t n; \
646
+		size_t n; \
638 647
 		for ( n = 0; n < max_size && \
639 648
 			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
640 649
 			buf[n] = (char) c; \
@@ -647,7 +656,7 @@ static int input (void );
647 656
 	else \
648 657
 		{ \
649 658
 		errno=0; \
650
-		while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
659
+		while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
651 660
 			{ \
652 661
 			if( errno != EINTR) \
653 662
 				{ \
@@ -702,7 +711,7 @@ extern int yylex (void);
702 711
 
703 712
 /* Code executed at the end of each rule. */
704 713
 #ifndef YY_BREAK
705
-#define YY_BREAK break;
714
+#define YY_BREAK /*LINTED*/break;
706 715
 #endif
707 716
 
708 717
 #define YY_RULE_SETUP \
@@ -712,14 +721,10 @@ extern int yylex (void);
712 721
  */
713 722
 YY_DECL
714 723
 {
715
-	register yy_state_type yy_current_state;
716
-	register char *yy_cp, *yy_bp;
717
-	register int yy_act;
724
+	yy_state_type yy_current_state;
725
+	char *yy_cp, *yy_bp;
726
+	int yy_act;
718 727
     
719
-#line 28 "C.flex"
720
-
721
-#line 722 "lex.yy.c"
722
-
723 728
 	if ( !(yy_init) )
724 729
 		{
725 730
 		(yy_init) = 1;
@@ -746,7 +751,12 @@ YY_DECL
746 751
 		yy_load_buffer_state( );
747 752
 		}
748 753
 
749
-	while ( 1 )		/* loops until end-of-file is reached */
754
+	{
755
+#line 28 "C.flex"
756
+
757
+#line 758 "lex.yy.c"
758
+
759
+	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
750 760
 		{
751 761
 		yy_cp = (yy_c_buf_p);
752 762
 
@@ -762,7 +772,7 @@ YY_DECL
762 772
 yy_match:
763 773
 		do
764 774
 			{
765
-			register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
775
+			YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
766 776
 			if ( yy_accept[yy_current_state] )
767 777
 				{
768 778
 				(yy_last_accepting_state) = yy_current_state;
@@ -774,7 +784,7 @@ yy_match:
774 784
 				if ( yy_current_state >= 98 )
775 785
 					yy_c = yy_meta[(unsigned int) yy_c];
776 786
 				}
777
-			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
787
+			yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
778 788
 			++yy_cp;
779 789
 			}
780 790
 		while ( yy_base[yy_current_state] != 131 );
@@ -1001,7 +1011,7 @@ YY_RULE_SETUP
1001 1011
 #line 76 "C.flex"
1002 1012
 ECHO;
1003 1013
 	YY_BREAK
1004
-#line 1005 "lex.yy.c"
1014
+#line 1015 "lex.yy.c"
1005 1015
 case YY_STATE_EOF(INITIAL):
1006 1016
 	yyterminate();
1007 1017
 
@@ -1132,6 +1142,7 @@ case YY_STATE_EOF(INITIAL):
1132 1142
 			"fatal flex scanner internal error--no action found" );
1133 1143
 	} /* end of action switch */
1134 1144
 		} /* end of scanning one token */
1145
+	} /* end of user's declarations */
1135 1146
 } /* end of yylex */
1136 1147
 
1137 1148
 /* yy_get_next_buffer - try to read in a new buffer
@@ -1143,9 +1154,9 @@ case YY_STATE_EOF(INITIAL):
1143 1154
  */
1144 1155
 static int yy_get_next_buffer (void)
1145 1156
 {
1146
-    	register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1147
-	register char *source = (yytext_ptr);
1148
-	register int number_to_move, i;
1157
+    	char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1158
+	char *source = (yytext_ptr);
1159
+	int number_to_move, i;
1149 1160
 	int ret_val;
1150 1161
 
1151 1162
 	if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
@@ -1174,7 +1185,7 @@ static int yy_get_next_buffer (void)
1174 1185
 	/* Try to read more data. */
1175 1186
 
1176 1187
 	/* First move last chars to start of buffer. */
1177
-	number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1;
1188
+	number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
1178 1189
 
1179 1190
 	for ( i = 0; i < number_to_move; ++i )
1180 1191
 		*(dest++) = *(source++);
@@ -1187,21 +1198,21 @@ static int yy_get_next_buffer (void)
1187 1198
 
1188 1199
 	else
1189 1200
 		{
1190
-			yy_size_t num_to_read =
1201
+			int num_to_read =
1191 1202
 			YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1192 1203
 
1193 1204
 		while ( num_to_read <= 0 )
1194 1205
 			{ /* Not enough room in the buffer - grow it. */
1195 1206
 
1196 1207
 			/* just a shorter name for the current buffer */
1197
-			YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
1208
+			YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1198 1209
 
1199 1210
 			int yy_c_buf_p_offset =
1200 1211
 				(int) ((yy_c_buf_p) - b->yy_ch_buf);
1201 1212
 
1202 1213
 			if ( b->yy_is_our_buffer )
1203 1214
 				{
1204
-				yy_size_t new_size = b->yy_buf_size * 2;
1215
+				int new_size = b->yy_buf_size * 2;
1205 1216
 
1206 1217
 				if ( new_size <= 0 )
1207 1218
 					b->yy_buf_size += b->yy_buf_size / 8;
@@ -1214,7 +1225,7 @@ static int yy_get_next_buffer (void)
1214 1225
 				}
1215 1226
 			else
1216 1227
 				/* Can't grow it, we don't own it. */
1217
-				b->yy_ch_buf = 0;
1228
+				b->yy_ch_buf = NULL;
1218 1229
 
1219 1230
 			if ( ! b->yy_ch_buf )
1220 1231
 				YY_FATAL_ERROR(
@@ -1256,9 +1267,9 @@ static int yy_get_next_buffer (void)
1256 1267
 	else
1257 1268
 		ret_val = EOB_ACT_CONTINUE_SCAN;
1258 1269
 
1259
-	if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1270
+	if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1260 1271
 		/* Extend the array by 50%, plus the number we really need. */
1261
-		yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1272
+		int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1262 1273
 		YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size  );
1263 1274
 		if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1264 1275
 			YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
@@ -1277,14 +1288,14 @@ static int yy_get_next_buffer (void)
1277 1288
 
1278 1289
     static yy_state_type yy_get_previous_state (void)
1279 1290
 {
1280
-	register yy_state_type yy_current_state;
1281
-	register char *yy_cp;
1291
+	yy_state_type yy_current_state;
1292
+	char *yy_cp;
1282 1293
     
1283 1294
 	yy_current_state = (yy_start);
1284 1295
 
1285 1296
 	for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
1286 1297
 		{
1287
-		register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1298
+		YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1288 1299
 		if ( yy_accept[yy_current_state] )
1289 1300
 			{
1290 1301
 			(yy_last_accepting_state) = yy_current_state;
@@ -1296,7 +1307,7 @@ static int yy_get_next_buffer (void)
1296 1307
 			if ( yy_current_state >= 98 )
1297 1308
 				yy_c = yy_meta[(unsigned int) yy_c];
1298 1309
 			}
1299
-		yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1310
+		yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
1300 1311
 		}
1301 1312
 
1302 1313
 	return yy_current_state;
@@ -1309,10 +1320,10 @@ static int yy_get_next_buffer (void)
1309 1320
  */
1310 1321
     static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state )
1311 1322
 {
1312
-	register int yy_is_jam;
1313
-    	register char *yy_cp = (yy_c_buf_p);
1323
+	int yy_is_jam;
1324
+    	char *yy_cp = (yy_c_buf_p);
1314 1325
 
1315
-	register YY_CHAR yy_c = 1;
1326
+	YY_CHAR yy_c = 1;
1316 1327
 	if ( yy_accept[yy_current_state] )
1317 1328
 		{
1318 1329
 		(yy_last_accepting_state) = yy_current_state;
@@ -1324,15 +1335,17 @@ static int yy_get_next_buffer (void)
1324 1335
 		if ( yy_current_state >= 98 )
1325 1336
 			yy_c = yy_meta[(unsigned int) yy_c];
1326 1337
 		}
1327
-	yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1338
+	yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
1328 1339
 	yy_is_jam = (yy_current_state == 97);
1329 1340
 
1330
-	return yy_is_jam ? 0 : yy_current_state;
1341
+		return yy_is_jam ? 0 : yy_current_state;
1331 1342
 }
1332 1343
 
1333
-    static void yyunput (int c, register char * yy_bp )
1344
+#ifndef YY_NO_UNPUT
1345
+
1346
+    static void yyunput (int c, char * yy_bp )
1334 1347
 {
1335
-	register char *yy_cp;
1348
+	char *yy_cp;
1336 1349
     
1337 1350
     yy_cp = (yy_c_buf_p);
1338 1351
 
@@ -1342,10 +1355,10 @@ static int yy_get_next_buffer (void)
1342 1355
 	if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1343 1356
 		{ /* need to shift things up to make room */
1344 1357
 		/* +2 for EOB chars. */
1345
-		register yy_size_t number_to_move = (yy_n_chars) + 2;
1346
-		register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
1358
+		int number_to_move = (yy_n_chars) + 2;
1359
+		char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
1347 1360
 					YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
1348
-		register char *source =
1361
+		char *source =
1349 1362
 				&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
1350 1363
 
1351 1364
 		while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
@@ -1354,7 +1367,7 @@ static int yy_get_next_buffer (void)
1354 1367
 		yy_cp += (int) (dest - source);
1355 1368
 		yy_bp += (int) (dest - source);
1356 1369
 		YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
1357
-			(yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
1370
+			(yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
1358 1371
 
1359 1372
 		if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1360 1373
 			YY_FATAL_ERROR( "flex scanner push-back overflow" );
@@ -1367,6 +1380,8 @@ static int yy_get_next_buffer (void)
1367 1380
 	(yy_c_buf_p) = yy_cp;
1368 1381
 }
1369 1382
 
1383
+#endif
1384
+
1370 1385
 #ifndef YY_NO_INPUT
1371 1386
 #ifdef __cplusplus
1372 1387
     static int yyinput (void)
@@ -1391,7 +1406,7 @@ static int yy_get_next_buffer (void)
1391 1406
 
1392 1407
 		else
1393 1408
 			{ /* need more input */
1394
-			yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
1409
+			int offset = (yy_c_buf_p) - (yytext_ptr);
1395 1410
 			++(yy_c_buf_p);
1396 1411
 
1397 1412
 			switch ( yy_get_next_buffer(  ) )
@@ -1516,7 +1531,7 @@ static void yy_load_buffer_state  (void)
1516 1531
 	if ( ! b )
1517 1532
 		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1518 1533
 
1519
-	b->yy_buf_size = size;
1534
+	b->yy_buf_size = (yy_size_t)size;
1520 1535
 
1521 1536
 	/* yy_ch_buf has to be 2 characters longer than the size given because
1522 1537
 	 * we need to put in 2 end-of-buffer characters.
@@ -1551,10 +1566,6 @@ static void yy_load_buffer_state  (void)
1551 1566
 	yyfree((void *) b  );
1552 1567
 }
1553 1568
 
1554
-#ifndef __cplusplus
1555
-extern int isatty (int );
1556
-#endif /* __cplusplus */
1557
-    
1558 1569
 /* Initializes or reinitializes a buffer.
1559 1570
  * This function is sometimes called more than once on the same buffer,
1560 1571
  * such as during a yyrestart() or at EOF.
@@ -1667,7 +1678,7 @@ void yypop_buffer_state (void)
1667 1678
  */
1668 1679
 static void yyensure_buffer_stack (void)
1669 1680
 {
1670
-	yy_size_t num_to_alloc;
1681
+	int num_to_alloc;
1671 1682
     
1672 1683
 	if (!(yy_buffer_stack)) {
1673 1684
 
@@ -1675,15 +1686,15 @@ static void yyensure_buffer_stack (void)
1675 1686
 		 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1676 1687
 		 * immediate realloc on the next call.
1677 1688
          */
1678
-		num_to_alloc = 1;
1689
+      num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
1679 1690
 		(yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
1680 1691
 								(num_to_alloc * sizeof(struct yy_buffer_state*)
1681 1692
 								);
1682 1693
 		if ( ! (yy_buffer_stack) )
1683 1694
 			YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1684
-								  
1695
+
1685 1696
 		memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1686
-				
1697
+
1687 1698
 		(yy_buffer_stack_max) = num_to_alloc;
1688 1699
 		(yy_buffer_stack_top) = 0;
1689 1700
 		return;
@@ -1692,7 +1703,7 @@ static void yyensure_buffer_stack (void)
1692 1703
 	if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1693 1704
 
1694 1705
 		/* Increase the buffer to prepare for a possible push. */
1695
-		int grow_size = 8 /* arbitrary grow size */;
1706
+		yy_size_t grow_size = 8 /* arbitrary grow size */;
1696 1707
 
1697 1708
 		num_to_alloc = (yy_buffer_stack_max) + grow_size;
1698 1709
 		(yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
@@ -1712,7 +1723,7 @@ static void yyensure_buffer_stack (void)
1712 1723
  * @param base the character buffer
1713 1724
  * @param size the size in bytes of the character buffer
1714 1725
  * 
1715
- * @return the newly allocated buffer state object. 
1726
+ * @return the newly allocated buffer state object.
1716 1727
  */
1717 1728
 YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1718 1729
 {
@@ -1722,7 +1733,7 @@ YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1722 1733
 	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
1723 1734
 	     base[size-1] != YY_END_OF_BUFFER_CHAR )
1724 1735
 		/* They forgot to leave room for the EOB's. */
1725
-		return 0;
1736
+		return NULL;
1726 1737
 
1727 1738
 	b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state )  );
1728 1739
 	if ( ! b )
@@ -1731,7 +1742,7 @@ YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1731 1742
 	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
1732 1743
 	b->yy_buf_pos = b->yy_ch_buf = base;
1733 1744
 	b->yy_is_our_buffer = 0;
1734
-	b->yy_input_file = 0;
1745
+	b->yy_input_file = NULL;
1735 1746
 	b->yy_n_chars = b->yy_buf_size;
1736 1747
 	b->yy_is_interactive = 0;
1737 1748
 	b->yy_at_bol = 1;
@@ -1754,24 +1765,25 @@ YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1754 1765
 YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
1755 1766
 {
1756 1767
     
1757
-	return yy_scan_bytes(yystr,strlen(yystr) );
1768
+	return yy_scan_bytes(yystr,(int) strlen(yystr) );
1758 1769
 }
1759 1770
 
1760 1771
 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
1761 1772
  * scan from a @e copy of @a bytes.
1762
- * @param bytes the byte buffer to scan
1763
- * @param len the number of bytes in the buffer pointed to by @a bytes.
1773
+ * @param yybytes the byte buffer to scan
1774
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
1764 1775
  * 
1765 1776
  * @return the newly allocated buffer state object.
1766 1777
  */
1767
-YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, yy_size_t  _yybytes_len )
1778
+YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, int  _yybytes_len )
1768 1779
 {
1769 1780
 	YY_BUFFER_STATE b;
1770 1781
 	char *buf;
1771
-	yy_size_t n, i;
1782
+	yy_size_t n;
1783
+	int i;
1772 1784
     
1773 1785
 	/* Get memory for full buffer, including space for trailing EOB's. */
1774
-	n = _yybytes_len + 2;
1786
+	n = (yy_size_t) (_yybytes_len + 2);
1775 1787
 	buf = (char *) yyalloc(n  );
1776 1788
 	if ( ! buf )
1777 1789
 		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
@@ -1797,9 +1809,9 @@ YY_BUFFER_STATE yy_scan_bytes  (yyconst char * yybytes, yy_size_t  _yybytes_len
1797 1809
 #define YY_EXIT_FAILURE 2
1798 1810
 #endif
1799 1811
 
1800
-static void yy_fatal_error (yyconst char* msg )
1812
+static void yynoreturn yy_fatal_error (yyconst char* msg )
1801 1813
 {
1802
-    	(void) fprintf( stderr, "%s\n", msg );
1814
+			(void) fprintf( stderr, "%s\n", msg );
1803 1815
 	exit( YY_EXIT_FAILURE );
1804 1816
 }
1805 1817
 
@@ -1827,7 +1839,7 @@ static void yy_fatal_error (yyconst char* msg )
1827 1839
  */
1828 1840
 int yyget_lineno  (void)
1829 1841
 {
1830
-        
1842
+    
1831 1843
     return yylineno;
1832 1844
 }
1833 1845
 
@@ -1850,7 +1862,7 @@ FILE *yyget_out  (void)
1850 1862
 /** Get the length of the current token.
1851 1863
  * 
1852 1864
  */
1853
-yy_size_t yyget_leng  (void)
1865
+int yyget_leng  (void)
1854 1866
 {
1855 1867
         return yyleng;
1856 1868
 }
@@ -1865,29 +1877,29 @@ char *yyget_text  (void)
1865 1877
 }
1866 1878
 
1867 1879
 /** Set the current line number.
1868
- * @param line_number
1880
+ * @param _line_number line number
1869 1881
  * 
1870 1882
  */
1871
-void yyset_lineno (int  line_number )
1883
+void yyset_lineno (int  _line_number )
1872 1884
 {
1873 1885
     
1874
-    yylineno = line_number;
1886
+    yylineno = _line_number;
1875 1887
 }
1876 1888
 
1877 1889
 /** Set the input stream. This does not discard the current
1878 1890
  * input buffer.
1879
- * @param in_str A readable stream.
1891
+ * @param _in_str A readable stream.
1880 1892
  * 
1881 1893
  * @see yy_switch_to_buffer
1882 1894
  */
1883
-void yyset_in (FILE *  in_str )
1895
+void yyset_in (FILE *  _in_str )
1884 1896
 {
1885
-        yyin = in_str ;
1897
+        yyin = _in_str ;
1886 1898
 }
1887 1899
 
1888
-void yyset_out (FILE *  out_str )
1900
+void yyset_out (FILE *  _out_str )
1889 1901
 {
1890
-        yyout = out_str ;
1902
+        yyout = _out_str ;
1891 1903
 }
1892 1904
 
1893 1905
 int yyget_debug  (void)
@@ -1895,9 +1907,9 @@ int yyget_debug  (void)
1895 1907
         return yy_flex_debug;
1896 1908
 }
1897 1909
 
1898
-void yyset_debug (int  bdebug )
1910
+void yyset_debug (int  _bdebug )
1899 1911
 {
1900
-        yy_flex_debug = bdebug ;
1912
+        yy_flex_debug = _bdebug ;
1901 1913
 }
1902 1914
 
1903 1915
 static int yy_init_globals (void)
@@ -1906,10 +1918,10 @@ static int yy_init_globals (void)
1906 1918
      * This function is called from yylex_destroy(), so don't allocate here.
1907 1919
      */
1908 1920
 
1909
-    (yy_buffer_stack) = 0;
1921
+    (yy_buffer_stack) = NULL;
1910 1922
     (yy_buffer_stack_top) = 0;
1911 1923
     (yy_buffer_stack_max) = 0;
1912
-    (yy_c_buf_p) = (char *) 0;
1924
+    (yy_c_buf_p) = NULL;
1913 1925
     (yy_init) = 0;
1914 1926
     (yy_start) = 0;
1915 1927
 
@@ -1918,8 +1930,8 @@ static int yy_init_globals (void)
1918 1930
     yyin = stdin;
1919 1931
     yyout = stdout;
1920 1932
 #else
1921
-    yyin = (FILE *) 0;
1922
-    yyout = (FILE *) 0;
1933
+    yyin = NULL;
1934
+    yyout = NULL;
1923 1935
 #endif
1924 1936
 
1925 1937
     /* For future reference: Set errno on error, since we are called by
@@ -1957,7 +1969,8 @@ int yylex_destroy  (void)
1957 1969
 #ifndef yytext_ptr
1958 1970
 static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
1959 1971
 {
1960
-	register int i;
1972
+		
1973
+	int i;
1961 1974
 	for ( i = 0; i < n; ++i )
1962 1975
 		s1[i] = s2[i];
1963 1976
 }
@@ -1966,7 +1979,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
1966 1979
 #ifdef YY_NEED_STRLEN
1967 1980
 static int yy_flex_strlen (yyconst char * s )
1968 1981
 {
1969
-	register int n;
1982
+	int n;
1970 1983
 	for ( n = 0; s[n]; ++n )
1971 1984
 		;
1972 1985
 
@@ -1976,11 +1989,12 @@ static int yy_flex_strlen (yyconst char * s )
1976 1989
 
1977 1990
 void *yyalloc (yy_size_t  size )
1978 1991
 {
1979
-	return (void *) malloc( size );
1992
+			return malloc(size);
1980 1993
 }
1981 1994
 
1982 1995
 void *yyrealloc  (void * ptr, yy_size_t  size )
1983 1996
 {
1997
+		
1984 1998
 	/* The cast to (char *) in the following accommodates both
1985 1999
 	 * implementations that use char* generic pointers, and those
1986 2000
 	 * that use void* generic pointers.  It works with the latter
@@ -1988,12 +2002,12 @@ void *yyrealloc  (void * ptr, yy_size_t  size )
1988 2002
 	 * any pointer type to void*, and deal with argument conversions
1989 2003
 	 * as though doing an assignment.
1990 2004
 	 */
1991
-	return (void *) realloc( (char *) ptr, size );
2005
+	return realloc(ptr, size);
1992 2006
 }
1993 2007
 
1994 2008
 void yyfree (void * ptr )
1995 2009
 {
1996
-	free( (char *) ptr );	/* see yyrealloc() for (char *) cast */
2010
+			free( (char *) ptr );	/* see yyrealloc() for (char *) cast */
1997 2011
 }
1998 2012
 
1999 2013
 #define YYTABLES_NAME "yytables"

+ 11 - 6
tac/list.c

@@ -51,7 +51,7 @@ BLIST* create_list(BIND *binding, BLIST *second) {
51 51
   return head;
52 52
 }
53 53
 
54
-ENV* create_new_function_env(ENV* env) {
54
+ENV* create_new_function_env(ENV* env, ENV* prenv) {
55 55
   ENV* n_env = (ENV*) malloc(sizeof(ENV));
56 56
   if (n_env == NULL) {
57 57
     perror("Failed to create environment");
@@ -59,18 +59,23 @@ ENV* create_new_function_env(ENV* env) {
59 59
   }
60 60
   n_env->bindings = NULL;
61 61
   n_env->parent = env;
62
+  n_env->counter = 0;
63
+  n_env->param_counter = 0;
64
+  n_env->arg_counter = 0;
65
+  n_env->previous = prenv;
62 66
   return n_env;
63 67
 }
64 68
 
65
-BIND* create_binding(char* name, NODE* tree, ENV* env_ptr) {
69
+BIND* create_binding(TOKEN* name, int sp_offset, ENV* env_ptr) {
66 70
   BIND* n_bind = (BIND*) malloc(sizeof(BIND));
67 71
   if (n_bind == NULL) {
68 72
     perror("Failed to create binding: ");
69 73
     exit(1);
70 74
   }
71 75
   n_bind->name = name;
72
-  n_bind->tree = tree;
76
+  n_bind->env_offset = sp_offset;
73 77
   n_bind->env  = env_ptr;
78
+  n_bind->is_saved = 0;
74 79
 
75 80
   return n_bind;
76 81
 }
@@ -83,10 +88,10 @@ void append_list(BLIST *head, BIND *binding) {
83 88
   ptr->next = create_list(binding, NULL);
84 89
 }
85 90
 
86
-BIND* find_name_in_list(char* name, BLIST *head) {
91
+BIND* find_name_in_list(TOKEN* name, BLIST *head) {
87 92
   BLIST *ptr = head;
88 93
   while (ptr != NULL) {
89
-    if (strcmp(ptr->binding->name, name) == 0) {
94
+    if (name == ptr->binding->name) {
90 95
       return ptr->binding;
91 96
     }
92 97
     ptr = ptr->next;
@@ -94,7 +99,7 @@ BIND* find_name_in_list(char* name, BLIST *head) {
94 99
   return NULL;
95 100
 }
96 101
 
97
-  BIND* find_name_in_env(char* name, ENV* env) {
102
+  BIND* find_name_in_env(TOKEN* name, ENV* env) {
98 103
     BIND* ptr = NULL;
99 104
     ENV* env_ptr = env;
100 105
     while (env_ptr != NULL && 

+ 4 - 4
tac/list.h

@@ -3,11 +3,11 @@
3 3
 #include "types.h"
4 4
 
5 5
 BLIST* create_list(BIND*, BLIST*);
6
-BIND* create_binding(char*, NODE*, ENV*);
6
+BIND* create_binding(TOKEN*, int, ENV*);
7 7
 void append_list(BLIST*, BIND*);
8
-BIND* find_name_in_list(char*, BLIST*);
9
-BIND* find_name_in_env(char*, ENV*);
10
-ENV* create_new_function_env(ENV*);
8
+BIND* find_name_in_list(TOKEN*, BLIST*);
9
+BIND* find_name_in_env(TOKEN*, ENV*);
10
+ENV* create_new_function_env(ENV*, ENV*);
11 11
 void add_tac(TLIST*, int, TOKEN*, TOKEN*, TOKEN*);
12 12
 TAC_T* create_tac(int, TOKEN*, TOKEN*, TOKEN*);
13 13
 TLIST* new_tac_list(TAC_T*, TLIST*);

+ 188 - 95
tac/main.c

@@ -7,6 +7,8 @@
7 7
 #include "types.h"
8 8
 #include "list.h"
9 9
 
10
+int debug = 0;
11
+
10 12
 extern TOKEN* lookup_token(char*);
11 13
 
12 14
 TOKEN* gen_tmp(void) {
@@ -119,26 +121,30 @@ char* stok(TOKEN* tok) {
119 121
   return tok->lexeme;
120 122
 }
121 123
 
124
+void print_tac_el(TAC_T* elem) {
125
+    int op = elem->op;
126
+    if (op == '=') printf("%s := %s\n", stok(elem->dst), stok(elem->src));
127
+    if (op=='+' || op=='-' || op=='*' || op=='/' || op =='%') printf("%s := %s %c %s\n", stok(elem->dst), stok(elem->src), op, stok(elem->tgt));
128
+    if (op == RETURN) printf("ret %s\n", stok(elem->src));
129
+    if (op == 'D') printf("func %s\n", stok(elem->dst));
130
+    if (op == '>' || op == '<') printf("if %s %c %s then %s\n", stok(elem->src), op, stok(elem->tgt), stok(elem->dst));
131
+    if (op == GE_OP) printf("if %s >= %s then %s\n", stok(elem->src), stok(elem->tgt), stok(elem->dst));
132
+    if (op == LE_OP) printf("if %s <= %s then %s\n", stok(elem->src), stok(elem->tgt), stok(elem->dst));
133
+    if (op == EQ_OP) printf("if %s == %s then %s\n", stok(elem->src), stok(elem->tgt), stok(elem->dst));
134
+    if (op == NE_OP) printf("if %s != %s then %s\n", stok(elem->src), stok(elem->tgt), stok(elem->dst));
135
+    if (op == IDENTIFIER) printf("%s\n", stok(elem->dst));
136
+    if (op == VOID) printf("goto %s\n", stok(elem->dst));
137
+    if (op == AUTO) printf("param %s\n", stok(elem->dst));
138
+    if (op == APPLY) printf("call %s, %s\n", stok(elem->dst), stok(elem->tgt));
139
+    if (op == 278) printf("arg %s\n", stok(elem->dst));
140
+    if (op == 279) printf("end %s\n\n", stok(elem->dst));
141
+}
142
+
122 143
 void print_tac(TLIST* tac_list) {
123 144
   TLIST *ptr = tac_list;
124 145
 
125 146
   while (ptr != NULL) {
126
-    int op = ptr->elem->op;
127
-    if (op == '=') printf("%s := %s\n", stok(ptr->elem->dst), stok(ptr->elem->src));
128
-    if (op=='+' || op=='-' || op=='*' || op=='/' || op =='%') printf("%s := %s %c %s\n", stok(ptr->elem->dst), stok(ptr->elem->src), op, stok(ptr->elem->tgt));
129
-    if (op == RETURN) printf("ret %s\n", stok(ptr->elem->src));
130
-    if (op == 'D') printf("\nfunc %s\n", stok(ptr->elem->dst));
131
-    if (op == '>' || op == '<') printf("if %s %c %s then %s\n", stok(ptr->elem->src), op, stok(ptr->elem->tgt), stok(ptr->elem->dst));
132
-    if (op == GE_OP) printf("if %s >= %s then %s\n", stok(ptr->elem->src), stok(ptr->elem->tgt), stok(ptr->elem->dst));
133
-    if (op == LE_OP) printf("if %s <= %s then %s\n", stok(ptr->elem->src), stok(ptr->elem->tgt), stok(ptr->elem->dst));
134
-    if (op == EQ_OP) printf("if %s == %s then %s\n", stok(ptr->elem->src), stok(ptr->elem->tgt), stok(ptr->elem->dst));
135
-    if (op == NE_OP) printf("if %s != %s then %s\n", stok(ptr->elem->src), stok(ptr->elem->tgt), stok(ptr->elem->dst));
136
-    if (op == IDENTIFIER) printf("%s\n", stok(ptr->elem->dst));
137
-    if (op == VOID) printf("goto %s\n", stok(ptr->elem->dst));
138
-    if (op == AUTO) printf("param %s\n", stok(ptr->elem->dst));
139
-    if (op == APPLY) printf("call %s, %s\n", stok(ptr->elem->dst), stok(ptr->elem->tgt));
140
-    if (op == 278) printf("arg %s\n", stok(ptr->elem->dst));
141
-    if (op == 279) printf("end %s\n", stok(ptr->elem->dst));
147
+    print_tac_el(ptr->elem);
142 148
     ptr = ptr->next;
143 149
   }
144 150
 }
@@ -271,9 +277,12 @@ TOKEN* build_tac(NODE *tree, TACS* tac) {
271 277
       NODE **val_list;
272 278
       num_args = count_args(tree->right);
273 279
       val_list = get_val_list(tree->right);
280
+      TOKEN* arg_tokens[num_args];
281
+      for (int i = 0; i < num_args; i++) {
282
+        arg_tokens[i] = build_tac(val_list[i], tac);
283
+      }
274 284
       for (int i = 0; i < num_args; i++) {
275
-        TOKEN* arg_token = build_tac(val_list[i], tac);
276
-        new_tac(tac, arg_token, NULL, NULL, 278);
285
+        new_tac(tac, arg_tokens[i], NULL, NULL, 278);
277 286
       }
278 287
     }
279 288
     new_tac(tac, (TOKEN*) tree->left->left, NULL, ret_val, APPLY);
@@ -289,115 +298,199 @@ TOKEN* build_tac(NODE *tree, TACS* tac) {
289 298
 
290 299
 int tmp_regs[10] = {8, 9, 10, 11, 12, 13, 14, 15, 24, 25};
291 300
 int svd_regs[8]  = {16, 17, 18, 19, 20, 21, 22, 23};
301
+int arg_regs[3] = {5, 6, 7};
292 302
 int tmp_cntr = 0;
293
-VARLOC** vartab;
303
+int var_cntr = 0;
294 304
 
295
-int is_imm(TOKEN *t) {
296
-  if (t->type==CONSTANT) return 1;
297
-  else return 0;
298
-}
299
-
300
-int find_var_idx(TOKEN* var) {
301
-  int i;
302
-  for (i = 0; i < 8; i++) { 
303
-    if (vartab[i]->var == var) {
304
-      return vartab[i]->loc_idx;
305
+int register_me(TOKEN* name, ENV* env) {
306
+  if (tmp_cntr == 10) tmp_cntr = 0;
307
+  if (name->type == CONSTANT) {
308
+    if (name->value == 0) {
309
+      return 0;
310
+    } else {
311
+      printf("li $%d, %d\n", tmp_regs[tmp_cntr], name->value);
312
+      return tmp_regs[tmp_cntr++];
305 313
     }
306
-  }
307
-  return -1;
308
-}
309
-
310
-int store_var(TOKEN* name) {
311
-  int i;
312
-  for (i = 0; i < 8; i++) {
313
-    if (vartab[i]->var == NULL) {
314
-      vartab[i]->var = name;
315
-      vartab[i]->loc_idx = svd_regs[i];
316
-      return vartab[i]->loc_idx;
317
-    } else if (name == vartab[i]->var) {
318
-      vartab[i]->loc_idx = svd_regs[i];
319
-      return svd_regs[i];
314
+  } else {
315
+    BIND* binding = find_name_in_list(name, env->bindings);
316
+    if (binding == NULL) {
317
+      BIND* new_bind;
318
+      if (name->lexeme[0] != '$') {
319
+        new_bind = create_binding(name, env->counter++, NULL);
320
+        if (env->bindings == NULL) env->bindings = create_list(new_bind, NULL);
321
+        else append_list(env->bindings, new_bind);
322
+        new_bind->is_saved = 1;
323
+        return svd_regs[new_bind->env_offset];
324
+      } else {
325
+        new_bind = create_binding(name, tmp_cntr++, NULL);
326
+        if (env->bindings == NULL) env->bindings = create_list(new_bind, NULL);
327
+        else append_list(env->bindings, new_bind);
328
+        return tmp_regs[new_bind->env_offset];
329
+      }
330
+    } else {
331
+      return binding->is_saved ? svd_regs[binding->env_offset] : tmp_regs[binding->env_offset];
320 332
     }
321 333
   }
322
-  printf("bugger\n");
323
-  exit(1);
324 334
 }
325 335
 
326
-void init_reg() {
327
-  int i;
328
-  vartab = (VARLOC**) malloc(8 * sizeof(VARLOC*));
329
-  for (i = 0; i < 8; i++) {
330
-    vartab[i] = (VARLOC*) malloc(sizeof(VARLOC));
331
-    vartab[i]->var = NULL;
332
-    vartab[i]->loc_idx = -1;
333
-  }
334
-}
335
-
336
-int alloc_register(TOKEN* val) {
337
-  int idx;
338
-  int imm = is_imm(val);
339
-  if (imm) {
340
-    if (val->value <= 32767 && val->value >= -32767) {
341
-      printf("ori $%d, $0, %d\n", tmp_regs[tmp_cntr], val->value);
342
-      idx = tmp_regs[tmp_cntr++];
343
-    } else {
344
-      printf("li $%d, %d\n", tmp_regs[tmp_cntr], val->value);
345
-      idx = tmp_regs[tmp_cntr++];
346
-    }
347
-  } else {
348
-    idx = find_var_idx(val);
349
-  }
350
-  if (tmp_cntr == 10) tmp_cntr = 0;
351
-  return idx;
336
+void alloc_function_env() {
337
+  printf("li $a0, 68\n");
338
+  printf("li $v0, 9\n");
339
+  printf("syscall\n");
352 340
 }
353 341
 
354 342
 void compile_tac(TLIST* tacs) {
343
+  ENV* env = create_new_function_env(NULL, NULL);
355 344
   printf("=====\n");
356
-  init_reg();
345
+  alloc_function_env();
346
+  printf("or $fp, $0, $v0\n");
347
+  printf("la $t0, main\n");
348
+  printf("sw $t0, 0($fp)\n");
349
+  printf("sw $0, 4($fp)\n");
350
+  printf("la $ra, done\n");
351
+  printf("j main\n");
357 352
   while(tacs != NULL) {
358 353
     TAC_T* t = tacs->elem;
354
+    if (debug) {
355
+      printf("#");
356
+      print_tac_el(t);
357
+    }
359 358
     if (t->op == '=') {
360
-      int src_idx = alloc_register(t->src);
361
-      printf("or $%d, $0, $%d\n", store_var(t->dst), src_idx);
359
+      int src = register_me(t->src, env);
360
+      int dst = register_me(t->dst, env);
361
+      printf("or $%d, $0, $%d\n", dst, src);
362 362
     }
363 363
     if (t->op == 'D') {
364
+      env = create_new_function_env(NULL, env);
364 365
       printf("%s:\n", t->dst->lexeme);
366
+      printf("sw $ra, 64($fp)\n");
365 367
     }
366 368
     if (t->op == '+') {
367
-      int tgt_idx = alloc_register(t->tgt);
368
-      int src_idx = alloc_register(t->src);
369
-      printf("add $%d, $%d, $%d\n", store_var(t->dst), src_idx, tgt_idx);
369
+      int src = register_me(t->src, env);
370
+      int dst = register_me(t->dst, env);
371
+      int tgt = register_me(t->tgt, env);
372
+      printf("add $%d, $%d, $%d\n", dst, src, tgt);
370 373
     }
371 374
     if (t->op == '-') {
372
-      int tgt_idx = alloc_register(t->tgt);
373
-      int src_idx = alloc_register(t->src);
374
-      printf("sub $%d, $%d, $%d\n", store_var(t->dst), src_idx, tgt_idx);
375
+      int src = register_me(t->src, env);
376
+      int dst = register_me(t->dst, env);
377
+      int tgt = register_me(t->tgt, env);
378
+      printf("sub $%d, $%d, $%d\n", dst, src, tgt);
375 379
     }
376 380
     if (t->op == '*') {
377
-      int tgt_idx = alloc_register(t->tgt);
378
-      int src_idx = alloc_register(t->src);
379
-      printf("mult $%d, $%d\n", src_idx, tgt_idx);
380
-      printf("mflo $%d\n", store_var(t->dst));
381
+      int src = register_me(t->src, env);
382
+      int dst = register_me(t->dst, env);
383
+      int tgt = register_me(t->tgt, env);
384
+      printf("mult $%d, $%d\n", src, tgt);
385
+      printf("mflo $%d\n", dst);
381 386
     }
382 387
     if (t->op == '/') {
383
-      int tgt_idx = alloc_register(t->tgt);
384
-      int src_idx = alloc_register(t->src);
385
-      printf("div $%d, $%d\n", src_idx, tgt_idx);
386
-      printf("mflo $%d\n", store_var(t->dst));
388
+      int src = register_me(t->src, env);
389
+      int dst = register_me(t->dst, env);
390
+      int tgt = register_me(t->tgt, env);
391
+      printf("div $%d, $%d\n", src, tgt);
392
+      printf("mflo $%d\n", dst);
387 393
     }
388 394
     if (t->op == '%') {
389
-      int tgt_idx = alloc_register(t->tgt);
390
-      int src_idx = alloc_register(t->src);
391
-      printf("div $%d, $%d\n", src_idx, tgt_idx);
392
-      printf("mfhi $%d\n", store_var(t->dst));
395
+      int src = register_me(t->src, env);
396
+      int dst = register_me(t->dst, env);
397
+      int tgt = register_me(t->tgt, env);
398
+      printf("div $%d, $%d\n", src, tgt);
399
+      printf("mfhi $%d\n", dst);
400
+    }
401
+    if (t->op == LE_OP) {
402
+      int src = register_me(t->src, env);
403
+      int tgt = register_me(t->tgt, env);
404
+      printf("ble $%d, $%d, %s\n", src, tgt, stok(t->dst));
405
+    }
406
+    if (t->op == GE_OP) {
407
+      int src = register_me(t->src, env);
408
+      int tgt = register_me(t->tgt, env);
409
+      printf("bge $%d, $%d, %s\n", src, tgt, stok(t->dst));
410
+    }
411
+    if (t->op == EQ_OP) {
412
+      int src = register_me(t->src, env);
413
+      int tgt = register_me(t->tgt, env);
414
+      printf("beq $%d, $%d, %s\n", src, tgt, stok(t->dst));
415
+    }
416
+    if (t->op == NE_OP) {
417
+      int src = register_me(t->src, env);
418
+      int tgt = register_me(t->tgt, env);
419
+      printf("bne $%d, $%d, %s\n", src, tgt, stok(t->dst));
420
+    }
421
+    if (t->op == '>') {
422
+      int src = register_me(t->src, env);
423
+      int tgt = register_me(t->tgt, env);
424
+      printf("bgt $%d, $%d, %s\n", src, tgt, stok(t->dst));
425
+    }
426
+    if (t->op == '<') {
427
+      int src = register_me(t->src, env);
428
+      int tgt = register_me(t->tgt, env);
429
+      printf("blt $%d, $%d, %s\n", src, tgt, stok(t->dst));
430
+    }
431
+    if (t->op == APPLY) {
432
+      int tgt_idx = register_me(t->tgt, env);
433
+      env->arg_counter = 0;
434
+      alloc_function_env();
435
+      printf("sw $fp, 4($v0)\n");
436
+      if (env->bindings != NULL) {
437
+        int i = 2;
438
+        BLIST* ptr = env->bindings;
439
+        while (ptr != NULL) {
440
+          if (ptr->binding->name->lexeme[0] != '$') {
441
+            printf("sw $%d, %d($fp)\n", svd_regs[ptr->binding->env_offset], i*4);
442
+            i++;
443
+          }
444
+          ptr = ptr->next;
445
+        }
446
+      }
447
+      printf("or $fp, $0, $v0\n");
448
+      printf("la $t0, %s\n", stok(t->dst));
449
+      printf("sw $t0, 0($fp)\n");
450
+      printf("jal %s\n", stok(t->dst));
451
+      printf("lw $fp, 4($fp)\n");
452
+      printf("lw $ra, 64($fp)\n");
453
+      if (env->bindings != NULL) {
454
+        int i = 2;
455
+        BLIST* ptr = env->bindings;
456
+        while (ptr != NULL) {
457
+          if (ptr->binding->name->lexeme[0] != '$') {
458
+            printf("lw $%d, %d($fp)\n", svd_regs[ptr->binding->env_offset], i*4);
459
+            i++;
460
+          }
461
+          ptr = ptr->next;
462
+        }
463
+      }
464
+      printf("or $%d, $0, $v1\n", tgt_idx);
465
+    }
466
+    if (t->op == IDENTIFIER) {
467
+      printf("%s:\n", stok(t->dst));
468
+    }
469
+    if (t->op == VOID) {
470
+      printf("j %s\n", stok(t->dst));
393 471
     }
394 472
     if (t->op == RETURN) {
395
-      int src_idx = alloc_register(t->src);
473
+      int src_idx = register_me(t->src, env);
396 474
       printf("or $v1, $0, $%d\n", src_idx);
475
+      printf("jr $31\n");
476
+    }
477
+    if (t->op == 279) {
478
+      env = env->previous;
479
+    }
480
+    if (t->op == 278) {
481
+      int dst_idx = register_me(t->dst, env);
482
+      printf("or $%d, $0, $%d\n", arg_regs[env->arg_counter], dst_idx);
483
+      env->arg_counter++;
484
+    }
485
+    if (t->op == AUTO) {
486
+      int dst_idx = register_me(t->dst, env);
487
+      printf("or $%d, $0, $%d\n", dst_idx, arg_regs[env->param_counter]);
488
+      env->param_counter++;
397 489
     }
398 490
     tacs = tacs->next;
399 491
   }
400
-  printf("ori $v0, 10\n");
492
+  printf("done:\n");
493
+  printf("ori $v0, $0, 10\n");
401 494
   printf("syscall\n");
402 495
 }
403 496
 
@@ -418,7 +511,7 @@ extern void init_symbtable(void);
418 511
 int main(int argc, char** argv)
419 512
 {
420 513
     NODE* tree;
421
-    if (argc>1 && strcmp(argv[1],"-d")==0) yydebug = 1;
514
+    if (argc>1 && strcmp(argv[1],"-d")==0) debug = 1;
422 515
     init_symbtable();
423 516
     printf("--C COMPILER\n");
424 517
     yyparse();

+ 54 - 0
tac/mips.asm

@@ -0,0 +1,54 @@
1
+li $a0, 68
2
+li $v0, 9
3
+syscall
4
+or $fp, $0, $v0
5
+la $t0, main
6
+sw $t0, 0($fp)
7
+sw $0, 4($fp)
8
+la $ra, done
9
+j main
10
+blah:
11
+sw $ra, 64($fp)
12
+or $16, $0, $5
13
+li $8, 3
14
+or $17, $0, $8
15
+add $9, $17, $16
16
+or $v1, $0, $9
17
+jr $31
18
+main:
19
+sw $ra, 64($fp)
20
+li $10, 4
21
+or $16, $0, $10
22
+li $11, 4
23
+or $5, $0, $11
24
+li $a0, 68
25
+li $v0, 9
26
+syscall
27
+sw $fp, 4($v0)
28
+sw $16, 8($fp)
29
+or $fp, $0, $v0
30
+la $t0, blah
31
+sw $t0, 0($fp)
32
+jal blah
33
+lw $fp, 4($fp)
34
+lw $ra, 64($fp)
35
+lw $16, 8($fp)
36
+or $12, $0, $v1
37
+or $17, $0, $12
38
+li $13, 5
39
+ble $17, $13, L0
40
+li $15, 10
41
+add $14, $16, $15
42
+or $16, $0, $14
43
+j L1
44
+L0:
45
+li $25, 5
46
+add $24, $16, $25
47
+or $16, $0, $24
48
+L1:
49
+add $8, $17, $16
50
+or $v1, $0, $8
51
+jr $31
52
+done:
53
+ori $v0, $0, 10
54
+syscall

+ 155 - 0
tac/recurse.asm

@@ -0,0 +1,155 @@
1
+li $a0, 68
2
+li $v0, 9
3
+syscall
4
+or $fp, $0, $v0
5
+la $t0, main
6
+sw $t0, 0($fp)
7
+sw $0, 4($fp)
8
+la $ra, done
9
+j main
10
+#func inner_fact
11
+inner_fact:
12
+sw $ra, 64($fp)
13
+#param n
14
+or $16, $0, $5
15
+#param a
16
+or $17, $0, $6
17
+#if n != 0 then L0
18
+bne $16, $0, L0
19
+#ret a
20
+or $v1, $0, $17
21
+jr $31
22
+#L0
23
+L0:
24
+#$t1 := n - 1
25
+li $9, 1
26
+sub $8, $16, $9
27
+#$t2 := a * n
28
+mult $17, $16
29
+mflo $10
30
+#arg $t1
31
+or $5, $0, $8
32
+#arg $t2
33
+or $6, $0, $10
34
+#call inner_fact, $t0
35
+li $a0, 68
36
+li $v0, 9
37
+syscall
38
+sw $fp, 4($v0)
39
+sw $16, 8($fp)
40
+sw $17, 12($fp)
41
+or $fp, $0, $v0
42
+la $t0, inner_fact
43
+sw $t0, 0($fp)
44
+jal inner_fact
45
+lw $fp, 4($fp)
46
+lw $ra, 64($fp)
47
+lw $16, 8($fp)
48
+lw $17, 12($fp)
49
+or $11, $0, $v1
50
+#ret $t0
51
+or $v1, $0, $11
52
+jr $31
53
+#end inner_fact
54
+
55
+#func fact
56
+fact:
57
+sw $ra, 64($fp)
58
+#param n
59
+or $16, $0, $5
60
+#arg n
61
+or $5, $0, $16
62
+#arg 1
63
+li $12, 1
64
+or $6, $0, $12
65
+#call inner_fact, $t3
66
+li $a0, 68
67
+li $v0, 9
68
+syscall
69
+sw $fp, 4($v0)
70
+sw $16, 8($fp)
71
+or $fp, $0, $v0
72
+la $t0, inner_fact
73
+sw $t0, 0($fp)
74
+jal inner_fact
75
+lw $fp, 4($fp)
76
+lw $ra, 64($fp)
77
+lw $16, 8($fp)
78
+or $13, $0, $v1
79
+#ret $t3
80
+or $v1, $0, $13
81
+jr $31
82
+#end fact
83
+
84
+#func main
85
+main:
86
+sw $ra, 64($fp)
87
+#arg 3
88
+li $14, 3
89
+or $5, $0, $14
90
+#call fact, $t4
91
+li $a0, 68
92
+li $v0, 9
93
+syscall
94
+sw $fp, 4($v0)
95
+or $fp, $0, $v0
96
+la $t0, fact
97
+sw $t0, 0($fp)
98
+jal fact
99
+lw $fp, 4($fp)
100
+lw $ra, 64($fp)
101
+or $15, $0, $v1
102
+#x := $t4
103
+or $16, $0, $15
104
+#arg 5
105
+li $24, 5
106
+or $5, $0, $24
107
+#call fact, $t5
108
+li $a0, 68
109
+li $v0, 9
110
+syscall
111
+sw $fp, 4($v0)
112
+sw $16, 8($fp)
113
+or $fp, $0, $v0
114
+la $t0, fact
115
+sw $t0, 0($fp)
116
+jal fact
117
+lw $fp, 4($fp)
118
+lw $ra, 64($fp)
119
+lw $16, 8($fp)
120
+or $25, $0, $v1
121
+#y := $t5
122
+or $17, $0, $25
123
+#arg 7
124
+li $8, 7
125
+or $5, $0, $8
126
+#call fact, $t6
127
+li $a0, 68
128
+li $v0, 9
129
+syscall
130
+sw $fp, 4($v0)
131
+sw $16, 8($fp)
132
+sw $17, 12($fp)
133
+or $fp, $0, $v0
134
+la $t0, fact
135
+sw $t0, 0($fp)
136
+jal fact
137
+lw $fp, 4($fp)
138
+lw $ra, 64($fp)
139
+lw $16, 8($fp)
140
+lw $17, 12($fp)
141
+or $9, $0, $v1
142
+#z := $t6
143
+or $18, $0, $9
144
+#$t8 := x + y
145
+add $10, $16, $17
146
+#$t7 := $t8 + z
147
+add $11, $10, $18
148
+#ret $t7
149
+or $v1, $0, $11
150
+jr $31
151
+#end main
152
+
153
+done:
154
+ori $v0, $0, 10
155
+syscall

+ 19 - 0
tac/recursion.c

@@ -0,0 +1,19 @@
1
+/* ##answer: 5166*/
2
+
3
+
4
+int inner_fact(int n, int a) {
5
+  if (n == 0) return a;
6
+  return inner_fact(n-1, a*n);
7
+}
8
+
9
+int fact(int n) {
10
+  return inner_fact(n, 1);
11
+}
12
+
13
+int main() {
14
+  int x = fact(3);
15
+  int y = fact(5);
16
+  int z = fact(7);
17
+
18
+  return x+y+z;
19
+}

+ 9 - 12
tac/simple.c

@@ -1,18 +1,15 @@
1
-int inner_fact(int n, int a) {
2
-  if (n == 0) return a;
3
-  return inner_fact(n-1, a*n);
4
-}
5
-
6
-int fact(int n) {
7
-  return inner_fact(n, 1);
1
+int blah(int b) {
2
+  int y = 3;
3
+  return y + b;
8 4
 }
9 5
 
10 6
 int main() {
11
-  int x = blah(2);
12
-  if (x > 0) {
13
-    x = 10;
7
+  int y = 4;
8
+  int x = blah(4);
9
+  if (x > 5) {
10
+    y = y+10;
14 11
   } else {
15
-    x = 5;
12
+    y = y+5;
16 13
   }
17
-  return x;
14
+  return x+y;
18 15
 }

+ 24 - 15
tac/test.asm

@@ -1,18 +1,27 @@
1
+j main
2
+blah:
3
+ori $8, $0, 6
4
+or $v1, $0, $8
5
+jr $31
1 6
 main:
2
-ori $8, $0, 2
3
-li $9, 48282
4
-add $19, $9, $8
5
-ori $10, $0, 2
6
-mult $19, $10
7
-mflo $20
8
-ori $11, $0, 2
9
-ori $12, $0, 4
10
-div $12, $11
11
-mflo $21
12
-ori $13, $0, 5
13
-div $13, $21
14
-mfhi $22
15
-sub $23, $20, $22
16
-or $k0, $0, $23
7
+la $31 done
8
+sw $31, 0($sp)
9
+jal blah
10
+nop
11
+lw $31, 0($sp)
12
+or $9, $0, $v1
13
+or $16, $0, $9
14
+ori $10, $0, 5
15
+ble $16, $10, L0
16
+ori $11, $0, 10
17
+or $17, $0, $11
18
+j L1
19
+L0:
20
+ori $12, $0, 5
21
+or $18, $0, $12
22
+L1:
23
+or $v1, $0, $18
24
+jr $31
25
+done:
17 26
 ori $v0, 10
18 27
 syscall

+ 8 - 2
tac/types.h

@@ -3,8 +3,9 @@
3 3
 #include "nodes.h"
4 4
 
5 5
 typedef struct binding {
6
-  char* name;
7
-  NODE* tree;
6
+  TOKEN* name;
7
+  int env_offset;
8
+  int is_saved;
8 9
   struct environ *env;
9 10
 } BIND;
10 11
 
@@ -14,8 +15,13 @@ typedef struct blist {
14 15
 } BLIST;
15 16
 
16 17
 typedef struct environ {
18
+  int return_addr;
17 19
   BLIST *bindings;
18 20
   struct environ *parent;
21
+  struct environ *previous;
22
+  int counter;
23
+  int param_counter;
24
+  int arg_counter;
19 25
 } ENV;
20 26
 
21 27
 typedef struct tac_elem {