3 次代碼提交 890548e796 ... a059405928

作者 SHA1 備註 提交日期
  Matt Coles a059405928 woohoo 8 年之前
  Matt Coles f4f00926dc merging 8 年之前
  Matt Coles db96312cee blah 8 年之前
共有 25 個文件被更改,包括 1795 次插入1352 次删除
  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
       if(debug)printf("I got: ");
255
       if(debug)printf("I got: ");
256
       if (var_bind->tree->type == CONSTANT) {
256
       if (var_bind->tree->type == CONSTANT) {
257
         if(debug){
257
         if(debug){
258
-          printf("CONSTANT\n");
259
           print_leaf(var_bind->tree, 0);
258
           print_leaf(var_bind->tree, 0);
260
         }
259
         }
261
       } else {
260
       } else {
310
       return ret_val;
309
       return ret_val;
311
     } else {
310
     } else {
312
       printf("HELP called a function with no return!!\n");
311
       printf("HELP called a function with no return!!\n");
312
+      exit(1);
313
     }
313
     }
314
   }
314
   }
315
   if (tree->type == IF) {
315
   if (tree->type == IF) {
371
     if (debug) printf("Adding %d and %d\n", lhs->value, rhs->value);
371
     if (debug) printf("Adding %d and %d\n", lhs->value, rhs->value);
372
     int result = lhs->value + rhs->value;
372
     int result = lhs->value + rhs->value;
373
     return anon_binding((NODE*) get_int_token(result));
373
     return anon_binding((NODE*) get_int_token(result));
374
-  }
374
+ }
375
   if (tree->type == '-') {
375
   if (tree->type == '-') {
376
     TOKEN* lhs = (TOKEN*) recursive_interpret(tree->left, env_ptr)->tree;
376
     TOKEN* lhs = (TOKEN*) recursive_interpret(tree->left, env_ptr)->tree;
377
     TOKEN* rhs = (TOKEN*) recursive_interpret(tree->right, env_ptr)->tree;
377
     TOKEN* rhs = (TOKEN*) recursive_interpret(tree->right, env_ptr)->tree;

+ 10 - 0
cw/simple.c

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
 int main() {
11
 int main() {
2
   int b = 4;
12
   int b = 4;
3
 
13
 

+ 21 - 0
cw/simple.c.orig

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

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

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

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

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

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

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

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

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
 }
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
 }

文件差異過大導致無法顯示
+ 978 - 1027
tac/C.tab.c


+ 47 - 61
tac/C.tab.h

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
    it under the terms of the GNU General Public License as published by
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
    This program is distributed in the hope that it will be useful,
12
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
    GNU General Public License for more details.
15
    GNU General Public License for more details.
17
 
16
 
18
    You should have received a copy of the GNU General Public License
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
 /* As a special exception, you may create a larger work that contains
20
 /* As a special exception, you may create a larger work that contains
24
    part or all of the Bison parser skeleton and distribute that work
21
    part or all of the Bison parser skeleton and distribute that work
33
    This special exception was added by the Free Software Foundation in
30
    This special exception was added by the Free Software Foundation in
34
    version 2.2 of Bison.  */
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
 #ifndef YYTOKENTYPE
44
 #ifndef YYTOKENTYPE
38
 # define YYTOKENTYPE
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
 #endif
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
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
72
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
90
 typedef int YYSTYPE;
73
 typedef int YYSTYPE;
91
-# define yystype YYSTYPE /* obsolescent; will be withdrawn */
92
-# define YYSTYPE_IS_DECLARED 1
93
 # define YYSTYPE_IS_TRIVIAL 1
74
 # define YYSTYPE_IS_TRIVIAL 1
75
+# define YYSTYPE_IS_DECLARED 1
94
 #endif
76
 #endif
95
 
77
 
78
+
96
 extern YYSTYPE yylval;
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
 
7
 
8
 #define FLEX_SCANNER
8
 #define FLEX_SCANNER
9
 #define YY_FLEX_MAJOR_VERSION 2
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
 #if YY_FLEX_SUBMINOR_VERSION > 0
12
 #if YY_FLEX_SUBMINOR_VERSION > 0
13
 #define FLEX_BETA
13
 #define FLEX_BETA
14
 #endif
14
 #endif
46
 typedef uint16_t flex_uint16_t;
46
 typedef uint16_t flex_uint16_t;
47
 typedef int32_t flex_int32_t;
47
 typedef int32_t flex_int32_t;
48
 typedef uint32_t flex_uint32_t;
48
 typedef uint32_t flex_uint32_t;
49
-typedef uint64_t flex_uint64_t;
50
 #else
49
 #else
51
 typedef signed char flex_int8_t;
50
 typedef signed char flex_int8_t;
52
 typedef short int flex_int16_t;
51
 typedef short int flex_int16_t;
54
 typedef unsigned char flex_uint8_t; 
53
 typedef unsigned char flex_uint8_t; 
55
 typedef unsigned short int flex_uint16_t;
54
 typedef unsigned short int flex_uint16_t;
56
 typedef unsigned int flex_uint32_t;
55
 typedef unsigned int flex_uint32_t;
57
-#endif /* ! C99 */
58
 
56
 
59
 /* Limits of integral types. */
57
 /* Limits of integral types. */
60
 #ifndef INT8_MIN
58
 #ifndef INT8_MIN
85
 #define UINT32_MAX             (4294967295U)
83
 #define UINT32_MAX             (4294967295U)
86
 #endif
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
 #define yyconst const
91
 #define yyconst const
92
+
93
+#if defined(__GNUC__) && __GNUC__ >= 3
94
+#define yynoreturn __attribute__((__noreturn__))
107
 #else
95
 #else
108
-#define yyconst
96
+#define yynoreturn
109
 #endif
97
 #endif
110
 
98
 
111
 /* Returned upon end-of-file. */
99
 /* Returned upon end-of-file. */
141
 
129
 
142
 /* Size of default input buffer. */
130
 /* Size of default input buffer. */
143
 #ifndef YY_BUF_SIZE
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
 #define YY_BUF_SIZE 16384
139
 #define YY_BUF_SIZE 16384
140
+#endif /* __ia64__ */
145
 #endif
141
 #endif
146
 
142
 
147
 /* The state buf must be large enough to hold one state per character in the main buffer.
143
 /* The state buf must be large enough to hold one state per character in the main buffer.
158
 typedef size_t yy_size_t;
154
 typedef size_t yy_size_t;
159
 #endif
155
 #endif
160
 
156
 
161
-extern yy_size_t yyleng;
157
+extern int yyleng;
162
 
158
 
163
 extern FILE *yyin, *yyout;
159
 extern FILE *yyin, *yyout;
164
 
160
 
167
 #define EOB_ACT_LAST_MATCH 2
163
 #define EOB_ACT_LAST_MATCH 2
168
 
164
 
169
     #define YY_LESS_LINENO(n)
165
     #define YY_LESS_LINENO(n)
166
+    #define YY_LINENO_REWIND_TO(ptr)
170
     
167
     
171
 /* Return all but the first "n" matched characters back to the input stream. */
168
 /* Return all but the first "n" matched characters back to the input stream. */
172
 #define yyless(n) \
169
 #define yyless(n) \
196
 	/* Size of input buffer in bytes, not including room for EOB
193
 	/* Size of input buffer in bytes, not including room for EOB
197
 	 * characters.
194
 	 * characters.
198
 	 */
195
 	 */
199
-	yy_size_t yy_buf_size;
196
+	int yy_buf_size;
200
 
197
 
201
 	/* Number of characters read into yy_ch_buf, not including EOB
198
 	/* Number of characters read into yy_ch_buf, not including EOB
202
 	 * characters.
199
 	 * characters.
203
 	 */
200
 	 */
204
-	yy_size_t yy_n_chars;
201
+	int yy_n_chars;
205
 
202
 
206
 	/* Whether we "own" the buffer - i.e., we know we created it,
203
 	/* Whether we "own" the buffer - i.e., we know we created it,
207
 	 * and can realloc() it to grow it, and should free() it to
204
 	 * and can realloc() it to grow it, and should free() it to
224
 
221
 
225
     int yy_bs_lineno; /**< The line count. */
222
     int yy_bs_lineno; /**< The line count. */
226
     int yy_bs_column; /**< The column count. */
223
     int yy_bs_column; /**< The column count. */
227
-    
224
+
228
 	/* Whether to try to fill the input buffer when we reach the
225
 	/* Whether to try to fill the input buffer when we reach the
229
 	 * end of it.
226
 	 * end of it.
230
 	 */
227
 	 */
252
 /* Stack of input buffers. */
249
 /* Stack of input buffers. */
253
 static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
250
 static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
254
 static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
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
 /* We provide macros for accessing buffer states in case in the
254
 /* We provide macros for accessing buffer states in case in the
258
  * future we want to put the buffer states in a more general
255
  * future we want to put the buffer states in a more general
271
 
268
 
272
 /* yy_hold_char holds the character lost when yytext is formed. */
269
 /* yy_hold_char holds the character lost when yytext is formed. */
273
 static char yy_hold_char;
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
 /* Points to current character in buffer. */
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
 static int yy_init = 0;		/* whether we need to initialize */
276
 static int yy_init = 0;		/* whether we need to initialize */
280
 static int yy_start = 0;	/* start state number */
277
 static int yy_start = 0;	/* start state number */
281
 
278
 
300
 
297
 
301
 YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size  );
298
 YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size  );
302
 YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str  );
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
 void *yyalloc (yy_size_t  );
302
 void *yyalloc (yy_size_t  );
306
 void *yyrealloc (void *,yy_size_t  );
303
 void *yyrealloc (void *,yy_size_t  );
334
 
331
 
335
 typedef unsigned char YY_CHAR;
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
 typedef int yy_state_type;
336
 typedef int yy_state_type;
340
 
337
 
343
 int yylineno = 1;
340
 int yylineno = 1;
344
 
341
 
345
 extern char *yytext;
342
 extern char *yytext;
343
+#ifdef yytext_ptr
344
+#undef yytext_ptr
345
+#endif
346
 #define yytext_ptr yytext
346
 #define yytext_ptr yytext
347
 
347
 
348
 static yy_state_type yy_get_previous_state (void );
348
 static yy_state_type yy_get_previous_state (void );
349
 static yy_state_type yy_try_NUL_trans (yy_state_type current_state  );
349
 static yy_state_type yy_try_NUL_trans (yy_state_type current_state  );
350
 static int yy_get_next_buffer (void );
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
 /* Done after the current pattern has been matched and before the
353
 /* Done after the current pattern has been matched and before the
354
  * corresponding action - sets up yytext.
354
  * corresponding action - sets up yytext.
355
  */
355
  */
356
 #define YY_DO_BEFORE_ACTION \
356
 #define YY_DO_BEFORE_ACTION \
357
 	(yytext_ptr) = yy_bp; \
357
 	(yytext_ptr) = yy_bp; \
358
-	yyleng = (yy_size_t) (yy_cp - yy_bp); \
358
+	yyleng = (int) (yy_cp - yy_bp); \
359
 	(yy_hold_char) = *yy_cp; \
359
 	(yy_hold_char) = *yy_cp; \
360
 	*yy_cp = '\0'; \
360
 	*yy_cp = '\0'; \
361
 	(yy_c_buf_p) = yy_cp;
361
 	(yy_c_buf_p) = yy_cp;
384
 
384
 
385
     } ;
385
     } ;
386
 
386
 
387
-static yyconst flex_int32_t yy_ec[256] =
387
+static yyconst YY_CHAR yy_ec[256] =
388
     {   0,
388
     {   0,
389
         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
389
         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
390
         2,    2,    1,    1,    1,    1,    1,    1,    1,    1,
390
         2,    2,    1,    1,    1,    1,    1,    1,    1,    1,
416
         1,    1,    1,    1,    1
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
     {   0,
420
     {   0,
421
         1,    1,    1,    1,    1,    1,    2,    1,    1,    1,
421
         1,    1,    1,    1,    1,    1,    2,    1,    1,    1,
422
         1,    1,    1,    1,    3,    1,    1,    1,    1,    1,
422
         1,    1,    1,    1,    3,    1,    1,    1,    1,    1,
425
         3,    3,    3,    1,    1
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
     {   0,
429
     {   0,
430
         0,    0,  130,  131,  131,  131,  110,   41,  131,  104,
430
         0,    0,  130,  131,  131,  131,  110,   41,  131,  104,
431
       131,  131,  131,  131,  131,  131,  117,   32,  131,  131,
431
       131,  131,  131,  131,  131,  131,  117,   32,  131,  131,
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
     {   0,
459
     {   0,
460
         4,    5,    6,    7,    8,    9,   10,   11,   12,   13,
460
         4,    5,    6,    7,    8,    9,   10,   11,   12,   13,
461
        14,   15,   16,   17,   18,   19,   20,   21,   22,   23,
461
        14,   15,   16,   17,   18,   19,   20,   21,   22,   23,
567
 
567
 
568
 FILE *yyget_in (void );
568
 FILE *yyget_in (void );
569
 
569
 
570
-void yyset_in  (FILE * in_str  );
570
+void yyset_in  (FILE * _in_str  );
571
 
571
 
572
 FILE *yyget_out (void );
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
 char *yyget_text (void );
578
 char *yyget_text (void );
579
 
579
 
580
 int yyget_lineno (void );
580
 int yyget_lineno (void );
581
 
581
 
582
-void yyset_lineno (int line_number  );
582
+void yyset_lineno (int _line_number  );
583
 
583
 
584
 /* Macros after this point can all be overridden by user definitions in
584
 /* Macros after this point can all be overridden by user definitions in
585
  * section 1.
585
  * section 1.
593
 #endif
593
 #endif
594
 #endif
594
 #endif
595
 
595
 
596
+#ifndef YY_NO_UNPUT
597
+    
596
     static void yyunput (int c,char *buf_ptr  );
598
     static void yyunput (int c,char *buf_ptr  );
597
     
599
     
600
+#endif
601
+
598
 #ifndef yytext_ptr
602
 #ifndef yytext_ptr
599
 static void yy_flex_strncpy (char *,yyconst char *,int );
603
 static void yy_flex_strncpy (char *,yyconst char *,int );
600
 #endif
604
 #endif
615
 
619
 
616
 /* Amount of stuff to slurp up with each read. */
620
 /* Amount of stuff to slurp up with each read. */
617
 #ifndef YY_READ_BUF_SIZE
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
 #define YY_READ_BUF_SIZE 8192
626
 #define YY_READ_BUF_SIZE 8192
627
+#endif /* __ia64__ */
619
 #endif
628
 #endif
620
 
629
 
621
 /* Copy whatever the last rule matched to the standard output. */
630
 /* Copy whatever the last rule matched to the standard output. */
623
 /* This used to be an fputs(), but since the string might contain NUL's,
632
 /* This used to be an fputs(), but since the string might contain NUL's,
624
  * we now use fwrite().
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
 #endif
636
 #endif
628
 
637
 
629
 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
638
 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
634
 	if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
643
 	if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
635
 		{ \
644
 		{ \
636
 		int c = '*'; \
645
 		int c = '*'; \
637
-		yy_size_t n; \
646
+		size_t n; \
638
 		for ( n = 0; n < max_size && \
647
 		for ( n = 0; n < max_size && \
639
 			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
648
 			     (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
640
 			buf[n] = (char) c; \
649
 			buf[n] = (char) c; \
647
 	else \
656
 	else \
648
 		{ \
657
 		{ \
649
 		errno=0; \
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
 			if( errno != EINTR) \
661
 			if( errno != EINTR) \
653
 				{ \
662
 				{ \
702
 
711
 
703
 /* Code executed at the end of each rule. */
712
 /* Code executed at the end of each rule. */
704
 #ifndef YY_BREAK
713
 #ifndef YY_BREAK
705
-#define YY_BREAK break;
714
+#define YY_BREAK /*LINTED*/break;
706
 #endif
715
 #endif
707
 
716
 
708
 #define YY_RULE_SETUP \
717
 #define YY_RULE_SETUP \
712
  */
721
  */
713
 YY_DECL
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
 	if ( !(yy_init) )
728
 	if ( !(yy_init) )
724
 		{
729
 		{
725
 		(yy_init) = 1;
730
 		(yy_init) = 1;
746
 		yy_load_buffer_state( );
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
 		yy_cp = (yy_c_buf_p);
761
 		yy_cp = (yy_c_buf_p);
752
 
762
 
762
 yy_match:
772
 yy_match:
763
 		do
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
 			if ( yy_accept[yy_current_state] )
776
 			if ( yy_accept[yy_current_state] )
767
 				{
777
 				{
768
 				(yy_last_accepting_state) = yy_current_state;
778
 				(yy_last_accepting_state) = yy_current_state;
774
 				if ( yy_current_state >= 98 )
784
 				if ( yy_current_state >= 98 )
775
 					yy_c = yy_meta[(unsigned int) yy_c];
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
 			++yy_cp;
788
 			++yy_cp;
779
 			}
789
 			}
780
 		while ( yy_base[yy_current_state] != 131 );
790
 		while ( yy_base[yy_current_state] != 131 );
1001
 #line 76 "C.flex"
1011
 #line 76 "C.flex"
1002
 ECHO;
1012
 ECHO;
1003
 	YY_BREAK
1013
 	YY_BREAK
1004
-#line 1005 "lex.yy.c"
1014
+#line 1015 "lex.yy.c"
1005
 case YY_STATE_EOF(INITIAL):
1015
 case YY_STATE_EOF(INITIAL):
1006
 	yyterminate();
1016
 	yyterminate();
1007
 
1017
 
1132
 			"fatal flex scanner internal error--no action found" );
1142
 			"fatal flex scanner internal error--no action found" );
1133
 	} /* end of action switch */
1143
 	} /* end of action switch */
1134
 		} /* end of scanning one token */
1144
 		} /* end of scanning one token */
1145
+	} /* end of user's declarations */
1135
 } /* end of yylex */
1146
 } /* end of yylex */
1136
 
1147
 
1137
 /* yy_get_next_buffer - try to read in a new buffer
1148
 /* yy_get_next_buffer - try to read in a new buffer
1143
  */
1154
  */
1144
 static int yy_get_next_buffer (void)
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
 	int ret_val;
1160
 	int ret_val;
1150
 
1161
 
1151
 	if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
1162
 	if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
1174
 	/* Try to read more data. */
1185
 	/* Try to read more data. */
1175
 
1186
 
1176
 	/* First move last chars to start of buffer. */
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
 	for ( i = 0; i < number_to_move; ++i )
1190
 	for ( i = 0; i < number_to_move; ++i )
1180
 		*(dest++) = *(source++);
1191
 		*(dest++) = *(source++);
1187
 
1198
 
1188
 	else
1199
 	else
1189
 		{
1200
 		{
1190
-			yy_size_t num_to_read =
1201
+			int num_to_read =
1191
 			YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1202
 			YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1192
 
1203
 
1193
 		while ( num_to_read <= 0 )
1204
 		while ( num_to_read <= 0 )
1194
 			{ /* Not enough room in the buffer - grow it. */
1205
 			{ /* Not enough room in the buffer - grow it. */
1195
 
1206
 
1196
 			/* just a shorter name for the current buffer */
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
 			int yy_c_buf_p_offset =
1210
 			int yy_c_buf_p_offset =
1200
 				(int) ((yy_c_buf_p) - b->yy_ch_buf);
1211
 				(int) ((yy_c_buf_p) - b->yy_ch_buf);
1201
 
1212
 
1202
 			if ( b->yy_is_our_buffer )
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
 				if ( new_size <= 0 )
1217
 				if ( new_size <= 0 )
1207
 					b->yy_buf_size += b->yy_buf_size / 8;
1218
 					b->yy_buf_size += b->yy_buf_size / 8;
1214
 				}
1225
 				}
1215
 			else
1226
 			else
1216
 				/* Can't grow it, we don't own it. */
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
 			if ( ! b->yy_ch_buf )
1230
 			if ( ! b->yy_ch_buf )
1220
 				YY_FATAL_ERROR(
1231
 				YY_FATAL_ERROR(
1256
 	else
1267
 	else
1257
 		ret_val = EOB_ACT_CONTINUE_SCAN;
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
 		/* Extend the array by 50%, plus the number we really need. */
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
 		YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size  );
1273
 		YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size  );
1263
 		if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1274
 		if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1264
 			YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1275
 			YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1277
 
1288
 
1278
     static yy_state_type yy_get_previous_state (void)
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
 	yy_current_state = (yy_start);
1294
 	yy_current_state = (yy_start);
1284
 
1295
 
1285
 	for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
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
 		if ( yy_accept[yy_current_state] )
1299
 		if ( yy_accept[yy_current_state] )
1289
 			{
1300
 			{
1290
 			(yy_last_accepting_state) = yy_current_state;
1301
 			(yy_last_accepting_state) = yy_current_state;
1296
 			if ( yy_current_state >= 98 )
1307
 			if ( yy_current_state >= 98 )
1297
 				yy_c = yy_meta[(unsigned int) yy_c];
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
 	return yy_current_state;
1313
 	return yy_current_state;
1309
  */
1320
  */
1310
     static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state )
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
 	if ( yy_accept[yy_current_state] )
1327
 	if ( yy_accept[yy_current_state] )
1317
 		{
1328
 		{
1318
 		(yy_last_accepting_state) = yy_current_state;
1329
 		(yy_last_accepting_state) = yy_current_state;
1324
 		if ( yy_current_state >= 98 )
1335
 		if ( yy_current_state >= 98 )
1325
 			yy_c = yy_meta[(unsigned int) yy_c];
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
 	yy_is_jam = (yy_current_state == 97);
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
     yy_cp = (yy_c_buf_p);
1350
     yy_cp = (yy_c_buf_p);
1338
 
1351
 
1342
 	if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1355
 	if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1343
 		{ /* need to shift things up to make room */
1356
 		{ /* need to shift things up to make room */
1344
 		/* +2 for EOB chars. */
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
 					YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
1360
 					YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
1348
-		register char *source =
1361
+		char *source =
1349
 				&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
1362
 				&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
1350
 
1363
 
1351
 		while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1364
 		while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1354
 		yy_cp += (int) (dest - source);
1367
 		yy_cp += (int) (dest - source);
1355
 		yy_bp += (int) (dest - source);
1368
 		yy_bp += (int) (dest - source);
1356
 		YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
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
 		if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1372
 		if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
1360
 			YY_FATAL_ERROR( "flex scanner push-back overflow" );
1373
 			YY_FATAL_ERROR( "flex scanner push-back overflow" );
1367
 	(yy_c_buf_p) = yy_cp;
1380
 	(yy_c_buf_p) = yy_cp;
1368
 }
1381
 }
1369
 
1382
 
1383
+#endif
1384
+
1370
 #ifndef YY_NO_INPUT
1385
 #ifndef YY_NO_INPUT
1371
 #ifdef __cplusplus
1386
 #ifdef __cplusplus
1372
     static int yyinput (void)
1387
     static int yyinput (void)
1391
 
1406
 
1392
 		else
1407
 		else
1393
 			{ /* need more input */
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
 			++(yy_c_buf_p);
1410
 			++(yy_c_buf_p);
1396
 
1411
 
1397
 			switch ( yy_get_next_buffer(  ) )
1412
 			switch ( yy_get_next_buffer(  ) )
1516
 	if ( ! b )
1531
 	if ( ! b )
1517
 		YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
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
 	/* yy_ch_buf has to be 2 characters longer than the size given because
1536
 	/* yy_ch_buf has to be 2 characters longer than the size given because
1522
 	 * we need to put in 2 end-of-buffer characters.
1537
 	 * we need to put in 2 end-of-buffer characters.
1551
 	yyfree((void *) b  );
1566
 	yyfree((void *) b  );
1552
 }
1567
 }
1553
 
1568
 
1554
-#ifndef __cplusplus
1555
-extern int isatty (int );
1556
-#endif /* __cplusplus */
1557
-    
1558
 /* Initializes or reinitializes a buffer.
1569
 /* Initializes or reinitializes a buffer.
1559
  * This function is sometimes called more than once on the same buffer,
1570
  * This function is sometimes called more than once on the same buffer,
1560
  * such as during a yyrestart() or at EOF.
1571
  * such as during a yyrestart() or at EOF.
1667
  */
1678
  */
1668
 static void yyensure_buffer_stack (void)
1679
 static void yyensure_buffer_stack (void)
1669
 {
1680
 {
1670
-	yy_size_t num_to_alloc;
1681
+	int num_to_alloc;
1671
     
1682
     
1672
 	if (!(yy_buffer_stack)) {
1683
 	if (!(yy_buffer_stack)) {
1673
 
1684
 
1675
 		 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1686
 		 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1676
 		 * immediate realloc on the next call.
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
 		(yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
1690
 		(yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
1680
 								(num_to_alloc * sizeof(struct yy_buffer_state*)
1691
 								(num_to_alloc * sizeof(struct yy_buffer_state*)
1681
 								);
1692
 								);
1682
 		if ( ! (yy_buffer_stack) )
1693
 		if ( ! (yy_buffer_stack) )
1683
 			YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1694
 			YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1684
-								  
1695
+
1685
 		memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1696
 		memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1686
-				
1697
+
1687
 		(yy_buffer_stack_max) = num_to_alloc;
1698
 		(yy_buffer_stack_max) = num_to_alloc;
1688
 		(yy_buffer_stack_top) = 0;
1699
 		(yy_buffer_stack_top) = 0;
1689
 		return;
1700
 		return;
1692
 	if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1703
 	if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1693
 
1704
 
1694
 		/* Increase the buffer to prepare for a possible push. */
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
 		num_to_alloc = (yy_buffer_stack_max) + grow_size;
1708
 		num_to_alloc = (yy_buffer_stack_max) + grow_size;
1698
 		(yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
1709
 		(yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
1712
  * @param base the character buffer
1723
  * @param base the character buffer
1713
  * @param size the size in bytes of the character buffer
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
 YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1728
 YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1718
 {
1729
 {
1722
 	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
1733
 	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
1723
 	     base[size-1] != YY_END_OF_BUFFER_CHAR )
1734
 	     base[size-1] != YY_END_OF_BUFFER_CHAR )
1724
 		/* They forgot to leave room for the EOB's. */
1735
 		/* They forgot to leave room for the EOB's. */
1725
-		return 0;
1736
+		return NULL;
1726
 
1737
 
1727
 	b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state )  );
1738
 	b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state )  );
1728
 	if ( ! b )
1739
 	if ( ! b )
1731
 	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
1742
 	b->yy_buf_size = size - 2;	/* "- 2" to take care of EOB's */
1732
 	b->yy_buf_pos = b->yy_ch_buf = base;
1743
 	b->yy_buf_pos = b->yy_ch_buf = base;
1733
 	b->yy_is_our_buffer = 0;
1744
 	b->yy_is_our_buffer = 0;
1734
-	b->yy_input_file = 0;
1745
+	b->yy_input_file = NULL;
1735
 	b->yy_n_chars = b->yy_buf_size;
1746
 	b->yy_n_chars = b->yy_buf_size;
1736
 	b->yy_is_interactive = 0;
1747
 	b->yy_is_interactive = 0;
1737
 	b->yy_at_bol = 1;
1748
 	b->yy_at_bol = 1;
1754
 YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
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
 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
1771
 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
1761
  * scan from a @e copy of @a bytes.
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
  * @return the newly allocated buffer state object.
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
 	YY_BUFFER_STATE b;
1780
 	YY_BUFFER_STATE b;
1770
 	char *buf;
1781
 	char *buf;
1771
-	yy_size_t n, i;
1782
+	yy_size_t n;
1783
+	int i;
1772
     
1784
     
1773
 	/* Get memory for full buffer, including space for trailing EOB's. */
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
 	buf = (char *) yyalloc(n  );
1787
 	buf = (char *) yyalloc(n  );
1776
 	if ( ! buf )
1788
 	if ( ! buf )
1777
 		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
1789
 		YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
1797
 #define YY_EXIT_FAILURE 2
1809
 #define YY_EXIT_FAILURE 2
1798
 #endif
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
 	exit( YY_EXIT_FAILURE );
1815
 	exit( YY_EXIT_FAILURE );
1804
 }
1816
 }
1805
 
1817
 
1827
  */
1839
  */
1828
 int yyget_lineno  (void)
1840
 int yyget_lineno  (void)
1829
 {
1841
 {
1830
-        
1842
+    
1831
     return yylineno;
1843
     return yylineno;
1832
 }
1844
 }
1833
 
1845
 
1850
 /** Get the length of the current token.
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
         return yyleng;
1867
         return yyleng;
1856
 }
1868
 }
1865
 }
1877
 }
1866
 
1878
 
1867
 /** Set the current line number.
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
 /** Set the input stream. This does not discard the current
1889
 /** Set the input stream. This does not discard the current
1878
  * input buffer.
1890
  * input buffer.
1879
- * @param in_str A readable stream.
1891
+ * @param _in_str A readable stream.
1880
  * 
1892
  * 
1881
  * @see yy_switch_to_buffer
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
 int yyget_debug  (void)
1905
 int yyget_debug  (void)
1895
         return yy_flex_debug;
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
 static int yy_init_globals (void)
1915
 static int yy_init_globals (void)
1906
      * This function is called from yylex_destroy(), so don't allocate here.
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
     (yy_buffer_stack_top) = 0;
1922
     (yy_buffer_stack_top) = 0;
1911
     (yy_buffer_stack_max) = 0;
1923
     (yy_buffer_stack_max) = 0;
1912
-    (yy_c_buf_p) = (char *) 0;
1924
+    (yy_c_buf_p) = NULL;
1913
     (yy_init) = 0;
1925
     (yy_init) = 0;
1914
     (yy_start) = 0;
1926
     (yy_start) = 0;
1915
 
1927
 
1918
     yyin = stdin;
1930
     yyin = stdin;
1919
     yyout = stdout;
1931
     yyout = stdout;
1920
 #else
1932
 #else
1921
-    yyin = (FILE *) 0;
1922
-    yyout = (FILE *) 0;
1933
+    yyin = NULL;
1934
+    yyout = NULL;
1923
 #endif
1935
 #endif
1924
 
1936
 
1925
     /* For future reference: Set errno on error, since we are called by
1937
     /* For future reference: Set errno on error, since we are called by
1957
 #ifndef yytext_ptr
1969
 #ifndef yytext_ptr
1958
 static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
1970
 static void yy_flex_strncpy (char* s1, yyconst char * s2, int n )
1959
 {
1971
 {
1960
-	register int i;
1972
+		
1973
+	int i;
1961
 	for ( i = 0; i < n; ++i )
1974
 	for ( i = 0; i < n; ++i )
1962
 		s1[i] = s2[i];
1975
 		s1[i] = s2[i];
1963
 }
1976
 }
1966
 #ifdef YY_NEED_STRLEN
1979
 #ifdef YY_NEED_STRLEN
1967
 static int yy_flex_strlen (yyconst char * s )
1980
 static int yy_flex_strlen (yyconst char * s )
1968
 {
1981
 {
1969
-	register int n;
1982
+	int n;
1970
 	for ( n = 0; s[n]; ++n )
1983
 	for ( n = 0; s[n]; ++n )
1971
 		;
1984
 		;
1972
 
1985
 
1976
 
1989
 
1977
 void *yyalloc (yy_size_t  size )
1990
 void *yyalloc (yy_size_t  size )
1978
 {
1991
 {
1979
-	return (void *) malloc( size );
1992
+			return malloc(size);
1980
 }
1993
 }
1981
 
1994
 
1982
 void *yyrealloc  (void * ptr, yy_size_t  size )
1995
 void *yyrealloc  (void * ptr, yy_size_t  size )
1983
 {
1996
 {
1997
+		
1984
 	/* The cast to (char *) in the following accommodates both
1998
 	/* The cast to (char *) in the following accommodates both
1985
 	 * implementations that use char* generic pointers, and those
1999
 	 * implementations that use char* generic pointers, and those
1986
 	 * that use void* generic pointers.  It works with the latter
2000
 	 * that use void* generic pointers.  It works with the latter
1988
 	 * any pointer type to void*, and deal with argument conversions
2002
 	 * any pointer type to void*, and deal with argument conversions
1989
 	 * as though doing an assignment.
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
 void yyfree (void * ptr )
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
 #define YYTABLES_NAME "yytables"
2013
 #define YYTABLES_NAME "yytables"

+ 11 - 6
tac/list.c

51
   return head;
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
   ENV* n_env = (ENV*) malloc(sizeof(ENV));
55
   ENV* n_env = (ENV*) malloc(sizeof(ENV));
56
   if (n_env == NULL) {
56
   if (n_env == NULL) {
57
     perror("Failed to create environment");
57
     perror("Failed to create environment");
59
   }
59
   }
60
   n_env->bindings = NULL;
60
   n_env->bindings = NULL;
61
   n_env->parent = env;
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
   return n_env;
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
   BIND* n_bind = (BIND*) malloc(sizeof(BIND));
70
   BIND* n_bind = (BIND*) malloc(sizeof(BIND));
67
   if (n_bind == NULL) {
71
   if (n_bind == NULL) {
68
     perror("Failed to create binding: ");
72
     perror("Failed to create binding: ");
69
     exit(1);
73
     exit(1);
70
   }
74
   }
71
   n_bind->name = name;
75
   n_bind->name = name;
72
-  n_bind->tree = tree;
76
+  n_bind->env_offset = sp_offset;
73
   n_bind->env  = env_ptr;
77
   n_bind->env  = env_ptr;
78
+  n_bind->is_saved = 0;
74
 
79
 
75
   return n_bind;
80
   return n_bind;
76
 }
81
 }
83
   ptr->next = create_list(binding, NULL);
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
   BLIST *ptr = head;
92
   BLIST *ptr = head;
88
   while (ptr != NULL) {
93
   while (ptr != NULL) {
89
-    if (strcmp(ptr->binding->name, name) == 0) {
94
+    if (name == ptr->binding->name) {
90
       return ptr->binding;
95
       return ptr->binding;
91
     }
96
     }
92
     ptr = ptr->next;
97
     ptr = ptr->next;
94
   return NULL;
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
     BIND* ptr = NULL;
103
     BIND* ptr = NULL;
99
     ENV* env_ptr = env;
104
     ENV* env_ptr = env;
100
     while (env_ptr != NULL && 
105
     while (env_ptr != NULL && 

+ 4 - 4
tac/list.h

3
 #include "types.h"
3
 #include "types.h"
4
 
4
 
5
 BLIST* create_list(BIND*, BLIST*);
5
 BLIST* create_list(BIND*, BLIST*);
6
-BIND* create_binding(char*, NODE*, ENV*);
6
+BIND* create_binding(TOKEN*, int, ENV*);
7
 void append_list(BLIST*, BIND*);
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
 void add_tac(TLIST*, int, TOKEN*, TOKEN*, TOKEN*);
11
 void add_tac(TLIST*, int, TOKEN*, TOKEN*, TOKEN*);
12
 TAC_T* create_tac(int, TOKEN*, TOKEN*, TOKEN*);
12
 TAC_T* create_tac(int, TOKEN*, TOKEN*, TOKEN*);
13
 TLIST* new_tac_list(TAC_T*, TLIST*);
13
 TLIST* new_tac_list(TAC_T*, TLIST*);

+ 188 - 95
tac/main.c

7
 #include "types.h"
7
 #include "types.h"
8
 #include "list.h"
8
 #include "list.h"
9
 
9
 
10
+int debug = 0;
11
+
10
 extern TOKEN* lookup_token(char*);
12
 extern TOKEN* lookup_token(char*);
11
 
13
 
12
 TOKEN* gen_tmp(void) {
14
 TOKEN* gen_tmp(void) {
119
   return tok->lexeme;
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
 void print_tac(TLIST* tac_list) {
143
 void print_tac(TLIST* tac_list) {
123
   TLIST *ptr = tac_list;
144
   TLIST *ptr = tac_list;
124
 
145
 
125
   while (ptr != NULL) {
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
     ptr = ptr->next;
148
     ptr = ptr->next;
143
   }
149
   }
144
 }
150
 }
271
       NODE **val_list;
277
       NODE **val_list;
272
       num_args = count_args(tree->right);
278
       num_args = count_args(tree->right);
273
       val_list = get_val_list(tree->right);
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
       for (int i = 0; i < num_args; i++) {
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
     new_tac(tac, (TOKEN*) tree->left->left, NULL, ret_val, APPLY);
288
     new_tac(tac, (TOKEN*) tree->left->left, NULL, ret_val, APPLY);
289
 
298
 
290
 int tmp_regs[10] = {8, 9, 10, 11, 12, 13, 14, 15, 24, 25};
299
 int tmp_regs[10] = {8, 9, 10, 11, 12, 13, 14, 15, 24, 25};
291
 int svd_regs[8]  = {16, 17, 18, 19, 20, 21, 22, 23};
300
 int svd_regs[8]  = {16, 17, 18, 19, 20, 21, 22, 23};
301
+int arg_regs[3] = {5, 6, 7};
292
 int tmp_cntr = 0;
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
 void compile_tac(TLIST* tacs) {
342
 void compile_tac(TLIST* tacs) {
343
+  ENV* env = create_new_function_env(NULL, NULL);
355
   printf("=====\n");
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
   while(tacs != NULL) {
352
   while(tacs != NULL) {
358
     TAC_T* t = tacs->elem;
353
     TAC_T* t = tacs->elem;
354
+    if (debug) {
355
+      printf("#");
356
+      print_tac_el(t);
357
+    }
359
     if (t->op == '=') {
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
     if (t->op == 'D') {
363
     if (t->op == 'D') {
364
+      env = create_new_function_env(NULL, env);
364
       printf("%s:\n", t->dst->lexeme);
365
       printf("%s:\n", t->dst->lexeme);
366
+      printf("sw $ra, 64($fp)\n");
365
     }
367
     }
366
     if (t->op == '+') {
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
     if (t->op == '-') {
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
     if (t->op == '*') {
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
     if (t->op == '/') {
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
     if (t->op == '%') {
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
     if (t->op == RETURN) {
472
     if (t->op == RETURN) {
395
-      int src_idx = alloc_register(t->src);
473
+      int src_idx = register_me(t->src, env);
396
       printf("or $v1, $0, $%d\n", src_idx);
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
     tacs = tacs->next;
490
     tacs = tacs->next;
399
   }
491
   }
400
-  printf("ori $v0, 10\n");
492
+  printf("done:\n");
493
+  printf("ori $v0, $0, 10\n");
401
   printf("syscall\n");
494
   printf("syscall\n");
402
 }
495
 }
403
 
496
 
418
 int main(int argc, char** argv)
511
 int main(int argc, char** argv)
419
 {
512
 {
420
     NODE* tree;
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
     init_symbtable();
515
     init_symbtable();
423
     printf("--C COMPILER\n");
516
     printf("--C COMPILER\n");
424
     yyparse();
517
     yyparse();

+ 54 - 0
tac/mips.asm

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

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

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
-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
 int main() {
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
   } else {
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
+j main
2
+blah:
3
+ori $8, $0, 6
4
+or $v1, $0, $8
5
+jr $31
1
 main:
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
 ori $v0, 10
26
 ori $v0, 10
18
 syscall
27
 syscall

+ 8 - 2
tac/types.h

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