📄 y_tab.c
字号:
# line 2 "lua.stx"#include <stdio.h>#include <stdlib.h>#include <string.h>#include "opcode.h"#include "hash.h"#include "inout.h"#include "table.h"#include "lua.h"#ifndef ALIGNMENT#define ALIGNMENT (sizeof(void *))#endif#ifndef MAXCODE#define MAXCODE 1024#endifstatic long buffer[MAXCODE];static Byte *code = (Byte *)buffer;static long mainbuffer[MAXCODE];static Byte *maincode = (Byte *)mainbuffer;static Byte *basepc;static Byte *pc;#define MAXVAR 32static long varbuffer[MAXVAR];static Byte nvarbuffer=0; /* number of variables at a list */static Word localvar[STACKGAP];static Byte nlocalvar=0; /* number of local variables */static int ntemp; /* number of temporary var into stack */static int err; /* flag to indicate error *//* Internal functions */#define align(n) align_n(sizeof(n))static void code_byte (Byte c){ if (pc-basepc>MAXCODE-1) { lua_error ("code buffer overflow"); err = 1; } *pc++ = c;}static void code_word (Word n){ if (pc-basepc>MAXCODE-sizeof(Word)) { lua_error ("code buffer overflow"); err = 1; } *((Word *)pc) = n; pc += sizeof(Word);}static void code_float (float n){ if (pc-basepc>MAXCODE-sizeof(float)) { lua_error ("code buffer overflow"); err = 1; } *((float *)pc) = n; pc += sizeof(float);}static void incr_ntemp (void){ if (ntemp+nlocalvar+MAXVAR+1 < STACKGAP) ntemp++; else { lua_error ("stack overflow"); err = 1; }}static void incr_nlocalvar (void){ if (ntemp+nlocalvar+MAXVAR+1 < STACKGAP) nlocalvar++; else { lua_error ("too many local variables or expression too complicate"); err = 1; }}static void incr_nvarbuffer (void){ if (nvarbuffer < MAXVAR-1) nvarbuffer++; else { lua_error ("variable buffer overflow"); err = 1; }}static void align_n (unsigned size){ if (size > ALIGNMENT) size = ALIGNMENT; while (((pc+1-code)%size) != 0) /* +1 to include BYTECODE */ code_byte (NOP);}static void code_number (float f){ int i = f; if (f == i) /* f has an integer value */ { if (i <= 2) code_byte(PUSH0 + i); else if (i <= 255) { code_byte(PUSHBYTE); code_byte(i); } else { align(Word); code_byte(PUSHWORD); code_word(i); } } else { align(float); code_byte(PUSHFLOAT); code_float(f); } incr_ntemp();}# line 140 "lua.stx"typedef union { int vInt; long vLong; float vFloat; Word vWord; Byte *pByte;} YYSTYPE;# define NIL 257# define IF 258# define THEN 259# define ELSE 260# define ELSEIF 261# define WHILE 262# define DO 263# define REPEAT 264# define UNTIL 265# define END 266# define RETURN 267# define LOCAL 268# define NUMBER 269# define FUNCTION 270# define NAME 271# define STRING 272# define DEBUG 273# define NOT 274# define AND 275# define OR 276# define NE 277# define LE 278# define GE 279# define CONC 280# define UNARY 281#define yyclearin yychar = -1#define yyerrok yyerrflag = 0extern int yychar;extern int yyerrflag;#ifndef YYMAXDEPTH#define YYMAXDEPTH 150#endifYYSTYPE yylval, yyval;# define YYERRCODE 256# line 530 "lua.stx"/*** Search a local name and if find return its index. If do not find return -1*/static int lua_localname (Word n){ int i; for (i=nlocalvar-1; i >= 0; i--) if (n == localvar[i]) return i; /* local var */ return -1; /* global var */}/*** Push a variable given a number. If number is positive, push global variable** indexed by (number -1). If negative, push local indexed by ABS(number)-1.** Otherwise, if zero, push indexed variable (record).*/static void lua_pushvar (long number){ if (number > 0) /* global var */ { align(Word); code_byte(PUSHGLOBAL); code_word(number-1); incr_ntemp(); } else if (number < 0) /* local var */ { number = (-number) - 1; if (number < 10) code_byte(PUSHLOCAL0 + number); else { code_byte(PUSHLOCAL); code_byte(number); } incr_ntemp(); } else { code_byte(PUSHINDEXED); ntemp--; }}static void lua_codeadjust (int n){ code_byte(ADJUST); code_byte(n + nlocalvar);}static void lua_codestore (int i){ if (varbuffer[i] > 0) /* global var */ { align(Word); code_byte(STOREGLOBAL); code_word(varbuffer[i]-1); } else if (varbuffer[i] < 0) /* local var */ { int number = (-varbuffer[i]) - 1; if (number < 10) code_byte(STORELOCAL0 + number); else { code_byte(STORELOCAL); code_byte(number); } } else /* indexed var */ { int j; int upper=0; /* number of indexed variables upper */ int param; /* number of itens until indexed expression */ for (j=i+1; j <nvarbuffer; j++) if (varbuffer[j] == 0) upper++; param = upper*2 + i; if (param == 0) code_byte(STOREINDEXED0); else { code_byte(STOREINDEXED); code_byte(param); } }}void yyerror (char *s){ static char msg[256]; sprintf (msg,"%s near \"%s\" at line %d in file \"%s\"", s, lua_lasttext (), lua_linenumber, lua_filename()); lua_error (msg); err = 1;}int yywrap (void){ return 1;}/*** Parse LUA code and execute global statement.** Return 0 on success or 1 on error.*/int lua_parse (void){ Byte *initcode = maincode; err = 0; if (yyparse () || (err==1)) return 1; *maincode++ = HALT; if (lua_execute (initcode)) return 1; maincode = initcode; return 0;}#if 0static void PrintCode (void){ Byte *p = code; printf ("\n\nCODE\n"); while (p != pc) { switch ((OpCode)*p) { case NOP: printf ("%d NOP\n", (p++)-code); break; case PUSHNIL: printf ("%d PUSHNIL\n", (p++)-code); break; case PUSH0: case PUSH1: case PUSH2: printf ("%d PUSH%c\n", p-code, *p-PUSH0+'0'); p++; break; case PUSHBYTE: printf ("%d PUSHBYTE %d\n", p-code, *(++p)); p++; break; case PUSHWORD: printf ("%d PUSHWORD %d\n", p-code, *((Word *)(p+1))); p += 1 + sizeof(Word); break; case PUSHFLOAT: printf ("%d PUSHFLOAT %f\n", p-code, *((float *)(p+1))); p += 1 + sizeof(float); break; case PUSHSTRING: printf ("%d PUSHSTRING %d\n", p-code, *((Word *)(p+1))); p += 1 + sizeof(Word); break; case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3: case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: case PUSHLOCAL8: case PUSHLOCAL9: printf ("%d PUSHLOCAL%c\n", p-code, *p-PUSHLOCAL0+'0'); p++; break; case PUSHLOCAL: printf ("%d PUSHLOCAL %d\n", p-code, *(++p)); p++; break; case PUSHGLOBAL: printf ("%d PUSHGLOBAL %d\n", p-code, *((Word *)(p+1))); p += 1 + sizeof(Word); break; case PUSHINDEXED: printf ("%d PUSHINDEXED\n", (p++)-code); break; case PUSHMARK: printf ("%d PUSHMARK\n", (p++)-code); break; case PUSHOBJECT: printf ("%d PUSHOBJECT\n", (p++)-code); break; case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3: case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7: case STORELOCAL8: case STORELOCAL9: printf ("%d STORELOCAL%c\n", p-code, *p-STORELOCAL0+'0'); p++; break; case STORELOCAL: printf ("%d STORELOCAK %d\n", p-code, *(++p)); p++; break; case STOREGLOBAL: printf ("%d STOREGLOBAL %d\n", p-code, *((Word *)(p+1))); p += 1 + sizeof(Word); break; case STOREINDEXED0: printf ("%d STOREINDEXED0\n", (p++)-code); break; case STOREINDEXED: printf ("%d STOREINDEXED %d\n", p-code, *(++p)); p++; break; case STOREFIELD: printf ("%d STOREFIELD\n", (p++)-code); break; case ADJUST: printf ("%d ADJUST %d\n", p-code, *(++p)); p++; break; case CREATEARRAY: printf ("%d CREATEARRAY\n", (p++)-code); break; case EQOP: printf ("%d EQOP\n", (p++)-code); break; case LTOP: printf ("%d LTOP\n", (p++)-code); break; case LEOP: printf ("%d LEOP\n", (p++)-code); break; case ADDOP: printf ("%d ADDOP\n", (p++)-code); break; case SUBOP: printf ("%d SUBOP\n", (p++)-code); break; case MULTOP: printf ("%d MULTOP\n", (p++)-code); break; case DIVOP: printf ("%d DIVOP\n", (p++)-code); break; case CONCOP: printf ("%d CONCOP\n", (p++)-code); break; case MINUSOP: printf ("%d MINUSOP\n", (p++)-code); break; case NOTOP: printf ("%d NOTOP\n", (p++)-code); break; case ONTJMP: printf ("%d ONTJMP %d\n", p-code, *((Word *)(p+1))); p += sizeof(Word) + 1; break; case ONFJMP: printf ("%d ONFJMP %d\n", p-code, *((Word *)(p+1))); p += sizeof(Word) + 1; break; case JMP: printf ("%d JMP %d\n", p-code, *((Word *)(p+1))); p += sizeof(Word) + 1; break; case UPJMP: printf ("%d UPJMP %d\n", p-code, *((Word *)(p+1))); p += sizeof(Word) + 1; break; case IFFJMP: printf ("%d IFFJMP %d\n", p-code, *((Word *)(p+1))); p += sizeof(Word) + 1; break; case IFFUPJMP: printf ("%d IFFUPJMP %d\n", p-code, *((Word *)(p+1))); p += sizeof(Word) + 1; break; case POP: printf ("%d POP\n", (p++)-code); break; case CALLFUNC: printf ("%d CALLFUNC\n", (p++)-code); break; case RETCODE: printf ("%d RETCODE %d\n", p-code, *(++p)); p++; break; default: printf ("%d Cannot happen\n", (p++)-code); break; } }}#endifint yyexca[] ={-1, 1, 0, -1, -2, 2,-1, 19, 40, 65, 91, 95, 46, 97, -2, 92,-1, 29, 40, 65, 91, 95, 46, 97, -2, 51,-1, 70, 275, 33, 276, 33, 61, 33, 277, 33, 62, 33, 60, 33, 278, 33, 279, 33, 280, 33, 43, 33, 45, 33, 42, 33, 47, 33, -2, 68,-1, 71, 91, 95, 46, 97, -2, 93,-1, 102, 260, 27, 261, 27, 265, 27, 266, 27, 267, 27, -2, 11,-1, 117, 93, 85, -2, 87,-1, 122, 267, 30, -2, 29,-1, 145, 275, 33, 276, 33, 61, 33, 277, 33, 62, 33, 60, 33, 278, 33, 279, 33, 280, 33, 43, 33, 45, 33, 42, 33, 47, 33, -2, 70, };# define YYNPROD 105# define YYLAST 318int yyact[]={ 54, 52, 136, 53, 13, 55, 54, 52, 14, 53, 15, 55, 5, 166, 18, 6, 129, 21, 47, 46, 48, 107, 104, 97, 47, 46, 48, 54, 52, 80, 53, 21, 55, 54, 52, 40, 53, 9, 55, 54, 52, 158, 53, 160, 55, 47, 46, 48, 159, 101, 81, 47, 46, 48, 10, 54, 52, 126, 53, 67, 55, 54, 52, 60, 53, 155, 55, 148, 149, 135, 147, 108, 150, 47, 46, 48, 73, 23, 75, 47, 46, 48, 7, 25, 38, 153, 26, 164, 27, 117, 61, 62, 74, 11, 76, 54, 24, 127, 65, 66, 55, 37, 154, 151, 103, 111, 72, 28, 93, 94, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 116, 59, 77, 54, 52, 118, 53, 99, 55, 110, 95, 64, 44, 70, 109, 29, 33, 105, 106, 42, 112, 41, 165, 139, 19, 17, 152, 79, 123, 43, 119, 20, 114, 113, 98, 63, 144, 143, 122, 68, 39, 36, 130, 35, 120, 12, 8, 102, 125, 128, 141, 78, 69, 70, 71, 142, 131, 132, 140, 22, 124, 4, 3, 2, 121, 96, 138, 146, 137, 134, 157, 133, 115, 16, 1, 0, 0, 0, 0, 0, 0, 0, 156, 0, 0, 0, 0, 161, 0, 0, 0, 0, 162, 0, 0, 0, 168, 0, 172, 145, 163, 171, 0, 174, 0, 0, 0, 169, 156, 167, 170, 173, 57, 58, 49, 50, 51, 56, 57, 58, 49, 50, 51, 56, 175, 0, 0, 100, 0, 45, 0, 0, 0, 0, 70, 0, 0, 0, 0, 57, 58, 49, 50, 51, 56, 57, 58, 49, 50, 51, 56, 0, 0, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 58, 49, 50, 51, 56, 0, 0, 49, 50, 51, 56, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 21, 31, 0, 34 };int yypact[]={ -1000, -258, -1000, -1000, -1000, -234, -1000, 34, -254, -1000, -1000, -1000, -1000, 43, -1000, -1000, 40, -1000, -236, -1000, -1000, -1000, 93, -9, -1000, 43, 43, 43, 92, -1000, -1000, -1000, -1000, -1000, 43, 43, -1000, 43, -240, 62, 31, -13, 48, 83, -242, -1000, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, -1000, -1000, 90, 13, -1000, -1000, -248, 43, 19, -15, -216, -1000, 60, -1000, -1000, -249, -1000, -1000, 43, -250, 43, 89, 61, -1000, -1000, -3, -3, -3, -3, -3, -3, 53, 53, -1000, -1000, 82, -1000, -1000, -1000, -2, -1000, 85, 13, -1000, 43, -1000, -1000, 31, 43, -36, -1000, 56, 60, -1000, -255, -1000, 43, 43, -1000, -269, -1000, -1000, -1000, 13, 34, -1000, 43, -1000, 13, -1000, -1000, -1000, -1000, -193, 19, 19, -53, 59, -1000, -1000, -8, 58, 43, -1000, -1000, -1000, -1000, -226, -1000, -218, -223, -1000, 43, -1000, -269, 26, -1000, -1000, -1000, 13, -253, 43, -1000, -1000, -1000, -42, -1000, 43, 43, -1000, 34, -1000, 13, -1000, -1000, -1000, -1000, -193, -1000 };int yypgo[]={ 0, 195, 50, 96, 71, 135, 194, 193, 192, 190, 189, 187, 136, 186, 184, 82, 54, 183, 182, 180, 172, 170, 59, 168, 167, 166, 63, 70, 164, 162, 137, 161, 160, 159, 158, 157, 156, 155, 154, 153, 152, 150, 149, 148, 69, 147, 144, 65, 143, 142, 140, 76, 138 };int yyr1[]={ 0, 1, 14, 1, 1, 1, 19, 21, 17, 23,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -