Imported from ../lua-3.0.tar.gz.
[lua.git] / src / parser.c
blobad5f8d68ceb68db8ee8102baf2fa8b288f0e2564
1 #ifndef lint
2 static char luaY_sccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
3 #endif
4 #define YYBYACC 1
5 #define YYMAJOR 1
6 #define YYMINOR 9
7 #define luaY_clearin (luaY_char=(-1))
8 #define luaY_errok (luaY_errflag=0)
9 #define YYRECOVERING (luaY_errflag!=0)
10 #define YYPREFIX "luaY_"
11 #line 2 "lua.stx"
13 char *rcs_luastx = "$Id: parser.c,v 1.1 1997/06/30 18:59:03 lhf Exp $";
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
19 #include "luadebug.h"
20 #include "luamem.h"
21 #include "lex.h"
22 #include "opcode.h"
23 #include "hash.h"
24 #include "inout.h"
25 #include "tree.h"
26 #include "table.h"
27 #include "lua.h"
28 #include "func.h"
30 /* to avoid warnings generated by yacc */
31 int luaY_parse (void);
32 #define malloc luaI_malloc
33 #define realloc luaI_realloc
34 #define free luaI_free
36 #ifndef LISTING
37 #define LISTING 0
38 #endif
40 #ifndef CODE_BLOCK
41 #define CODE_BLOCK 256
42 #endif
43 static int maxcode;
44 static int maxmain;
45 static int maxcurr;
46 static Byte *funcCode = NULL;
47 static Byte **initcode;
48 static Byte *basepc;
49 static int maincode;
50 static int pc;
53 #define MAXVAR 32
54 static Long varbuffer[MAXVAR]; /* variables in an assignment list;
55 it's long to store negative Word values */
56 static int nvarbuffer=0; /* number of variables at a list */
58 #define MAXLOCALS 32
59 static TaggedString *localvar[MAXLOCALS]; /* store local variable names */
60 static int nlocalvar=0; /* number of local variables */
62 #define MAXFIELDS FIELDS_PER_FLUSH*2
64 int lua_debug = 0;
66 /* Internal functions */
68 static void luaY_error (char *s)
70 luaI_syntaxerror(s);
73 static void check_space (int i)
75 if (pc+i>maxcurr-1) /* 1 byte free to code HALT of main code */
76 maxcurr = growvector(&basepc, maxcurr, Byte, codeEM, MAX_INT);
79 static void code_byte (Byte c)
81 check_space(1);
82 basepc[pc++] = c;
85 static void code_word (Word n)
87 check_space(sizeof(Word));
88 memcpy(basepc+pc, &n, sizeof(Word));
89 pc += sizeof(Word);
92 static void code_float (real n)
94 check_space(sizeof(real));
95 memcpy(basepc+pc, &n, sizeof(real));
96 pc += sizeof(real);
99 static void code_code (TFunc *tf)
101 check_space(sizeof(TFunc *));
102 memcpy(basepc+pc, &tf, sizeof(TFunc *));
103 pc += sizeof(TFunc *);
106 static void code_word_at (Byte *p, int n)
108 Word w = n;
109 if (w != n)
110 luaY_error("block too big");
111 memcpy(p, &w, sizeof(Word));
114 static void flush_record (int n)
116 if (n == 0) return;
117 code_byte(STOREMAP);
118 code_byte(n);
121 static void flush_list (int m, int n)
123 if (n == 0) return;
124 if (m == 0)
125 code_byte(STORELIST0);
126 else
127 if (m < 255)
129 code_byte(STORELIST);
130 code_byte(m);
132 else
133 luaY_error ("list constructor too long");
134 code_byte(n);
137 static void store_localvar (TaggedString *name, int n)
139 if (nlocalvar+n < MAXLOCALS)
140 localvar[nlocalvar+n] = name;
141 else
142 luaY_error ("too many local variables");
143 if (lua_debug)
144 luaI_registerlocalvar(name, lua_linenumber);
147 static void add_localvar (TaggedString *name)
149 store_localvar(name, 0);
150 nlocalvar++;
153 static void add_varbuffer (Long var)
155 if (nvarbuffer < MAXVAR)
156 varbuffer[nvarbuffer++] = var;
157 else
158 luaY_error ("variable buffer overflow");
161 static void code_string (Word w)
163 code_byte(PUSHSTRING);
164 code_word(w);
167 static void code_constant (TaggedString *s)
169 code_string(luaI_findconstant(s));
172 static void code_number (float f)
174 Word i;
175 if (f >= 0 && f <= (float)MAX_WORD && (float)(i=(Word)f) == f) {
176 /* f has an (short) integer value */
177 if (i <= 2) code_byte(PUSH0 + i);
178 else if (i <= 255)
180 code_byte(PUSHBYTE);
181 code_byte(i);
183 else
185 code_byte(PUSHWORD);
186 code_word(i);
189 else
191 code_byte(PUSHFLOAT);
192 code_float(f);
197 ** Search a local name and if find return its index. If do not find return -1
199 static int lua_localname (TaggedString *n)
201 int i;
202 for (i=nlocalvar-1; i >= 0; i--)
203 if (n == localvar[i]) return i; /* local var */
204 return -1; /* global var */
208 ** Push a variable given a number. If number is positive, push global variable
209 ** indexed by (number -1). If negative, push local indexed by ABS(number)-1.
210 ** Otherwise, if zero, push indexed variable (record).
212 static void lua_pushvar (Long number)
214 if (number > 0) /* global var */
216 code_byte(PUSHGLOBAL);
217 code_word(number-1);
219 else if (number < 0) /* local var */
221 number = (-number) - 1;
222 if (number < 10) code_byte(PUSHLOCAL0 + number);
223 else
225 code_byte(PUSHLOCAL);
226 code_byte(number);
229 else
231 code_byte(PUSHINDEXED);
235 static void lua_codeadjust (int n)
237 if (n+nlocalvar == 0)
238 code_byte(ADJUST0);
239 else
241 code_byte(ADJUST);
242 code_byte(n+nlocalvar);
246 static void change2main (void)
248 /* (re)store main values */
249 pc=maincode; basepc=*initcode; maxcurr=maxmain;
250 nlocalvar=0;
253 static void savemain (void)
255 /* save main values */
256 maincode=pc; *initcode=basepc; maxmain=maxcurr;
259 static void init_func (void)
261 if (funcCode == NULL) /* first function */
263 funcCode = newvector(CODE_BLOCK, Byte);
264 maxcode = CODE_BLOCK;
266 savemain(); /* save main values */
267 /* set func values */
268 pc=0; basepc=funcCode; maxcurr=maxcode;
269 nlocalvar = 0;
270 luaI_codedebugline(lua_linenumber);
273 static void codereturn (void)
275 if (nlocalvar == 0)
276 code_byte(RETCODE0);
277 else
279 code_byte(RETCODE);
280 code_byte(nlocalvar);
284 void luaI_codedebugline (int line)
286 static int lastline = 0;
287 if (lua_debug && line != lastline)
289 code_byte(SETLINE);
290 code_word(line);
291 lastline = line;
295 static int adjust_functioncall (Long exp, int i)
297 if (exp <= 0)
298 return -exp; /* exp is -list length */
299 else
301 int temp = basepc[exp];
302 basepc[exp] = i;
303 return temp+i;
307 static void adjust_mult_assign (int vars, Long exps, int temps)
309 if (exps > 0)
310 { /* must correct function call */
311 int diff = vars - basepc[exps];
312 if (diff >= 0)
313 adjust_functioncall(exps, diff);
314 else
316 adjust_functioncall(exps, 0);
317 lua_codeadjust(temps);
320 else if (vars != -exps)
321 lua_codeadjust(temps);
324 static int close_parlist (int dots)
326 if (!dots)
327 lua_codeadjust(0);
328 else
330 code_byte(VARARGS);
331 code_byte(nlocalvar);
332 add_localvar(luaI_createfixedstring("arg"));
334 return lua_linenumber;
337 static void storesinglevar (Long v)
339 if (v > 0) /* global var */
341 code_byte(STOREGLOBAL);
342 code_word(v-1);
344 else if (v < 0) /* local var */
346 int number = (-v) - 1;
347 if (number < 10) code_byte(STORELOCAL0 + number);
348 else
350 code_byte(STORELOCAL);
351 code_byte(number);
354 else
355 code_byte(STOREINDEXED0);
358 static void lua_codestore (int i)
360 if (varbuffer[i] != 0) /* global or local var */
361 storesinglevar(varbuffer[i]);
362 else /* indexed var */
364 int j;
365 int upper=0; /* number of indexed variables upper */
366 int param; /* number of itens until indexed expression */
367 for (j=i+1; j <nvarbuffer; j++)
368 if (varbuffer[j] == 0) upper++;
369 param = upper*2 + i;
370 if (param == 0)
371 code_byte(STOREINDEXED0);
372 else
374 code_byte(STOREINDEXED);
375 code_byte(param);
380 static void codeIf (Long thenAdd, Long elseAdd)
382 Long elseinit = elseAdd+sizeof(Word)+1;
383 if (pc == elseinit) /* no else */
385 pc -= sizeof(Word)+1;
386 elseinit = pc;
388 else
390 basepc[elseAdd] = JMP;
391 code_word_at(basepc+elseAdd+1, pc-elseinit);
393 basepc[thenAdd] = IFFJMP;
394 code_word_at(basepc+thenAdd+1,elseinit-(thenAdd+sizeof(Word)+1));
399 ** Parse LUA code.
401 void lua_parse (TFunc *tf)
403 initcode = &(tf->code);
404 *initcode = newvector(CODE_BLOCK, Byte);
405 maincode = 0;
406 maxmain = CODE_BLOCK;
407 change2main();
408 if (luaY_parse ()) lua_error("parse error");
409 savemain();
410 (*initcode)[maincode++] = RETCODE0;
411 tf->size = maincode;
412 #if LISTING
413 { static void PrintCode (Byte *c, Byte *end);
414 PrintCode(*initcode,*initcode+maincode); }
415 #endif
419 #line 412 "lua.stx"
420 typedef union
422 int vInt;
423 float vFloat;
424 char *pChar;
425 Word vWord;
426 Long vLong;
427 TFunc *pFunc;
428 TaggedString *pTStr;
429 } YYSTYPE;
430 #line 431 "y.tab.c"
431 #define WRONGTOKEN 257
432 #define NIL 258
433 #define IF 259
434 #define THEN 260
435 #define ELSE 261
436 #define ELSEIF 262
437 #define WHILE 263
438 #define DO 264
439 #define REPEAT 265
440 #define UNTIL 266
441 #define END 267
442 #define RETURN 268
443 #define LOCAL 269
444 #define FUNCTION 270
445 #define DOTS 271
446 #define NUMBER 272
447 #define STRING 273
448 #define NAME 274
449 #define AND 275
450 #define OR 276
451 #define EQ 277
452 #define NE 278
453 #define LE 279
454 #define GE 280
455 #define CONC 281
456 #define UNARY 282
457 #define NOT 283
458 #define YYERRCODE 256
459 short luaY_lhs[] = { -1,
460 0, 24, 24, 24, 28, 22, 22, 23, 31, 31,
461 27, 27, 26, 34, 26, 35, 26, 26, 26, 26,
462 33, 33, 33, 36, 30, 25, 25, 1, 32, 5,
463 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
464 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
465 38, 5, 39, 5, 40, 37, 4, 8, 8, 7,
466 7, 2, 2, 3, 41, 3, 17, 17, 18, 18,
467 19, 19, 42, 9, 9, 14, 14, 43, 43, 12,
468 12, 13, 13, 44, 45, 45, 15, 15, 16, 16,
469 6, 6, 20, 20, 20, 21, 29, 10, 10, 11,
472 short luaY_len[] = { 2,
473 2, 0, 3, 2, 3, 1, 3, 5, 0, 3,
474 0, 1, 8, 0, 8, 0, 6, 3, 1, 3,
475 0, 2, 7, 0, 3, 0, 3, 0, 1, 3,
476 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
477 3, 3, 2, 1, 1, 1, 1, 1, 1, 2,
478 0, 5, 0, 5, 0, 4, 2, 1, 3, 3,
479 1, 0, 1, 1, 0, 4, 0, 1, 1, 3,
480 1, 1, 0, 3, 2, 0, 2, 0, 1, 0,
481 2, 1, 3, 3, 3, 1, 0, 2, 1, 3,
482 1, 3, 1, 4, 3, 1, 1, 1, 3, 0,
485 short luaY_defred[] = { 2,
486 0, 0, 0, 14, 16, 0, 0, 0, 96, 19,
487 0, 0, 0, 93, 1, 0, 4, 0, 48, 46,
488 47, 0, 0, 0, 49, 29, 97, 0, 0, 44,
489 0, 0, 24, 0, 0, 0, 0, 98, 0, 0,
490 0, 0, 0, 0, 0, 57, 61, 12, 3, 0,
491 0, 0, 0, 0, 0, 28, 28, 28, 0, 0,
492 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
493 0, 0, 0, 9, 27, 65, 0, 0, 20, 0,
494 5, 0, 0, 0, 0, 0, 59, 0, 95, 30,
495 24, 51, 53, 0, 0, 0, 0, 0, 0, 0,
496 0, 0, 0, 0, 0, 0, 0, 0, 0, 73,
497 0, 0, 82, 0, 28, 0, 0, 0, 0, 99,
498 72, 71, 0, 0, 69, 7, 60, 94, 28, 0,
499 0, 0, 56, 0, 75, 0, 0, 88, 0, 24,
500 0, 25, 0, 0, 24, 0, 0, 0, 0, 85,
501 86, 83, 0, 74, 0, 0, 28, 17, 10, 0,
502 70, 24, 0, 0, 77, 0, 0, 8, 22, 0,
503 13, 81, 15, 28, 24, 28, 0, 23,
505 short luaY_dgoto[] = { 1,
506 91, 34, 35, 25, 26, 11, 46, 12, 108, 39,
507 79, 165, 109, 154, 110, 111, 123, 124, 125, 27,
508 14, 41, 81, 2, 15, 16, 49, 17, 28, 73,
509 117, 37, 164, 32, 33, 74, 30, 130, 131, 31,
510 118, 136, 135, 113, 114,
512 short luaY_sindex[] = { 0,
513 0, 288, -34, 0, 0, -34, -238, -223, 0, 0,
514 -6, 22, 0, 0, 0, 14, 0, 150, 0, 0,
515 0, -34, -34, -34, 0, 0, 0, 150, 547, 0,
516 -46, -34, 0, 14, 34, 0, 212, 0, -5, 0,
517 39, 156, -34, -223, -34, 0, 0, 0, 0, -194,
518 -34, -193, -4, -4, 48, 0, 0, 0, -34, -34,
519 -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
520 -38, 481, -173, 0, 0, 0, -34, -146, 0, -234,
521 0, -138, 34, 0, -15, 96, 0, 753, 0, 0,
522 0, 0, 0, -30, -30, -30, -30, -30, -30, -20,
523 -12, -12, -4, -4, -4, 0, -34, 16, 95, 0,
524 98, 212, 0, 82, 0, -34, 328, -34, 34, 0,
525 0, 0, 103, 101, 0, 0, 0, 0, 0, -34,
526 -34, 1181, 0, -91, 0, 92, -34, 0, -34, 0,
527 212, 0, 14, 0, 0, -234, -233, 118, 118, 0,
528 0, 0, -91, 0, 212, 212, 0, 0, 0, -105,
529 0, 0, -34, -103, 0, 95, -101, 0, 0, 1105,
530 0, 0, 0, 0, 0, 0, -233, 0,
532 short luaY_rindex[] = { 0,
533 0, 169, 52, 0, 0, 173, 0, 0, 0, 0,
534 0, 52, 508, 0, 0, 146, 0, -36, 0, 0,
535 0, 52, 52, 52, 0, 0, 0, 1, 0, 0,
536 0, 52, 0, 47, 461, 436, 0, 0, 197, 76,
537 0, 0, 52, 0, -32, 0, 0, 0, 0, 0,
538 52, 0, 24, 59, 1195, 0, 0, 0, 52, 52,
539 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
540 -27, 0, 0, 0, 0, 0, 52, 0, 0, 129,
541 0, 0, 311, 142, 0, 0, 0, 0, 0, 0,
542 0, 0, 0, 746, 776, 799, 821, 844, 866, 505,
543 383, 410, 88, 112, 359, 1174, 52, 0, 51, 0,
544 -40, -10, 0, 0, 0, 52, -153, 52, 921, 0,
545 0, 0, 0, 144, 0, 0, 0, 0, 0, 52,
546 52, 0, 0, 62, 0, 64, -26, 0, 52, 0,
547 939, 0, 682, 474, 0, 0, -77, 894, 1137, 0,
548 0, 0, 66, 0, 13, -18, 0, 0, 0, 0,
549 0, 0, 52, 0, 0, 51, 0, 0, 0, 0,
550 0, 0, 0, 0, 0, 0, -77, 0,
552 short luaY_gindex[] = { 0,
553 53, 147, -23, 3, 134, 0, 0, 0, 0, 0,
554 0, 0, 40, 0, 0, 0, 0, 0, 49, 6,
555 0, 0, 0, 0, 81, 83, -16, 0, 8, -70,
556 0, 1445, 27, 0, 0, 0, 187, 0, 0, 0,
557 0, 0, -108, 67, 0,
559 #define YYTABLESIZE 1608
560 short luaY_table[] = { 107,
561 45, 24, 138, 58, 10, 24, 22, 13, 62, 18,
562 22, 68, 66, 40, 67, 42, 69, 75, 78, 83,
563 129, 68, 66, 43, 67, 84, 69, 162, 163, 68,
564 52, 87, 79, 89, 69, 38, 121, 44, 78, 122,
565 58, 45, 45, 45, 45, 45, 11, 45, 89, 84,
566 9, 85, 107, 119, 43, 77, 90, 172, 50, 45,
567 45, 45, 45, 70, 43, 43, 43, 43, 43, 157,
568 43, 90, 48, 70, 160, 51, 71, 76, 80, 87,
569 89, 70, 43, 43, 78, 43, 58, 39, 90, 70,
570 55, 169, 116, 45, 45, 55, 55, 87, 79, 50,
571 50, 50, 50, 50, 176, 50, 84, 26, 26, 92,
572 93, 40, 26, 26, 89, 6, 43, 50, 50, 10,
573 50, 97, 13, 58, 18, 45, 159, 120, 39, 39,
574 39, 39, 39, 97, 39, 126, 127, 90, 134, 36,
575 133, 137, 139, 145, 146, 11, 39, 39, 43, 39,
576 153, 50, 40, 40, 40, 40, 40, 55, 40, 68,
577 66, 168, 67, 171, 69, 173, 97, 140, 26, 67,
578 40, 40, 62, 40, 55, 78, 36, 62, 36, 61,
579 39, 147, 151, 50, 68, 92, 79, 97, 76, 21,
580 80, 86, 166, 158, 161, 52, 100, 142, 47, 143,
581 152, 52, 92, 178, 40, 0, 0, 50, 0, 167,
582 36, 70, 39, 82, 0, 0, 0, 0, 0, 19,
583 0, 0, 0, 19, 0, 0, 175, 0, 177, 0,
584 0, 62, 97, 20, 21, 106, 40, 20, 21, 9,
585 51, 0, 0, 0, 23, 0, 51, 0, 23, 0,
586 65, 144, 0, 68, 66, 100, 67, 0, 69, 45,
587 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
588 45, 62, 0, 61, 45, 45, 45, 45, 45, 45,
589 45, 45, 43, 43, 43, 43, 43, 43, 43, 43,
590 43, 43, 43, 43, 0, 55, 0, 43, 43, 43,
591 43, 43, 43, 43, 43, 70, 0, 11, 11, 0,
592 18, 0, 11, 11, 0, 0, 0, 50, 50, 50,
593 50, 50, 50, 50, 50, 50, 50, 50, 50, 0,
594 0, 0, 50, 50, 50, 50, 50, 50, 50, 50,
595 0, 0, 0, 0, 0, 0, 39, 39, 39, 39,
596 39, 39, 39, 39, 39, 39, 39, 39, 41, 0,
597 0, 39, 39, 39, 39, 39, 39, 39, 39, 18,
598 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
599 40, 40, 37, 0, 0, 40, 40, 40, 40, 40,
600 40, 40, 40, 0, 59, 60, 63, 64, 65, 41,
601 41, 41, 41, 41, 11, 41, 0, 0, 11, 38,
602 11, 0, 0, 11, 11, 11, 0, 41, 41, 11,
603 41, 0, 0, 37, 0, 37, 37, 37, 0, 0,
604 0, 0, 0, 62, 62, 64, 0, 0, 62, 62,
605 0, 37, 37, 0, 37, 0, 0, 0, 0, 0,
606 38, 41, 38, 38, 38, 100, 0, 100, 100, 100,
607 63, 100, 100, 100, 100, 100, 100, 0, 38, 38,
608 100, 38, 0, 66, 0, 37, 64, 29, 29, 64,
609 29, 0, 29, 41, 0, 0, 57, 58, 59, 60,
610 63, 64, 65, 0, 64, 29, 0, 29, 0, 0,
611 0, 63, 38, 0, 42, 0, 0, 37, 0, 0,
612 0, 0, 0, 0, 66, 29, 29, 66, 29, 63,
613 29, 0, 68, 66, 0, 67, 0, 69, 0, 29,
614 0, 0, 66, 29, 38, 29, 0, 0, 0, 0,
615 62, 0, 61, 0, 0, 42, 3, 97, 42, 0,
616 4, 91, 5, 97, 0, 6, 7, 8, 0, 0,
617 0, 9, 0, 42, 42, 97, 42, 29, 91, 18,
618 0, 18, 18, 18, 70, 18, 18, 18, 18, 18,
619 18, 0, 0, 0, 18, 0, 3, 0, 68, 66,
620 4, 67, 5, 69, 0, 6, 7, 42, 97, 0,
621 0, 9, 0, 0, 0, 0, 62, 0, 61, 0,
622 0, 0, 0, 0, 0, 0, 0, 41, 41, 41,
623 41, 41, 41, 41, 41, 41, 41, 41, 41, 42,
624 97, 0, 41, 41, 41, 41, 41, 41, 41, 41,
625 70, 37, 37, 37, 37, 37, 37, 37, 37, 37,
626 37, 37, 37, 0, 0, 0, 37, 37, 37, 37,
627 37, 37, 37, 37, 0, 0, 0, 0, 38, 38,
628 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
629 0, 0, 0, 38, 38, 38, 38, 38, 38, 38,
630 38, 0, 0, 0, 64, 0, 64, 64, 64, 0,
631 64, 64, 64, 64, 64, 64, 0, 0, 0, 64,
632 29, 29, 29, 29, 29, 29, 29, 0, 0, 0,
633 0, 63, 63, 0, 0, 0, 63, 63, 0, 0,
634 0, 0, 66, 0, 66, 66, 66, 0, 66, 66,
635 66, 66, 66, 66, 115, 31, 0, 66, 29, 29,
636 29, 29, 29, 29, 29, 57, 58, 59, 60, 63,
637 64, 65, 0, 42, 42, 42, 42, 42, 42, 42,
638 42, 42, 42, 42, 42, 34, 0, 0, 42, 42,
639 42, 42, 42, 42, 42, 42, 31, 0, 0, 31,
640 0, 0, 0, 0, 68, 66, 0, 67, 33, 69,
641 0, 0, 0, 0, 31, 31, 56, 31, 0, 0,
642 0, 0, 62, 0, 61, 0, 34, 0, 0, 34,
643 32, 57, 58, 59, 60, 63, 64, 65, 0, 0,
644 0, 0, 0, 0, 34, 34, 0, 34, 31, 33,
645 0, 0, 33, 35, 0, 128, 70, 0, 0, 0,
646 0, 0, 0, 0, 0, 0, 0, 33, 33, 0,
647 33, 32, 0, 0, 32, 36, 0, 0, 34, 0,
648 31, 0, 0, 0, 0, 0, 0, 0, 0, 32,
649 32, 0, 32, 0, 35, 0, 0, 35, 0, 0,
650 0, 33, 0, 52, 0, 0, 0, 0, 0, 0,
651 34, 0, 35, 35, 0, 35, 36, 0, 0, 36,
652 0, 0, 0, 32, 0, 0, 0, 0, 0, 0,
653 101, 0, 0, 33, 36, 36, 0, 36, 0, 0,
654 0, 0, 0, 0, 52, 0, 35, 52, 28, 0,
655 11, 0, 11, 11, 11, 32, 11, 11, 11, 11,
656 11, 0, 52, 0, 0, 11, 0, 0, 36, 0,
657 0, 0, 0, 0, 0, 0, 0, 0, 35, 0,
658 0, 0, 0, 0, 0, 0, 0, 0, 0, 101,
659 0, 0, 0, 0, 0, 0, 52, 0, 0, 0,
660 36, 0, 0, 0, 0, 0, 0, 28, 0, 0,
661 0, 0, 0, 0, 31, 31, 31, 31, 31, 31,
662 31, 31, 31, 31, 31, 31, 0, 0, 52, 31,
663 31, 31, 31, 31, 31, 31, 0, 57, 58, 59,
664 60, 63, 64, 65, 34, 34, 34, 34, 34, 34,
665 34, 34, 34, 34, 34, 34, 0, 0, 0, 34,
666 34, 34, 34, 34, 34, 34, 0, 33, 33, 33,
667 33, 33, 33, 33, 33, 33, 33, 33, 33, 0,
668 0, 0, 33, 33, 33, 33, 33, 33, 33, 32,
669 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
670 32, 0, 0, 0, 32, 32, 32, 32, 32, 32,
671 32, 0, 35, 35, 35, 35, 35, 35, 35, 35,
672 35, 35, 35, 35, 0, 0, 0, 35, 35, 35,
673 35, 35, 35, 35, 36, 36, 36, 36, 36, 36,
674 36, 36, 36, 36, 36, 36, 54, 0, 0, 36,
675 36, 36, 36, 36, 36, 36, 68, 66, 0, 67,
676 0, 69, 52, 52, 52, 52, 52, 52, 52, 52,
677 52, 52, 52, 52, 62, 0, 61, 52, 52, 52,
678 0, 0, 0, 0, 0, 0, 0, 54, 0, 101,
679 54, 101, 101, 101, 0, 101, 101, 101, 101, 101,
680 101, 0, 0, 0, 101, 54, 0, 28, 70, 28,
681 28, 28, 0, 28, 28, 28, 28, 28, 28, 0,
682 0, 0, 28, 96, 0, 96, 96, 96, 96, 96,
683 96, 0, 68, 66, 0, 67, 0, 69, 0, 54,
684 0, 96, 96, 96, 86, 96, 29, 29, 0, 29,
685 62, 29, 61, 0, 0, 0, 0, 0, 0, 0,
686 0, 0, 0, 0, 29, 0, 29, 0, 0, 0,
687 0, 54, 0, 0, 96, 0, 0, 96, 0, 0,
688 0, 0, 0, 150, 70, 0, 0, 0, 0, 0,
689 0, 0, 0, 0, 0, 0, 0, 0, 29, 0,
690 0, 0, 0, 0, 0, 0, 96, 0, 96, 0,
691 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
692 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
693 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
694 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
695 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
696 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
697 0, 0, 0, 0, 174, 0, 0, 0, 0, 0,
698 0, 0, 0, 0, 0, 0, 0, 0, 0, 57,
699 58, 59, 60, 63, 64, 65, 0, 0, 0, 0,
700 0, 0, 0, 0, 0, 54, 54, 54, 54, 54,
701 54, 54, 54, 54, 54, 54, 54, 0, 0, 0,
702 54, 54, 54, 0, 0, 0, 0, 0, 0, 0,
703 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
704 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
705 0, 0, 0, 0, 0, 0, 0, 29, 96, 96,
706 96, 96, 96, 96, 96, 57, 58, 59, 60, 63,
707 64, 65, 0, 0, 0, 0, 53, 54, 0, 29,
708 29, 29, 29, 29, 29, 29, 72, 0, 0, 0,
709 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
710 0, 0, 0, 0, 0, 88, 0, 0, 0, 0,
711 0, 0, 0, 94, 95, 96, 97, 98, 99, 100,
712 101, 102, 103, 104, 105, 112, 0, 0, 0, 0,
713 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
714 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
715 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
716 0, 132, 0, 0, 0, 0, 0, 0, 0, 0,
717 141, 0, 0, 0, 0, 0, 0, 0, 0, 0,
718 0, 0, 0, 0, 148, 149, 0, 0, 0, 0,
719 0, 155, 0, 156, 0, 0, 0, 0, 0, 0,
720 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
721 0, 0, 0, 0, 0, 0, 0, 170,
723 short luaY_check[] = { 91,
724 0, 40, 111, 40, 2, 40, 45, 2, 41, 2,
725 45, 42, 43, 8, 45, 8, 47, 34, 59, 43,
726 91, 42, 43, 0, 45, 44, 47, 261, 262, 42,
727 46, 59, 59, 44, 47, 274, 271, 44, 44, 274,
728 40, 41, 42, 43, 44, 45, 0, 47, 59, 44,
729 274, 44, 91, 77, 61, 61, 44, 166, 0, 59,
730 60, 40, 62, 94, 41, 42, 43, 44, 45, 140,
731 47, 59, 59, 94, 145, 91, 123, 44, 40, 274,
732 274, 94, 59, 60, 125, 62, 123, 0, 41, 94,
733 123, 162, 266, 93, 94, 123, 123, 125, 125, 41,
734 42, 43, 44, 45, 175, 47, 125, 261, 262, 57,
735 58, 0, 266, 267, 125, 40, 93, 59, 60, 117,
736 62, 46, 117, 123, 117, 125, 143, 274, 41, 42,
737 43, 44, 45, 58, 47, 274, 41, 125, 44, 6,
738 125, 44, 61, 41, 44, 0, 59, 60, 125, 62,
739 59, 93, 41, 42, 43, 44, 45, 24, 47, 42,
740 43, 267, 45, 267, 47, 267, 91, 115, 0, 41,
741 59, 60, 0, 62, 123, 125, 43, 60, 45, 62,
742 93, 129, 274, 125, 41, 44, 125, 46, 125, 267,
743 125, 45, 153, 141, 146, 46, 0, 117, 12, 117,
744 134, 46, 61, 177, 93, -1, -1, 58, -1, 157,
745 77, 94, 125, 58, -1, -1, -1, -1, -1, 258,
746 -1, -1, -1, 258, -1, -1, 174, -1, 176, -1,
747 -1, 59, 91, 272, 273, 274, 125, 272, 273, 274,
748 91, -1, -1, -1, 283, -1, 91, -1, 283, -1,
749 281, 118, -1, 42, 43, 59, 45, -1, 47, 259,
750 260, 261, 262, 263, 264, 265, 266, 267, 268, 269,
751 270, 60, -1, 62, 274, 275, 276, 277, 278, 279,
752 280, 281, 259, 260, 261, 262, 263, 264, 265, 266,
753 267, 268, 269, 270, -1, 123, -1, 274, 275, 276,
754 277, 278, 279, 280, 281, 94, -1, 261, 262, -1,
755 0, -1, 266, 267, -1, -1, -1, 259, 260, 261,
756 262, 263, 264, 265, 266, 267, 268, 269, 270, -1,
757 -1, -1, 274, 275, 276, 277, 278, 279, 280, 281,
758 -1, -1, -1, -1, -1, -1, 259, 260, 261, 262,
759 263, 264, 265, 266, 267, 268, 269, 270, 0, -1,
760 -1, 274, 275, 276, 277, 278, 279, 280, 281, 59,
761 259, 260, 261, 262, 263, 264, 265, 266, 267, 268,
762 269, 270, 0, -1, -1, 274, 275, 276, 277, 278,
763 279, 280, 281, -1, 277, 278, 279, 280, 281, 41,
764 42, 43, 44, 45, 259, 47, -1, -1, 263, 0,
765 265, -1, -1, 268, 269, 270, -1, 59, 60, 274,
766 62, -1, -1, 41, -1, 43, 44, 45, -1, -1,
767 -1, -1, -1, 261, 262, 0, -1, -1, 266, 267,
768 -1, 59, 60, -1, 62, -1, -1, -1, -1, -1,
769 41, 93, 43, 44, 45, 259, -1, 261, 262, 263,
770 0, 265, 266, 267, 268, 269, 270, -1, 59, 60,
771 274, 62, -1, 0, -1, 93, 41, 42, 43, 44,
772 45, -1, 47, 125, -1, -1, 275, 276, 277, 278,
773 279, 280, 281, -1, 59, 60, -1, 62, -1, -1,
774 -1, 41, 93, -1, 0, -1, -1, 125, -1, -1,
775 -1, -1, -1, -1, 41, 42, 43, 44, 45, 59,
776 47, -1, 42, 43, -1, 45, -1, 47, -1, 94,
777 -1, -1, 59, 60, 125, 62, -1, -1, -1, -1,
778 60, -1, 62, -1, -1, 41, 259, 40, 44, -1,
779 263, 44, 265, 46, -1, 268, 269, 270, -1, -1,
780 -1, 274, -1, 59, 60, 58, 62, 94, 61, 259,
781 -1, 261, 262, 263, 94, 265, 266, 267, 268, 269,
782 270, -1, -1, -1, 274, -1, 259, -1, 42, 43,
783 263, 45, 265, 47, -1, 268, 269, 93, 91, -1,
784 -1, 274, -1, -1, -1, -1, 60, -1, 62, -1,
785 -1, -1, -1, -1, -1, -1, -1, 259, 260, 261,
786 262, 263, 264, 265, 266, 267, 268, 269, 270, 125,
787 123, -1, 274, 275, 276, 277, 278, 279, 280, 281,
788 94, 259, 260, 261, 262, 263, 264, 265, 266, 267,
789 268, 269, 270, -1, -1, -1, 274, 275, 276, 277,
790 278, 279, 280, 281, -1, -1, -1, -1, 259, 260,
791 261, 262, 263, 264, 265, 266, 267, 268, 269, 270,
792 -1, -1, -1, 274, 275, 276, 277, 278, 279, 280,
793 281, -1, -1, -1, 259, -1, 261, 262, 263, -1,
794 265, 266, 267, 268, 269, 270, -1, -1, -1, 274,
795 275, 276, 277, 278, 279, 280, 281, -1, -1, -1,
796 -1, 261, 262, -1, -1, -1, 266, 267, -1, -1,
797 -1, -1, 259, -1, 261, 262, 263, -1, 265, 266,
798 267, 268, 269, 270, 264, 0, -1, 274, 275, 276,
799 277, 278, 279, 280, 281, 275, 276, 277, 278, 279,
800 280, 281, -1, 259, 260, 261, 262, 263, 264, 265,
801 266, 267, 268, 269, 270, 0, -1, -1, 274, 275,
802 276, 277, 278, 279, 280, 281, 41, -1, -1, 44,
803 -1, -1, -1, -1, 42, 43, -1, 45, 0, 47,
804 -1, -1, -1, -1, 59, 60, 260, 62, -1, -1,
805 -1, -1, 60, -1, 62, -1, 41, -1, -1, 44,
806 0, 275, 276, 277, 278, 279, 280, 281, -1, -1,
807 -1, -1, -1, -1, 59, 60, -1, 62, 93, 41,
808 -1, -1, 44, 0, -1, 93, 94, -1, -1, -1,
809 -1, -1, -1, -1, -1, -1, -1, 59, 60, -1,
810 62, 41, -1, -1, 44, 0, -1, -1, 93, -1,
811 125, -1, -1, -1, -1, -1, -1, -1, -1, 59,
812 60, -1, 62, -1, 41, -1, -1, 44, -1, -1,
813 -1, 93, -1, 0, -1, -1, -1, -1, -1, -1,
814 125, -1, 59, 60, -1, 62, 41, -1, -1, 44,
815 -1, -1, -1, 93, -1, -1, -1, -1, -1, -1,
816 0, -1, -1, 125, 59, 60, -1, 62, -1, -1,
817 -1, -1, -1, -1, 41, -1, 93, 44, 0, -1,
818 259, -1, 261, 262, 263, 125, 265, 266, 267, 268,
819 269, -1, 59, -1, -1, 274, -1, -1, 93, -1,
820 -1, -1, -1, -1, -1, -1, -1, -1, 125, -1,
821 -1, -1, -1, -1, -1, -1, -1, -1, -1, 59,
822 -1, -1, -1, -1, -1, -1, 93, -1, -1, -1,
823 125, -1, -1, -1, -1, -1, -1, 59, -1, -1,
824 -1, -1, -1, -1, 259, 260, 261, 262, 263, 264,
825 265, 266, 267, 268, 269, 270, -1, -1, 125, 274,
826 275, 276, 277, 278, 279, 280, -1, 275, 276, 277,
827 278, 279, 280, 281, 259, 260, 261, 262, 263, 264,
828 265, 266, 267, 268, 269, 270, -1, -1, -1, 274,
829 275, 276, 277, 278, 279, 280, -1, 259, 260, 261,
830 262, 263, 264, 265, 266, 267, 268, 269, 270, -1,
831 -1, -1, 274, 275, 276, 277, 278, 279, 280, 259,
832 260, 261, 262, 263, 264, 265, 266, 267, 268, 269,
833 270, -1, -1, -1, 274, 275, 276, 277, 278, 279,
834 280, -1, 259, 260, 261, 262, 263, 264, 265, 266,
835 267, 268, 269, 270, -1, -1, -1, 274, 275, 276,
836 277, 278, 279, 280, 259, 260, 261, 262, 263, 264,
837 265, 266, 267, 268, 269, 270, 0, -1, -1, 274,
838 275, 276, 277, 278, 279, 280, 42, 43, -1, 45,
839 -1, 47, 259, 260, 261, 262, 263, 264, 265, 266,
840 267, 268, 269, 270, 60, -1, 62, 274, 275, 276,
841 -1, -1, -1, -1, -1, -1, -1, 41, -1, 259,
842 44, 261, 262, 263, -1, 265, 266, 267, 268, 269,
843 270, -1, -1, -1, 274, 59, -1, 259, 94, 261,
844 262, 263, -1, 265, 266, 267, 268, 269, 270, -1,
845 -1, -1, 274, 40, -1, 42, 43, 44, 45, 46,
846 47, -1, 42, 43, -1, 45, -1, 47, -1, 93,
847 -1, 58, 59, 60, 61, 62, 42, 43, -1, 45,
848 60, 47, 62, -1, -1, -1, -1, -1, -1, -1,
849 -1, -1, -1, -1, 60, -1, 62, -1, -1, -1,
850 -1, 125, -1, -1, 91, -1, -1, 94, -1, -1,
851 -1, -1, -1, 93, 94, -1, -1, -1, -1, -1,
852 -1, -1, -1, -1, -1, -1, -1, -1, 94, -1,
853 -1, -1, -1, -1, -1, -1, 123, -1, 125, -1,
854 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
855 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
856 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
857 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
858 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
859 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
860 -1, -1, -1, -1, 260, -1, -1, -1, -1, -1,
861 -1, -1, -1, -1, -1, -1, -1, -1, -1, 275,
862 276, 277, 278, 279, 280, 281, -1, -1, -1, -1,
863 -1, -1, -1, -1, -1, 259, 260, 261, 262, 263,
864 264, 265, 266, 267, 268, 269, 270, -1, -1, -1,
865 274, 275, 276, -1, -1, -1, -1, -1, -1, -1,
866 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
867 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
868 -1, -1, -1, -1, -1, -1, -1, 3, 275, 276,
869 277, 278, 279, 280, 281, 275, 276, 277, 278, 279,
870 280, 281, -1, -1, -1, -1, 22, 23, -1, 275,
871 276, 277, 278, 279, 280, 281, 32, -1, -1, -1,
872 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
873 -1, -1, -1, -1, -1, 51, -1, -1, -1, -1,
874 -1, -1, -1, 59, 60, 61, 62, 63, 64, 65,
875 66, 67, 68, 69, 70, 71, -1, -1, -1, -1,
876 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
877 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
878 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
879 -1, 107, -1, -1, -1, -1, -1, -1, -1, -1,
880 116, -1, -1, -1, -1, -1, -1, -1, -1, -1,
881 -1, -1, -1, -1, 130, 131, -1, -1, -1, -1,
882 -1, 137, -1, 139, -1, -1, -1, -1, -1, -1,
883 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
884 -1, -1, -1, -1, -1, -1, -1, 163,
886 #define YYFINAL 1
887 #ifndef YYDEBUG
888 #define YYDEBUG 0
889 #endif
890 #define YYMAXTOKEN 283
891 #if YYDEBUG
892 char *luaY_name[] = {
893 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
894 0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'","'.'","'/'",0,0,0,0,0,0,0,0,0,0,
895 "':'","';'","'<'","'='","'>'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
896 0,0,0,"'['",0,"']'","'^'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
897 0,"'{'",0,"'}'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
898 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
899 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
900 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"WRONGTOKEN","NIL","IF","THEN","ELSE",
901 "ELSEIF","WHILE","DO","REPEAT","UNTIL","END","RETURN","LOCAL","FUNCTION","DOTS",
902 "NUMBER","STRING","NAME","AND","OR","EQ","NE","LE","GE","CONC","UNARY","NOT",
904 char *luaY_rule[] = {
905 "$accept : chunk",
906 "chunk : chunklist ret",
907 "chunklist :",
908 "chunklist : chunklist stat sc",
909 "chunklist : chunklist function",
910 "function : FUNCTION funcname body",
911 "funcname : var",
912 "funcname : varexp ':' NAME",
913 "body : '(' parlist ')' block END",
914 "statlist :",
915 "statlist : statlist stat sc",
916 "sc :",
917 "sc : ';'",
918 "stat : IF expr1 THEN PrepJump block PrepJump elsepart END",
919 "$$1 :",
920 "stat : WHILE $$1 expr1 DO PrepJump block PrepJump END",
921 "$$2 :",
922 "stat : REPEAT $$2 block UNTIL expr1 PrepJump",
923 "stat : varlist1 '=' exprlist1",
924 "stat : functioncall",
925 "stat : LOCAL localdeclist decinit",
926 "elsepart :",
927 "elsepart : ELSE block",
928 "elsepart : ELSEIF expr1 THEN PrepJump block PrepJump elsepart",
929 "$$3 :",
930 "block : $$3 statlist ret",
931 "ret :",
932 "ret : RETURN exprlist sc",
933 "PrepJump :",
934 "expr1 : expr",
935 "expr : '(' expr ')'",
936 "expr : expr1 EQ expr1",
937 "expr : expr1 '<' expr1",
938 "expr : expr1 '>' expr1",
939 "expr : expr1 NE expr1",
940 "expr : expr1 LE expr1",
941 "expr : expr1 GE expr1",
942 "expr : expr1 '+' expr1",
943 "expr : expr1 '-' expr1",
944 "expr : expr1 '*' expr1",
945 "expr : expr1 '/' expr1",
946 "expr : expr1 '^' expr1",
947 "expr : expr1 CONC expr1",
948 "expr : '-' expr1",
949 "expr : table",
950 "expr : varexp",
951 "expr : NUMBER",
952 "expr : STRING",
953 "expr : NIL",
954 "expr : functioncall",
955 "expr : NOT expr1",
956 "$$4 :",
957 "expr : expr1 AND PrepJump $$4 expr1",
958 "$$5 :",
959 "expr : expr1 OR PrepJump $$5 expr1",
960 "$$6 :",
961 "table : $$6 '{' fieldlist '}'",
962 "functioncall : funcvalue funcParams",
963 "funcvalue : varexp",
964 "funcvalue : varexp ':' NAME",
965 "funcParams : '(' exprlist ')'",
966 "funcParams : table",
967 "exprlist :",
968 "exprlist : exprlist1",
969 "exprlist1 : expr",
970 "$$7 :",
971 "exprlist1 : exprlist1 ',' $$7 expr",
972 "parlist :",
973 "parlist : parlist1",
974 "parlist1 : par",
975 "parlist1 : parlist1 ',' par",
976 "par : NAME",
977 "par : DOTS",
978 "$$8 :",
979 "fieldlist : lfieldlist $$8 semicolonpart",
980 "fieldlist : ffieldlist1 lastcomma",
981 "semicolonpart :",
982 "semicolonpart : ';' ffieldlist",
983 "lastcomma :",
984 "lastcomma : ','",
985 "ffieldlist :",
986 "ffieldlist : ffieldlist1 lastcomma",
987 "ffieldlist1 : ffield",
988 "ffieldlist1 : ffieldlist1 ',' ffield",
989 "ffield : ffieldkey '=' expr1",
990 "ffieldkey : '[' expr1 ']'",
991 "ffieldkey : NAME",
992 "lfieldlist :",
993 "lfieldlist : lfieldlist1 lastcomma",
994 "lfieldlist1 : expr1",
995 "lfieldlist1 : lfieldlist1 ',' expr1",
996 "varlist1 : var",
997 "varlist1 : varlist1 ',' var",
998 "var : singlevar",
999 "var : varexp '[' expr1 ']'",
1000 "var : varexp '.' NAME",
1001 "singlevar : NAME",
1002 "varexp : var",
1003 "localdeclist : NAME",
1004 "localdeclist : localdeclist ',' NAME",
1005 "decinit :",
1006 "decinit : '=' exprlist1",
1008 #endif
1009 #ifdef YYSTACKSIZE
1010 #undef YYMAXDEPTH
1011 #define YYMAXDEPTH YYSTACKSIZE
1012 #else
1013 #ifdef YYMAXDEPTH
1014 #define YYSTACKSIZE YYMAXDEPTH
1015 #else
1016 #define YYSTACKSIZE 500
1017 #define YYMAXDEPTH 500
1018 #endif
1019 #endif
1020 int luaY_debug;
1021 int luaY_nerrs;
1022 int luaY_errflag;
1023 int luaY_char;
1024 short *luaY_ssp;
1025 YYSTYPE *luaY_vsp;
1026 YYSTYPE luaY_val;
1027 YYSTYPE luaY_lval;
1028 short luaY_ss[YYSTACKSIZE];
1029 YYSTYPE luaY_vs[YYSTACKSIZE];
1030 #define luaY_stacksize YYSTACKSIZE
1031 #define YYABORT goto luaY_abort
1032 #define YYREJECT goto luaY_abort
1033 #define YYACCEPT goto luaY_accept
1034 #define YYERROR goto luaY_errlab
1036 luaY_parse()
1038 register int luaY_m, luaY_n, luaY_state;
1039 #if YYDEBUG
1040 register char *luaY_s;
1041 extern char *getenv();
1043 if (luaY_s = getenv("YYDEBUG"))
1045 luaY_n = *luaY_s;
1046 if (luaY_n >= '0' && luaY_n <= '9')
1047 luaY_debug = luaY_n - '0';
1049 #endif
1051 luaY_nerrs = 0;
1052 luaY_errflag = 0;
1053 luaY_char = (-1);
1055 luaY_ssp = luaY_ss;
1056 luaY_vsp = luaY_vs;
1057 *luaY_ssp = luaY_state = 0;
1059 luaY_loop:
1060 if (luaY_n = luaY_defred[luaY_state]) goto luaY_reduce;
1061 if (luaY_char < 0)
1063 if ((luaY_char = luaY_lex()) < 0) luaY_char = 0;
1064 #if YYDEBUG
1065 if (luaY_debug)
1067 luaY_s = 0;
1068 if (luaY_char <= YYMAXTOKEN) luaY_s = luaY_name[luaY_char];
1069 if (!luaY_s) luaY_s = "illegal-symbol";
1070 printf("%sdebug: state %d, reading %d (%s)\n",
1071 YYPREFIX, luaY_state, luaY_char, luaY_s);
1073 #endif
1075 if ((luaY_n = luaY_sindex[luaY_state]) && (luaY_n += luaY_char) >= 0 &&
1076 luaY_n <= YYTABLESIZE && luaY_check[luaY_n] == luaY_char)
1078 #if YYDEBUG
1079 if (luaY_debug)
1080 printf("%sdebug: state %d, shifting to state %d\n",
1081 YYPREFIX, luaY_state, luaY_table[luaY_n]);
1082 #endif
1083 if (luaY_ssp >= luaY_ss + luaY_stacksize - 1)
1085 goto luaY_overflow;
1087 *++luaY_ssp = luaY_state = luaY_table[luaY_n];
1088 *++luaY_vsp = luaY_lval;
1089 luaY_char = (-1);
1090 if (luaY_errflag > 0) --luaY_errflag;
1091 goto luaY_loop;
1093 if ((luaY_n = luaY_rindex[luaY_state]) && (luaY_n += luaY_char) >= 0 &&
1094 luaY_n <= YYTABLESIZE && luaY_check[luaY_n] == luaY_char)
1096 luaY_n = luaY_table[luaY_n];
1097 goto luaY_reduce;
1099 if (luaY_errflag) goto luaY_inrecovery;
1100 #ifdef lint
1101 goto luaY_newerror;
1102 #endif
1103 luaY_newerror:
1104 luaY_error("syntax error");
1105 #ifdef lint
1106 goto luaY_errlab;
1107 #endif
1108 luaY_errlab:
1109 ++luaY_nerrs;
1110 luaY_inrecovery:
1111 if (luaY_errflag < 3)
1113 luaY_errflag = 3;
1114 for (;;)
1116 if ((luaY_n = luaY_sindex[*luaY_ssp]) && (luaY_n += YYERRCODE) >= 0 &&
1117 luaY_n <= YYTABLESIZE && luaY_check[luaY_n] == YYERRCODE)
1119 #if YYDEBUG
1120 if (luaY_debug)
1121 printf("%sdebug: state %d, error recovery shifting\
1122 to state %d\n", YYPREFIX, *luaY_ssp, luaY_table[luaY_n]);
1123 #endif
1124 if (luaY_ssp >= luaY_ss + luaY_stacksize - 1)
1126 goto luaY_overflow;
1128 *++luaY_ssp = luaY_state = luaY_table[luaY_n];
1129 *++luaY_vsp = luaY_lval;
1130 goto luaY_loop;
1132 else
1134 #if YYDEBUG
1135 if (luaY_debug)
1136 printf("%sdebug: error recovery discarding state %d\n",
1137 YYPREFIX, *luaY_ssp);
1138 #endif
1139 if (luaY_ssp <= luaY_ss) goto luaY_abort;
1140 --luaY_ssp;
1141 --luaY_vsp;
1145 else
1147 if (luaY_char == 0) goto luaY_abort;
1148 #if YYDEBUG
1149 if (luaY_debug)
1151 luaY_s = 0;
1152 if (luaY_char <= YYMAXTOKEN) luaY_s = luaY_name[luaY_char];
1153 if (!luaY_s) luaY_s = "illegal-symbol";
1154 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1155 YYPREFIX, luaY_state, luaY_char, luaY_s);
1157 #endif
1158 luaY_char = (-1);
1159 goto luaY_loop;
1161 luaY_reduce:
1162 #if YYDEBUG
1163 if (luaY_debug)
1164 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1165 YYPREFIX, luaY_state, luaY_n, luaY_rule[luaY_n]);
1166 #endif
1167 luaY_m = luaY_len[luaY_n];
1168 luaY_val = luaY_vsp[1-luaY_m];
1169 switch (luaY_n)
1171 case 5:
1172 #line 468 "lua.stx"
1174 code_byte(PUSHFUNCTION);
1175 code_code(luaY_vsp[0].pFunc);
1176 storesinglevar(luaY_vsp[-1].vLong);
1178 break;
1179 case 6:
1180 #line 475 "lua.stx"
1181 { luaY_val.vLong =luaY_vsp[0].vLong; init_func(); }
1182 break;
1183 case 7:
1184 #line 477 "lua.stx"
1186 code_constant(luaY_vsp[0].pTStr);
1187 luaY_val.vLong = 0; /* indexed variable */
1188 init_func();
1189 add_localvar(luaI_createfixedstring("self"));
1191 break;
1192 case 8:
1193 #line 486 "lua.stx"
1195 codereturn();
1196 luaY_val.pFunc = new(TFunc);
1197 luaI_initTFunc(luaY_val.pFunc);
1198 luaY_val.pFunc->size = pc;
1199 luaY_val.pFunc->code = newvector(pc, Byte);
1200 luaY_val.pFunc->lineDefined = luaY_vsp[-3].vInt;
1201 memcpy(luaY_val.pFunc->code, basepc, pc*sizeof(Byte));
1202 if (lua_debug)
1203 luaI_closelocalvars(luaY_val.pFunc);
1204 /* save func values */
1205 funcCode = basepc; maxcode=maxcurr;
1206 #if LISTING
1207 PrintCode(funcCode,funcCode+pc);
1208 #endif
1209 change2main(); /* change back to main code */
1211 break;
1212 case 13:
1213 #line 512 "lua.stx"
1214 { codeIf(luaY_vsp[-4].vLong, luaY_vsp[-2].vLong); }
1215 break;
1216 case 14:
1217 #line 514 "lua.stx"
1218 {luaY_val.vLong=pc;}
1219 break;
1220 case 15:
1221 #line 515 "lua.stx"
1223 basepc[luaY_vsp[-3].vLong] = IFFJMP;
1224 code_word_at(basepc+luaY_vsp[-3].vLong+1, pc - (luaY_vsp[-3].vLong + sizeof(Word)+1));
1225 basepc[luaY_vsp[-1].vLong] = UPJMP;
1226 code_word_at(basepc+luaY_vsp[-1].vLong+1, pc - (luaY_vsp[-6].vLong));
1228 break;
1229 case 16:
1230 #line 522 "lua.stx"
1231 {luaY_val.vLong=pc;}
1232 break;
1233 case 17:
1234 #line 523 "lua.stx"
1236 basepc[luaY_vsp[0].vLong] = IFFUPJMP;
1237 code_word_at(basepc+luaY_vsp[0].vLong+1, pc - (luaY_vsp[-4].vLong));
1239 break;
1240 case 18:
1241 #line 529 "lua.stx"
1244 int i;
1245 adjust_mult_assign(nvarbuffer, luaY_vsp[0].vLong, luaY_vsp[-2].vInt * 2 + nvarbuffer);
1246 for (i=nvarbuffer-1; i>=0; i--)
1247 lua_codestore (i);
1248 if (luaY_vsp[-2].vInt > 1 || (luaY_vsp[-2].vInt == 1 && varbuffer[0] != 0))
1249 lua_codeadjust (0);
1252 break;
1253 case 19:
1254 #line 539 "lua.stx"
1256 break;
1257 case 20:
1258 #line 541 "lua.stx"
1259 { nlocalvar += luaY_vsp[-1].vInt;
1260 adjust_mult_assign(luaY_vsp[-1].vInt, luaY_vsp[0].vInt, 0);
1262 break;
1263 case 23:
1264 #line 549 "lua.stx"
1265 { codeIf(luaY_vsp[-3].vLong, luaY_vsp[-1].vLong); }
1266 break;
1267 case 24:
1268 #line 552 "lua.stx"
1269 {luaY_val.vInt = nlocalvar;}
1270 break;
1271 case 25:
1272 #line 553 "lua.stx"
1274 if (nlocalvar != luaY_vsp[-2].vInt)
1276 if (lua_debug)
1277 for (; nlocalvar > luaY_vsp[-2].vInt; nlocalvar--)
1278 luaI_unregisterlocalvar(lua_linenumber);
1279 else
1280 nlocalvar = luaY_vsp[-2].vInt;
1281 lua_codeadjust (0);
1284 break;
1285 case 27:
1286 #line 568 "lua.stx"
1288 adjust_functioncall(luaY_vsp[-1].vLong, MULT_RET);
1289 codereturn();
1291 break;
1292 case 28:
1293 #line 575 "lua.stx"
1295 luaY_val.vLong = pc;
1296 code_byte(0); /* open space */
1297 code_word (0);
1299 break;
1300 case 29:
1301 #line 582 "lua.stx"
1302 { adjust_functioncall(luaY_vsp[0].vLong, 1); }
1303 break;
1304 case 30:
1305 #line 585 "lua.stx"
1306 { luaY_val.vLong = luaY_vsp[-1].vLong; }
1307 break;
1308 case 31:
1309 #line 586 "lua.stx"
1310 { code_byte(EQOP); luaY_val.vLong = 0; }
1311 break;
1312 case 32:
1313 #line 587 "lua.stx"
1314 { code_byte(LTOP); luaY_val.vLong = 0; }
1315 break;
1316 case 33:
1317 #line 588 "lua.stx"
1318 { code_byte(GTOP); luaY_val.vLong = 0; }
1319 break;
1320 case 34:
1321 #line 589 "lua.stx"
1322 { code_byte(EQOP); code_byte(NOTOP); luaY_val.vLong = 0; }
1323 break;
1324 case 35:
1325 #line 590 "lua.stx"
1326 { code_byte(LEOP); luaY_val.vLong = 0; }
1327 break;
1328 case 36:
1329 #line 591 "lua.stx"
1330 { code_byte(GEOP); luaY_val.vLong = 0; }
1331 break;
1332 case 37:
1333 #line 592 "lua.stx"
1334 { code_byte(ADDOP); luaY_val.vLong = 0; }
1335 break;
1336 case 38:
1337 #line 593 "lua.stx"
1338 { code_byte(SUBOP); luaY_val.vLong = 0; }
1339 break;
1340 case 39:
1341 #line 594 "lua.stx"
1342 { code_byte(MULTOP); luaY_val.vLong = 0; }
1343 break;
1344 case 40:
1345 #line 595 "lua.stx"
1346 { code_byte(DIVOP); luaY_val.vLong = 0; }
1347 break;
1348 case 41:
1349 #line 596 "lua.stx"
1350 { code_byte(POWOP); luaY_val.vLong = 0; }
1351 break;
1352 case 42:
1353 #line 597 "lua.stx"
1354 { code_byte(CONCOP); luaY_val.vLong = 0; }
1355 break;
1356 case 43:
1357 #line 598 "lua.stx"
1358 { code_byte(MINUSOP); luaY_val.vLong = 0;}
1359 break;
1360 case 44:
1361 #line 599 "lua.stx"
1362 { luaY_val.vLong = 0; }
1363 break;
1364 case 45:
1365 #line 600 "lua.stx"
1366 { luaY_val.vLong = 0;}
1367 break;
1368 case 46:
1369 #line 601 "lua.stx"
1370 { code_number(luaY_vsp[0].vFloat); luaY_val.vLong = 0; }
1371 break;
1372 case 47:
1373 #line 603 "lua.stx"
1375 code_string(luaY_vsp[0].vWord);
1376 luaY_val.vLong = 0;
1378 break;
1379 case 48:
1380 #line 607 "lua.stx"
1381 {code_byte(PUSHNIL); luaY_val.vLong = 0; }
1382 break;
1383 case 49:
1384 #line 608 "lua.stx"
1385 { luaY_val.vLong = luaY_vsp[0].vLong; }
1386 break;
1387 case 50:
1388 #line 609 "lua.stx"
1389 { code_byte(NOTOP); luaY_val.vLong = 0;}
1390 break;
1391 case 51:
1392 #line 610 "lua.stx"
1393 {code_byte(POP); }
1394 break;
1395 case 52:
1396 #line 611 "lua.stx"
1398 basepc[luaY_vsp[-2].vLong] = ONFJMP;
1399 code_word_at(basepc+luaY_vsp[-2].vLong+1, pc - (luaY_vsp[-2].vLong + sizeof(Word)+1));
1400 luaY_val.vLong = 0;
1402 break;
1403 case 53:
1404 #line 616 "lua.stx"
1405 {code_byte(POP); }
1406 break;
1407 case 54:
1408 #line 617 "lua.stx"
1410 basepc[luaY_vsp[-2].vLong] = ONTJMP;
1411 code_word_at(basepc+luaY_vsp[-2].vLong+1, pc - (luaY_vsp[-2].vLong + sizeof(Word)+1));
1412 luaY_val.vLong = 0;
1414 break;
1415 case 55:
1416 #line 625 "lua.stx"
1418 code_byte(CREATEARRAY);
1419 luaY_val.vLong = pc; code_word(0);
1421 break;
1422 case 56:
1423 #line 630 "lua.stx"
1425 code_word_at(basepc+luaY_vsp[-3].vLong, luaY_vsp[-1].vInt);
1427 break;
1428 case 57:
1429 #line 636 "lua.stx"
1431 code_byte(CALLFUNC);
1432 code_byte(luaY_vsp[-1].vInt+luaY_vsp[0].vInt);
1433 luaY_val.vLong = pc;
1434 code_byte(0); /* may be modified by other rules */
1436 break;
1437 case 58:
1438 #line 644 "lua.stx"
1439 { luaY_val.vInt = 0; }
1440 break;
1441 case 59:
1442 #line 646 "lua.stx"
1444 code_byte(PUSHSELF);
1445 code_word(luaI_findconstant(luaY_vsp[0].pTStr));
1446 luaY_val.vInt = 1;
1448 break;
1449 case 60:
1450 #line 654 "lua.stx"
1451 { luaY_val.vInt = adjust_functioncall(luaY_vsp[-1].vLong, 1); }
1452 break;
1453 case 61:
1454 #line 655 "lua.stx"
1455 { luaY_val.vInt = 1; }
1456 break;
1457 case 62:
1458 #line 658 "lua.stx"
1459 { luaY_val.vLong = 0; }
1460 break;
1461 case 63:
1462 #line 659 "lua.stx"
1463 { luaY_val.vLong = luaY_vsp[0].vLong; }
1464 break;
1465 case 64:
1466 #line 662 "lua.stx"
1467 { if (luaY_vsp[0].vLong != 0) luaY_val.vLong = luaY_vsp[0].vLong; else luaY_val.vLong = -1; }
1468 break;
1469 case 65:
1470 #line 663 "lua.stx"
1471 { luaY_val.vLong = adjust_functioncall(luaY_vsp[-1].vLong, 1); }
1472 break;
1473 case 66:
1474 #line 664 "lua.stx"
1476 if (luaY_vsp[0].vLong == 0) luaY_val.vLong = -(luaY_vsp[-1].vLong + 1); /* -length */
1477 else
1479 adjust_functioncall(luaY_vsp[0].vLong, luaY_vsp[-1].vLong);
1480 luaY_val.vLong = luaY_vsp[0].vLong;
1483 break;
1484 case 67:
1485 #line 674 "lua.stx"
1486 { luaY_val.vInt = close_parlist(0); }
1487 break;
1488 case 68:
1489 #line 675 "lua.stx"
1490 { luaY_val.vInt = close_parlist(luaY_vsp[0].vInt); }
1491 break;
1492 case 69:
1493 #line 678 "lua.stx"
1494 { luaY_val.vInt = luaY_vsp[0].vInt; }
1495 break;
1496 case 70:
1497 #line 680 "lua.stx"
1499 if (luaY_vsp[-2].vInt)
1500 lua_error("invalid parameter list");
1501 luaY_val.vInt = luaY_vsp[0].vInt;
1503 break;
1504 case 71:
1505 #line 687 "lua.stx"
1506 { add_localvar(luaY_vsp[0].pTStr); luaY_val.vInt = 0; }
1507 break;
1508 case 72:
1509 #line 688 "lua.stx"
1510 { luaY_val.vInt = 1; }
1511 break;
1512 case 73:
1513 #line 692 "lua.stx"
1514 { flush_list(luaY_vsp[0].vInt/FIELDS_PER_FLUSH, luaY_vsp[0].vInt%FIELDS_PER_FLUSH); }
1515 break;
1516 case 74:
1517 #line 694 "lua.stx"
1518 { luaY_val.vInt = luaY_vsp[-2].vInt+luaY_vsp[0].vInt; }
1519 break;
1520 case 75:
1521 #line 696 "lua.stx"
1522 { luaY_val.vInt = luaY_vsp[-1].vInt; flush_record(luaY_vsp[-1].vInt%FIELDS_PER_FLUSH); }
1523 break;
1524 case 76:
1525 #line 700 "lua.stx"
1526 { luaY_val.vInt = 0; }
1527 break;
1528 case 77:
1529 #line 702 "lua.stx"
1530 { luaY_val.vInt = luaY_vsp[0].vInt; flush_record(luaY_vsp[0].vInt%FIELDS_PER_FLUSH); }
1531 break;
1532 case 80:
1533 #line 709 "lua.stx"
1534 { luaY_val.vInt = 0; }
1535 break;
1536 case 81:
1537 #line 710 "lua.stx"
1538 { luaY_val.vInt = luaY_vsp[-1].vInt; }
1539 break;
1540 case 82:
1541 #line 713 "lua.stx"
1542 {luaY_val.vInt=1;}
1543 break;
1544 case 83:
1545 #line 715 "lua.stx"
1547 luaY_val.vInt=luaY_vsp[-2].vInt+1;
1548 if (luaY_val.vInt%FIELDS_PER_FLUSH == 0) flush_record(FIELDS_PER_FLUSH);
1550 break;
1551 case 86:
1552 #line 725 "lua.stx"
1553 { code_constant(luaY_vsp[0].pTStr); }
1554 break;
1555 case 87:
1556 #line 728 "lua.stx"
1557 { luaY_val.vInt = 0; }
1558 break;
1559 case 88:
1560 #line 729 "lua.stx"
1561 { luaY_val.vInt = luaY_vsp[-1].vInt; }
1562 break;
1563 case 89:
1564 #line 732 "lua.stx"
1565 {luaY_val.vInt=1;}
1566 break;
1567 case 90:
1568 #line 734 "lua.stx"
1570 luaY_val.vInt=luaY_vsp[-2].vInt+1;
1571 if (luaY_val.vInt%FIELDS_PER_FLUSH == 0)
1572 flush_list(luaY_val.vInt/FIELDS_PER_FLUSH - 1, FIELDS_PER_FLUSH);
1574 break;
1575 case 91:
1576 #line 742 "lua.stx"
1578 nvarbuffer = 0;
1579 add_varbuffer(luaY_vsp[0].vLong);
1580 luaY_val.vInt = (luaY_vsp[0].vLong == 0) ? 1 : 0;
1582 break;
1583 case 92:
1584 #line 748 "lua.stx"
1586 add_varbuffer(luaY_vsp[0].vLong);
1587 luaY_val.vInt = (luaY_vsp[0].vLong == 0) ? luaY_vsp[-2].vInt + 1 : luaY_vsp[-2].vInt;
1589 break;
1590 case 93:
1591 #line 754 "lua.stx"
1592 { luaY_val.vLong = luaY_vsp[0].vLong; }
1593 break;
1594 case 94:
1595 #line 756 "lua.stx"
1597 luaY_val.vLong = 0; /* indexed variable */
1599 break;
1600 case 95:
1601 #line 760 "lua.stx"
1603 code_constant(luaY_vsp[0].pTStr);
1604 luaY_val.vLong = 0; /* indexed variable */
1606 break;
1607 case 96:
1608 #line 767 "lua.stx"
1610 int local = lua_localname(luaY_vsp[0].pTStr);
1611 if (local == -1) /* global var */
1612 luaY_val.vLong = luaI_findsymbol(luaY_vsp[0].pTStr)+1; /* return positive value */
1613 else
1614 luaY_val.vLong = -(local+1); /* return negative value */
1616 break;
1617 case 97:
1618 #line 776 "lua.stx"
1619 { lua_pushvar(luaY_vsp[0].vLong); }
1620 break;
1621 case 98:
1622 #line 779 "lua.stx"
1623 {store_localvar(luaY_vsp[0].pTStr, 0); luaY_val.vInt = 1;}
1624 break;
1625 case 99:
1626 #line 781 "lua.stx"
1628 store_localvar(luaY_vsp[0].pTStr, luaY_vsp[-2].vInt);
1629 luaY_val.vInt = luaY_vsp[-2].vInt+1;
1631 break;
1632 case 100:
1633 #line 787 "lua.stx"
1634 { luaY_val.vInt = 0; }
1635 break;
1636 case 101:
1637 #line 788 "lua.stx"
1638 { luaY_val.vInt = luaY_vsp[0].vLong; }
1639 break;
1640 #line 1641 "y.tab.c"
1642 luaY_ssp -= luaY_m;
1643 luaY_state = *luaY_ssp;
1644 luaY_vsp -= luaY_m;
1645 luaY_m = luaY_lhs[luaY_n];
1646 if (luaY_state == 0 && luaY_m == 0)
1648 #if YYDEBUG
1649 if (luaY_debug)
1650 printf("%sdebug: after reduction, shifting from state 0 to\
1651 state %d\n", YYPREFIX, YYFINAL);
1652 #endif
1653 luaY_state = YYFINAL;
1654 *++luaY_ssp = YYFINAL;
1655 *++luaY_vsp = luaY_val;
1656 if (luaY_char < 0)
1658 if ((luaY_char = luaY_lex()) < 0) luaY_char = 0;
1659 #if YYDEBUG
1660 if (luaY_debug)
1662 luaY_s = 0;
1663 if (luaY_char <= YYMAXTOKEN) luaY_s = luaY_name[luaY_char];
1664 if (!luaY_s) luaY_s = "illegal-symbol";
1665 printf("%sdebug: state %d, reading %d (%s)\n",
1666 YYPREFIX, YYFINAL, luaY_char, luaY_s);
1668 #endif
1670 if (luaY_char == 0) goto luaY_accept;
1671 goto luaY_loop;
1673 if ((luaY_n = luaY_gindex[luaY_m]) && (luaY_n += luaY_state) >= 0 &&
1674 luaY_n <= YYTABLESIZE && luaY_check[luaY_n] == luaY_state)
1675 luaY_state = luaY_table[luaY_n];
1676 else
1677 luaY_state = luaY_dgoto[luaY_m];
1678 #if YYDEBUG
1679 if (luaY_debug)
1680 printf("%sdebug: after reduction, shifting from state %d \
1681 to state %d\n", YYPREFIX, *luaY_ssp, luaY_state);
1682 #endif
1683 if (luaY_ssp >= luaY_ss + luaY_stacksize - 1)
1685 goto luaY_overflow;
1687 *++luaY_ssp = luaY_state;
1688 *++luaY_vsp = luaY_val;
1689 goto luaY_loop;
1690 luaY_overflow:
1691 luaY_error("yacc stack overflow");
1692 luaY_abort:
1693 return (1);
1694 luaY_accept:
1695 return (0);