📄 output.c
字号:
if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; fprintf(output_file, "%5d,", base[i]); } if (!rflag) outline += 2; fprintf(output_file, "\n};\n"); if (!rflag) fprintf(output_file, "static "); fprintf(output_file, "int yygindex[] = {%39d,", base[3*nstates]); j = 10; for (i = 3*nstates + 1; i < nvectors - 1; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; fprintf(output_file, "%5d,", base[i]); } if (!rflag) outline += 2; fprintf(output_file, "\n};\n"); FREE(base);}void output_table(){ register int i; register int j; ++outline; fprintf(stderr, "YYTABLESIZE: %d\n", high); if(high >= MAXSHORT) { fprintf(stderr, "Table is longer than %d elements. It's not gonna fly.\n", MAXSHORT); exit(1); } fprintf(code_file, "#define YYTABLESIZE %d\n", high); if (!rflag) fprintf(output_file, "static "); fprintf(output_file, "int yytable[] = {%40d,", table[0]); j = 10; for (i = 1; i <= high; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; fprintf(output_file, "%5d,", table[i]); } if (!rflag) outline += 2; fprintf(output_file, "\n};\n"); FREE(table);}void output_check(){ register int i; register int j; if (!rflag) fprintf(output_file, "static "); fprintf(output_file, "int yycheck[] = {%40d,", check[0]); j = 10; for (i = 1; i <= high; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; fprintf(output_file, "%5d,", check[i]); } if (!rflag) outline += 2; fprintf(output_file, "\n};\n"); FREE(check);}void output_ctable(){ register int i; register int j; if (!rflag) fprintf(output_file, "static "); fprintf(output_file, "int yyctable[] = {%39d,", conflicts ? conflicts[0] : 0); j = 10; for (i = 1; i < nconflicts; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; fprintf(output_file, "%5d,", conflicts[i]); } if (!rflag) outline += 2; fprintf(output_file, "\n};\n"); if (conflicts) FREE(conflicts);}int is_C_identifier(char *name){ register char *s; register int c; s = name; c = *s; if (c == '"') { c = *++s; if (!isalpha(c) && c != '_' && c != '$') return (0); while ((c = *++s) != '"') { if (!isalnum(c) && c != '_' && c != '$') return (0); } return (1); } if (!isalpha(c) && c != '_' && c != '$') return (0); while ((c = *++s)) { if (!isalnum(c) && c != '_' && c != '$') return (0); } return (1);}void output_defines(){ register int c, i; register char *s; for (i = 2; i < ntokens; ++i) { s = symbol_name[i]; if (is_C_identifier(s)) { fprintf(code_file, "#define "); if (dflag) fprintf(defines_file, "#define "); c = *s; if (c == '"') { while ((c = *++s) != '"') { putc(c, code_file); if (dflag) putc(c, defines_file); } } else { do { putc(c, code_file); if (dflag) putc(c, defines_file); } while ((c = *++s)); } ++outline; fprintf(code_file, " %d\n", symbol_value[i]); if (dflag) fprintf(defines_file, " %d\n", symbol_value[i]); } } ++outline; fprintf(code_file, "#define YYERRCODE %d\n", symbol_value[1]); if (dflag && unionized) { fclose(union_file); union_file = fopen(union_file_name, "r"); if (union_file == NULL) open_error(union_file_name); while ((c = getc(union_file)) != EOF) putc(c, defines_file); fprintf(defines_file, " YYSTYPE;\nextern YYSTYPE yylval;\n"); }}void output_stored_text(){ register int c; register FILE *in, *out; register int state; /* 0=middle of line, 1=start of line, 2=seen '#' */ state = 1; fclose(text_file); text_file = fopen(text_file_name, "r"); if (text_file == NULL) open_error(text_file_name); in = text_file; if ((c = getc(in)) == EOF) return; out = code_file; do { if (c == '\n') { ++outline; if (state == 2) { fprintf(out, line_format+1, outline + 1, code_file_name); state = 1; continue; } state = 1; } else if (state == 1 && c == '#') state = 2; else state = 0; putc(c, out); } while ((c = getc(in)) != EOF); if (!lflag) fprintf(out, line_format, ++outline + 1, code_file_name);}void output_debug(){ register int i, j, k, max; char **symnam, *s; ++outline; fprintf(code_file, "#define YYFINAL %d\n", final_state); outline += 3; fprintf(code_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n", tflag); if (rflag) fprintf(output_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n", tflag); max = 0; for (i = 2; i < ntokens; ++i) if (symbol_value[i] > max) max = symbol_value[i]; ++outline; fprintf(code_file, "#define YYMAXTOKEN %d\n", max); symnam = (char **) MALLOC((max+1)*sizeof(char *)); if (symnam == 0) no_space(); /* Note that it is not necessary to initialize the element */ /* symnam[max]. */ for (i = 0; i < max; ++i) symnam[i] = 0; for (i = ntokens - 1; i >= 2; --i) symnam[symbol_value[i]] = symbol_name[i]; symnam[0] = "end-of-file"; if (!rflag) ++outline; fprintf(output_file, "#if YYDEBUG\n"); if (!rflag) fprintf(output_file, "static "); fprintf(output_file, "char *yyname[] = {"); j = 80; for (i = 0; i <= max; ++i) { if ((s = symnam[i])) { if (s[0] == '"') { k = 7; while (*++s != '"') { ++k; if (*s == '\\') { k += 2; if (*++s == '\\') ++k; } } j += k; if (j > 80) { if (!rflag) ++outline; putc('\n', output_file); j = k; } fprintf(output_file, "\"\\\""); s = symnam[i]; while (*++s != '"') { if (*s == '\\') { fprintf(output_file, "\\\\"); if (*++s == '\\') fprintf(output_file, "\\\\"); else putc(*s, output_file); } else putc(*s, output_file); } fprintf(output_file, "\\\"\","); } else if (s[0] == '\'') { if (s[1] == '"') { j += 7; if (j > 80) { if (!rflag) ++outline; putc('\n', output_file); j = 7; } fprintf(output_file, "\"'\\\"'\","); } else { k = 5; while (*++s != '\'') { ++k; if (*s == '\\') { k += 2; if (*++s == '\\') ++k; } } j += k; if (j > 80) { if (!rflag) ++outline; putc('\n', output_file); j = k; } fprintf(output_file, "\"'"); s = symnam[i]; while (*++s != '\'') { if (*s == '\\') { fprintf(output_file, "\\\\"); if (*++s == '\\') fprintf(output_file, "\\\\"); else putc(*s, output_file); } else putc(*s, output_file); } fprintf(output_file, "'\","); } } else { k = strlen(s) + 3; j += k; if (j > 80) { if (!rflag) ++outline; putc('\n', output_file); j = k; } putc('"', output_file); do { putc(*s, output_file); } while (*++s); fprintf(output_file, "\","); } } else { j += 2; if (j > 80) { if (!rflag) ++outline; putc('\n', output_file); j = 2; } fprintf(output_file, "0,"); } } if (!rflag) outline += 2; fprintf(output_file, "\n};\n"); FREE(symnam); if (!rflag) ++outline; if (!rflag) fprintf(output_file, "static "); fprintf(output_file, "char *yyrule[] = {\n"); for (i = 2; i < nrules; ++i) { fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]); for (j = rrhs[i]; ritem[j] > 0; ++j) { s = symbol_name[ritem[j]]; if (s[0] == '"') { fprintf(output_file, " \\\""); while (*++s != '"') { if (*s == '\\') { if (s[1] == '\\') fprintf(output_file, "\\\\\\\\"); else fprintf(output_file, "\\\\%c", s[1]); ++s; } else putc(*s, output_file); } fprintf(output_file, "\\\""); } else if (s[0] == '\'') { if (s[1] == '"') fprintf(output_file, " '\\\"'"); else if (s[1] == '\\') { if (s[2] == '\\') fprintf(output_file, " '\\\\\\\\"); else fprintf(output_file, " '\\\\%c", s[2]); s += 2; while (*++s != '\'') putc(*s, output_file); putc('\'', output_file); } else fprintf(output_file, " '%c'", s[1]); } else fprintf(output_file, " %s", s); } if (!rflag) ++outline; fprintf(output_file, "\",\n"); } if (!rflag) outline += 2; fprintf(output_file, "};\n#endif\n");}void output_stype(){ if (!unionized && ntags == 0) { outline += 3; fprintf(code_file, "#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n"); }}void output_trailing_text(){ register int c, last; register FILE *in, *out; if (line == 0) return; in = input_file; out = code_file; c = *cptr; if (c == '\n') { ++lineno; if ((c = getc(in)) == EOF) return; if (!lflag) { ++outline; fprintf(out, line_format, lineno, (inc_file?inc_file_name:input_file_name)); } if (c == '\n') ++outline; putc(c, out); last = c; } else { if (!lflag) { ++outline; fprintf(out, line_format, lineno, (inc_file?inc_file_name:input_file_name)); } do { putc(c, out); } while ((c = *++cptr) != '\n'); ++outline; putc('\n', out); last = '\n'; } while ((c = getc(in)) != EOF) { if (c == '\n') ++outline; putc(c, out); last = c; } if (last != '\n') { ++outline; putc('\n', out); } if (!lflag) fprintf(out, line_format, ++outline + 1, code_file_name);}void output_semantic_actions(){ register int c, last; register FILE *out; register int state; /* 0=middle of line, 1=start of line, 2=seen '#' */ state = 1; fclose(action_file); action_file = fopen(action_file_name, "r"); if (action_file == NULL) open_error(action_file_name); if ((c = getc(action_file)) == EOF) return; out = code_file; do { last = c; if (c == '\n') { ++outline; if (state == 2) { fprintf(out, line_format+1, outline + 1, code_file_name); state = 1; continue; } state = 1; } else if (state == 1 && c == '#') state = 2; else state = 0; putc(c, out); } while ((c = getc(action_file)) != EOF); if (last != '\n') { ++outline; putc('\n', out); } if (!lflag) fprintf(out, line_format, ++outline + 1, code_file_name);}void free_itemsets(){ register core *cp, *next; FREE(state_table); for (cp = first_state; cp; cp = next) { next = cp->next; FREE(cp); }}void free_shifts(){ register shifts *sp, *next; FREE(shift_table); for (sp = first_shift; sp; sp = next) { next = sp->next; FREE(sp); }}void free_reductions(){ register reductions *rp, *next; FREE(reduction_table); for (rp = first_reduction; rp; rp = next) { next = rp->next; FREE(rp); }}void write_section(char *section_name){ char **section; FILE *fp; int i; struct section *sl; for(sl=§ion_list[0]; sl->name; sl++) { if(strcmp(sl->name,section_name)==0) { break; } } if(sl->name==0) { fprintf(stderr, "Cannot find section '%s' in your skeleton file\n", section_name); exit(1); } section = sl->ptr; fp = code_file; for (i = lflag ? 1 : 0; section[i]; ++i) { ++outline; fprintf(fp, "%s\n", section[i]); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -