📄 vtc.c
字号:
return ptr; } if (!(*s & ~0x7f) && begin[*s]) { for (i = begin[*s]; i <= end[*s]; i++) { if (!strncmp(s + 1, words[i].s + 1, strlen(words[i].s) - 1)) break; } if (i <= end[*s]) { Add_ntoken(words[i].val); if (words[i].val == FASSIGN) infunc = 0; return s + strlen(words[i].s); } } Add_ntoken(*s); if (*s == '{') braces++; else if (*s == '}') { if (!braces) lexerror(ERR_BADBRACE); else if (!--braces) infunc = 0; } return s + 1;}static int read_char(s) char **s;{ char c; int val = 0, count; if (**s != '\\') return *(*s)++; c = transtab[*++(*s) & 0x7f]; if (c) { (*s)++; return c; } if (**s < '0' || **s > '8') return '\\'; for (count = 0; count < 3 && **s >= '0' && **s <= '8'; (*s)++) val = val * 8 + **s - '0'; return val;}static int enter_sconst(c) Cstr c;{ Push(sconsts, Cstr, sconstsize, sconstpos, cstr_c(c)); return sconstpos - 1;}static char *read_string(s) char *s;{ while (*s && *s != '"') { if (*s == '\\' && !s[1]) { instring = 1; return ""; } s_fadd(&sbuf, read_char(&s)); } if (!*s) { lexerror(ERR_UNTERMSTR); return ""; } instring = 0; Add_vtoken(SCONST, str, enter_sconst(sbuf.c)); return s + 1;}static char *read_comment(s) char *s;{ s = strchr(s, '*'); while (s) { if (s[1] == '/') { incomment = 0; return s + 2; } s = strchr(s + 1, '*'); } incomment = 1; return "";}static void compile(){ tokindex = 0; yyparse(); if (!errflag) { scan(); return; } while (yylex()); condpos = looppos = 0; cleanup_parse();}static void scan(){ Prog *newprog; Instr *in, *end; char *s; Func *func; String dtext; dtext = empty_string; jmptab[0] = loc; Code(I_STOP); newprog = New(Prog); newprog->refs = 0; newprog->avarc = avarc; newprog->reqargs = reqargs; newprog->lvarc = lvarc; newprog->code = Newarray(Instr, loc); Copy(icode, newprog->code, loc, Instr); end = newprog->code + loc; for (in = newprog->code; in < end; in += iwidth[in->type]) { switch(in->type) { case I_SCONST: in[1].sconst = add_sconst(&sconsts[in[1].sindex]); Case I_FCALL: s = in[2].ident; func = find_func(s); if (debug && (!func || !func->cmd) && !strstr(dtext.c.s, s)) { s_acat(&dtext, " "); s_acat(&dtext, s); s_acat(&dtext, "()"); } in[2].func = func ? func : add_func(s, NULL); Case I_FPTR: s = in[1].ident; func = find_func(s); if (debug && (!func || !func->cmd) && !strstr(dtext.c.s, s)) { s_acat(&dtext, " ."); s_acat(&dtext, s); } in[1].func = func ? func : add_func(s, NULL); Case I_GVAR: if (debug && !strstr(dtext.c.s, in[1].ident)) { s_acat(&dtext, " "); s_acat(&dtext, in[1].ident); } in[1].tnum = get_vindex(in[1].ident); Case I_JMP: case I_JMPT: case I_JMPF: case I_JMPPT: case I_JMPPF: in[1].loc = newprog->code + jmptab[in[1].offset]; } } if (debug && *dtext.c.s) { if (*curfile) outputf("%s ", curfile); outputf("%s:%s\n", *curfunc ? curfunc : "Command", dtext.c.s); } s_free(&dtext); if (*curfunc) { add_func(curfunc, newprog); cleanup_parse(); } else { cleanup_parse(); run_prog(newprog); }}static void cleanup_parse(){ while (identpos--) Discardstring(idents[identpos]); while (sconstpos--) { if (sconsts[sconstpos].s) Discardarray(sconsts[sconstpos].s, char, sconsts[sconstpos].l + 1); } free_labels(); curfunc = ""; tokpos = loc = lvarc = avarc = errflag = identpos = sconstpos = 0; reqargs = 0; jmppos = 1;}static void lexerror(s) char *s;{ if (lexline != -1) outputf("%s line %d: ", curfile, lexline); outputf("%s\n", s); errflag = 1;}static void yyerror(msg) char *msg;{ if (parseline != -1) outputf("%s line %d: ", curfile, parseline); coutput(msg); if (*curfunc) outputf(" in function %s", curfunc); coutput("\n"); errflag = 1;}static int yylex(){ while (tokindex < tokpos && tokbuf[tokindex].type == '\n') { tokindex++; if (parseline != -1) parseline++; } if (tokindex < tokpos) { yylval = tokbuf[tokindex].val; return tokbuf[tokindex++].type; } return 0;}int load_file(name) char *name;{ int olline, opline; char *ocfile; FILE *fp; String freader; freader = empty_string; fp = fopen(expand(name), "r"); if (!fp) return -1; olline = lexline; opline = parseline; ocfile = curfile; lexline = parseline = 1; curfile = vtstrdup(name); while (s_fget(&freader, fp)) { if (freader.c.s[freader.c.l - 1] == '\n') freader.c.s[freader.c.l - 1] = '\0'; parse(freader.c.s); if (tokpos) Add_ntoken('\n'); else parseline++; lexline++; } lexline = olline; parseline = opline; Discardstring(curfile); curfile = ocfile; fclose(fp); s_free(&freader); return 0;}__YYSCLASS yytabelem yyexca[] ={-1, 1, 0, -1, -2, 0,-1, 8, 59, 96, -2, 3,-1, 28, 283, 19, 91, 19, -2, 27,-1, 30, 283, 20, 91, 20, -2, 38, };# define YYNPROD 140# define YYLAST 718__YYSCLASS yytabelem yyact[]={ 33, 114, 115, 127, 135, 37, 206, 40, 5, 29, 36, 99, 35, 44, 172, 33, 97, 95, 74, 96, 37, 98, 40, 139, 29, 36, 5, 35, 44, 99, 86, 11, 21, 178, 97, 95, 198, 96, 80, 98, 223, 99, 86, 185, 143, 76, 97, 95, 75, 96, 209, 98, 89, 144, 91, 100, 67, 80, 134, 177, 168, 80, 179, 72, 89, 202, 91, 100, 175, 180, 187, 228, 99, 86, 45, 62, 215, 97, 95, 99, 96, 73, 98, 199, 97, 95, 85, 96, 101, 98, 21, 220, 145, 34, 40, 89, 29, 91, 85, 219, 44, 200, 89, 138, 91, 21, 197, 133, 34, 225, 33, 186, 80, 136, 130, 37, 84, 40, 72, 29, 36, 99, 35, 44, 47, 33, 97, 101, 84, 85, 37, 98, 40, 132, 29, 36, 77, 35, 44, 81, 71, 99, 86, 179, 10, 3, 97, 95, 7, 96, 205, 98, 65, 80, 190, 99, 86, 80, 142, 84, 97, 95, 33, 96, 89, 98, 91, 37, 229, 40, 226, 29, 36, 207, 35, 44, 99, 86, 89, 6, 91, 97, 95, 99, 96, 184, 98, 70, 97, 95, 214, 96, 69, 98, 176, 126, 4, 80, 85, 89, 182, 91, 12, 34, 181, 79, 89, 216, 91, 99, 147, 171, 85, 203, 97, 95, 170, 96, 34, 98, 194, 218, 167, 211, 42, 43, 38, 16, 84, 150, 14, 13, 23, 27, 15, 17, 18, 19, 20, 42, 43, 38, 16, 149, 41, 14, 13, 23, 28, 15, 17, 18, 19, 20, 39, 34, 61, 201, 227, 31, 32, 212, 131, 116, 93, 94, 8, 121, 122, 123, 124, 2, 213, 1, 31, 32, 82, 83, 87, 88, 90, 92, 93, 94, 60, 102, 140, 0, 82, 83, 87, 88, 90, 92, 93, 94, 0, 0, 0, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 103, 0, 42, 43, 38, 64, 0, 0, 0, 0, 0, 83, 87, 88, 90, 92, 93, 94, 0, 87, 88, 90, 92, 93, 94, 42, 43, 38, 64, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 103, 42, 43, 38, 64, 59, 0, 48, 46, 54, 0, 49, 50, 51, 52, 53, 55, 56, 57, 58, 0, 31, 32, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 31, 32, 174, 43, 38, 64, 87, 88, 90, 92, 93, 94, 0, 0, 0, 0, 0, 0, 0, 0, 87, 88, 90, 92, 93, 94, 9, 119, 119, 24, 0, 0, 0, 119, 0, 66, 0, 31, 32, 68, 0, 87, 88, 90, 92, 93, 94, 0, 0, 0, 90, 92, 93, 94, 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, 59, 0, 48, 46, 54, 0, 49, 50, 51, 52, 53, 55, 56, 57, 58, 59, 0, 48, 46, 54, 0, 49, 50, 51, 52, 53, 55, 56, 57, 58, 117, 0, 0, 137, 26, 0, 0, 26, 141, 26, 0, 0, 146, 26, 0, 0, 0, 0, 0, 0, 0, 26, 0, 22, 0, 0, 0, 0, 0, 0, 63, 0, 118, 120, 0, 0, 0, 169, 125, 0, 0, 128, 0, 0, 78, 0, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 0, 0, 129, 0, 0, 0, 0, 0, 0, 26, 26, 26, 0, 188, 0, 0, 0, 0, 26, 0, 26, 189, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 148, 195, 196, 0, 0, 0, 191, 192, 0, 0, 204, 0, 0, 0, 0, 0, 0, 0, 208, 0, 0, 0, 0, 26, 193, 0, 0, 0, 0, 0, 141, 0, 26, 0, 0, 0, 0, 0, 26, 0, 0, 0, 221, 26, 0, 0, 173, 0, 0, 0, 0, 210, 0, 0, 0, 183, 0, 230, 0, 0, 0, 0, 0, 0, 0, 0, 26, 26, 0, 0, 0, 0, 0, 0, 0, 224, 0, 0, 26, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 26, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 26, 217, 0, 0, 0, 0, 0, 0, 0, 222 };__YYSCLASS yytabelem yypact[]={ -65, -3000, -83, -18, 206, 191, 92, -91, -18, -3000, -3000, -3, -18, -3000, -3000, 100, 23, -242, -11, -14, 77, -3000, 17, 99, -3000, 4, 66, -3000, -291, 92, -3000, 54, 54, 92, 92, 92, 92, 54, -3000, -88, 92, -3000, -3000, -3000, 206, 93, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, 14, -3000, 17, 78, -3000, -3000, -3000, -262, 73, -18, 92, 92, -3000, -15, -3000, -3000, -3000, -6, -33, -3000, 92, -3000, -3000, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 2, 92, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -246, 129, 27, 153, -3000, -3000, 96, -3000, 206, -3000, 92, -3000, -16, 70, 26, -3000, -18, -3000, -3000, -3000, -3000, 92, 113, 92, 92, 118, 139, 42, 146, 146, -26, -26, -26, -26, 172, 172, 84, 84, -3000, -3000, -3000, 92, -3000, -3000, 92, 92, -3000, 13, -57, 43, -3000, 60, 21, 206, -3000, -3000, -18, 109, -258, -3000, -3000, 92, -3000, -3000, -3000, 35, 104, -8, 92, -3000, -3000, -3000, -3000, 92, -3000, 15, 206, 21, -3000, -3000, 36, 92, -3000, -3000, 4, 58, 50, -3000, -18, 92, -19, 17, 92, -3000, -3000, -3000, 68, -3000, 4, -3000, 92, 30, -3000, -18, -3000 };__YYSCLASS yytabelem yypgo[]={ 0, 286, 23, 285, 69, 273, 271, 501, 145, 144, 266, 410, 262, 59, 33, 257, 256, 254, 248, 379, 478, 233, 244, 439, 243, 229, 222, 221, 220, 413, 216, 211, 210, 31, 207, 205, 202, 200, 192, 190, 187, 185, 173, 170, 168, 158, 124 };__YYSCLASS yytabelem yyr1[]={ 0, 5, 5, 5, 10, 10, 6, 12, 15, 12, 8, 8, 8, 13, 13, 14, 14, 16, 16, 17, 17, 18, 18, 18, 18, 18, 18, 20, 20, 22, 22, 22, 22, 22, 22, 19, 19, 19, 21, 21, 21, 21, 21, 21, 21, 21, 21, 23, 24, 23, 25, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 26, 27, 23, 28, 23, 29, 29, 30, 29, 31, 29, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 32, 7, 1, 1, 2, 2, 33, 33, 34, 34, 9, 35, 35, 36, 11, 11, 11, 37, 11, 38, 39, 11, 40, 41, 11, 42, 43, 44, 11, 45, 11, 11, 11, 11, 11, 11, 4, 4, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46 };__YYSCLASS yytabelem yyr2[]={ 0, 6, 7, 5, 2, 4, 7, 6, 1, 10, 0, 4, 6, 0, 4, 3, 7, 3, 7, 3, 2, 3, 3, 7, 9, 9, 6, 2, 4, 3, 3, 5, 9, 13, 6, 2, 5, 5, 2, 3, 5, 5, 5, 5, 5, 4, 4, 2, 1, 9, 1, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 1, 15, 1, 11, 2, 7, 1, 9, 1, 9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 8, 3, 7, 1, 2, 0, 3, 1, 2, 6, 0, 4, 9, 2, 4, 5, 1, 11, 1, 1, 15, 1, 1, 17, 1, 1, 1, 25, 1, 8, 7, 5, 5, 5, 7, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };__YYSCLASS yytabelem yychk[]={ -3000, -5, -6, -8, 261, 91, 262, -8, -10, -11, -9, -33, -36, 264, 263, 267, 260, 268, 269, 270, 271, 123, -7, 265, -29, -23, -20, -21, -18, 42, -19, 292, 293, 33, 126, 45, 43, 38, 259, -17, 40, -22, 257, 258, 46, -4, 260, -46, 259, 263, 264, 265, 266, 267, 261, 268, 269, 270, 271, 257, 93, -16, -4, -7, 260, -9, -11, 59, -11, -38, -40, 40, 40, 58, 260, 59, 59, 59, -7, -35, 44, 40, 284, 285, 124, 94, 38, 286, 287, 60, 288, 62, 289, 290, 291, 43, 45, 42, 47, 37, 63, 61, -3, 282, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 292, 293, -21, -20, -20, -19, -20, -21, -21, -21, -21, -20, 283, 91, -20, -7, -4, -12, 40, 93, 44, 266, 40, -11, -33, -2, -1, -29, -45, 59, 59, 125, -11, -32, -7, -24, -25, -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, -23, -26, 58, -29, -30, -31, 260, -7, 257, 41, 41, -13, -14, 47, -4, -4, -37, -7, -41, 59, 41, 44, -11, -29, 41, -23, -23, -23, -28, -29, -29, 93, 93, 40, 41, -15, 44, -14, -11, 41, 264, -42, -29, 58, -23, -2, -13, -4, -39, 40, -34, -7, -27, 41, 41, -11, -7, 59, -23, 41, -43, -33, 41, -44, -11 };__YYSCLASS yytabelem yydef[]={ 10, -2, 10, 96, 0, 0, 0, 0, -2, 4, 104, 0, 96, 109, 112, 0, 21, 0, 0, 0, 0, 101, 97, 0, 89, 73, 39, 47, -2, 0, -2, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 35, 29, 30, 0, 0, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 11, 0, 17, 1, 21, 2, 5, 105, 106, 0, 96, 96, 94, 119, 0, 122, 123, 124, 0, 96, 90, 0, 48, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 68, 0, 75, 77, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 36, 37, 28, 39, 40, 20, 41, 42, 43, 44, 45, 46, 0, 0, 39, 0, 31, 6, 13, 12, 0, 107, 0, 113, 0, 0, 95, 92, 96, 121, 125, 100, 102, 0, 0, 0, 0, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 0, 71, 74, 0, 0, 23, 0, 29, 26, 34, 0, 8, 0, 15, 18, 96, 0, 0, 115, 32, 0, 120, 91, 103, 49, 51, 0, 0, 76, 78, 24, 25, 94, 7, 13, 0, 14, 108, 110, 0, 98, 93, 69, 72, 0, 0, 16, 96, 0, 0, 99, 0, 33, 9, 111, 0, 116, 70, 114, 96, 0, 117, 96, 118 };typedef struct { char *t_name; int t_val; } yytoktype;#ifndef YYDEBUG# define YYDEBUG 0 /* don't allow debugging */#endif#if YYDEBUG__YYSCLASS yytoktype yytoks[] ={ "ICONST", 257, "SCONST", 258, "BOBJ", 259, "IDENT", 260, "FUNC", 261, "FASSIGN", 262, "DO", 263, "WHILE", 264, "IF", 265, "ELSE", 266, "FOR", 267, "GOTO", 268, "BREAK", 269, "CONTINUE", 270, "RETURN", 271, ";", 59,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -