📄 ctabs.c
字号:
("\nconst unsigned char CLASS_HEADER scope_rhs[] = {0,\n", 1, scope_rhs_size, 10, scope_right_side); } } else { if (java_bit) { prnt_shorts ("\n public final static char scope_rhs[] = {0,\n", 1, scope_rhs_size, 10, scope_right_side); } else { prnt_shorts ("\nconst unsigned short CLASS_HEADER scope_rhs[] = {0,\n", 1, scope_rhs_size, 10, scope_right_side); } } if (java_bit) mystrcpy("\n public final static char scope_state[] = {0,\n"); else mystrcpy("\nconst unsigned short CLASS_HEADER scope_state[] = {0,\n"); padline(); k = 0; for (i = 1; i <= scope_state_size; i++) { if (scope_state[i] == 0) itoc(0); else itoc(state_index[scope_state[i]] + num_rules); *output_ptr++ = COMMA; k++; if (k == 10 && i != scope_state_size) { *output_ptr++ = '\n'; BUFFER_CHECK(sysdcl); padline(); k = 0; } } if (k != 0) { *(output_ptr - 1) = '\n'; BUFFER_CHECK(sysdcl); } if (java_bit) mystrcpy(" };\n"); else mystrcpy(" };\n"); if (num_symbols <= (java_bit ? 127 : 255)) { if (java_bit) mystrcpy("\n public final static byte in_symb[] = {0,\n"); else mystrcpy("\nconst unsigned char CLASS_HEADER in_symb[] = {0,\n"); } else { if (java_bit) mystrcpy("\n public final static char in_symb[] = {0,\n"); else mystrcpy("\nconst unsigned short CLASS_HEADER in_symb[] = {0,\n"); } /* Transition symbol */ padline(); *output_ptr++ = '0'; *output_ptr++ = COMMA; k = 1; for (state_no = 2; state_no <= (int) num_states; state_no++) { struct node *q; int item_no; q = statset[state_no].kernel_items; if (q != NULL) { item_no = q -> value - 1; i = item_table[item_no].symbol; } else i = 0; itoc(symbol_map[i]); *output_ptr++ = COMMA; k++; if (k == 10 && state_no != (int) num_states) { *output_ptr++ = '\n'; BUFFER_CHECK(sysdcl); padline(); k = 0; } } if (k != 0) { *(output_ptr - 1) = '\n'; BUFFER_CHECK(sysdcl); } if (java_bit) mystrcpy(" };\n"); else mystrcpy(" };\n"); } return;}/****************************************************************************//* PRINT_SYMBOLS: *//****************************************************************************/static void print_symbols(void){ int symbol; char line[SYMBOL_SIZE + /* max length of a token symbol */ 2 * MAX_PARM_SIZE + /* max length of prefix + suffix */ 64]; /* +64 for error messages lines */ /* or other fillers(blank, =,...)*/ if (java_bit) { strcpy(line, "interface "); strcat(line, sym_tag); strcat(line, "\n{\n public final static int\n"); } else strcpy(line, "enum {\n"); /*********************************************************/ /* We write the terminal symbols map. */ /*********************************************************/ for ALL_TERMINALS(symbol) { char *tok = RETRIEVE_STRING(symbol); fprintf(syssym, "%s", line); if (tok[0] == '\n' || tok[0] == escape) { tok[0] = escape; sprintf(line, "Escaped symbol %s is an invalid C variable.\n",tok); PRNT(line); } else if (strpbrk(tok, "!%^&*()-+={}[];:\"`~|\\,.<>/?\'") != NULL) { sprintf(line, "%s may be an invalid variable name.\n", tok); PRNT(line); } sprintf(line, " %s%s%s = %i,\n\0", prefix, tok, suffix, symbol_map[symbol]); if (c_bit || cpp_bit) { while(strlen(line) > PARSER_LINE_SIZE) { fwrite(line, sizeof(char), PARSER_LINE_SIZE - 2, syssym); fprintf(syssym, "\\\n"); strcpy(line, &line[PARSER_LINE_SIZE - 2]); } } } line[strlen(line) - 2] = '\0'; /* remove the string ",\n" from last line */ fprintf(syssym, "%s%s", line, (java_bit ? ";\n}\n" : "\n };\n")); return;}/****************************************************************************//* PRINT_DEFINITIONS: *//****************************************************************************/static void print_definitions(void){ if (java_bit) fprintf(sysdef, "interface %s\n{\n public final static int\n\n", def_tag); else fprintf(sysdef, "enum {\n"); if (error_maps_bit) { if (java_bit) fprintf(sysdef, " ERROR_SYMBOL = %d,\n" " MAX_NAME_LENGTH = %d,\n" " NUM_STATES = %d,\n\n", error_image, max_name_length, num_states); else { if (! jikes_bit) fprintf(sysdef, " ERROR_CODE,\n" " BEFORE_CODE,\n" " INSERTION_CODE,\n" " INVALID_CODE,\n" " SUBSTITUTION_CODE,\n" " DELETION_CODE,\n" " MERGE_CODE,\n" " MISPLACED_CODE,\n" " SCOPE_CODE,\n" " MANUAL_CODE,\n" " SECONDARY_CODE,\n" " EOF_CODE,\n\n"); fprintf(sysdef, " ERROR_SYMBOL = %d,\n" " MAX_DISTANCE = %d,\n" " MIN_DISTANCE = %d,\n" " MAX_NAME_LENGTH = %d,\n" " MAX_TERM_LENGTH = %d,\n" " NUM_STATES = %d,\n\n", error_image, maximum_distance, minimum_distance, max_name_length, max_name_length, num_states); } } if (java_bit) fprintf(sysdef, " NT_OFFSET = %d,\n" " SCOPE_UBOUND = %d,\n" " SCOPE_SIZE = %d,\n" " LA_STATE_OFFSET = %d,\n" " MAX_LA = %d,\n" " NUM_RULES = %d,\n" " NUM_TERMINALS = %d,\n" " NUM_NON_TERMINALS = %d,\n" " NUM_SYMBOLS = %d,\n" " START_STATE = %d,\n" " EOFT_SYMBOL = %d,\n" " EOLT_SYMBOL = %d,\n" " ACCEPT_ACTION = %d,\n" " ERROR_ACTION = %d;\n" "};\n\n", (table_opt == OPTIMIZE_SPACE ? num_terminals : num_symbols), num_scopes - 1, num_scopes, (read_reduce_bit && lalr_level > 1 ? error_act + num_rules : error_act), lalr_level, num_rules, num_terminals, num_non_terminals, num_symbols, state_index[1] + num_rules, eoft_image, eolt_image, accept_act, error_act); else fprintf(sysdef, " NT_OFFSET = %d,\n" " BUFF_UBOUND = %d,\n" " BUFF_SIZE = %d,\n" " STACK_UBOUND = %d,\n" " STACK_SIZE = %d,\n" " SCOPE_UBOUND = %d,\n" " SCOPE_SIZE = %d,\n" " LA_STATE_OFFSET = %d,\n" " MAX_LA = %d,\n" " NUM_RULES = %d,\n" " NUM_TERMINALS = %d,\n" " NUM_NON_TERMINALS = %d,\n" " NUM_SYMBOLS = %d,\n" " START_STATE = %d,\n" " EOFT_SYMBOL = %d,\n" " EOLT_SYMBOL = %d,\n" " ACCEPT_ACTION = %d,\n" " ERROR_ACTION = %d\n" " };\n\n", (table_opt == OPTIMIZE_SPACE ? num_terminals : num_symbols), maximum_distance + lalr_level - 1, maximum_distance + lalr_level, stack_size - 1, stack_size, num_scopes - 1, num_scopes, (read_reduce_bit && lalr_level > 1 ? error_act + num_rules : error_act), lalr_level, num_rules, num_terminals, num_non_terminals, num_symbols, state_index[1] + num_rules, eoft_image, eolt_image, accept_act, error_act); return;}/****************************************************************************//* PRINT_EXTERNS: *//****************************************************************************/static void print_externs(void){ if (c_bit || cpp_bit) { fprintf(sysprs, "%s SCOPE_REPAIR\n" "%s DEFERRED_RECOVERY\n" "%s FULL_DIAGNOSIS\n" "%s SPACE_TABLES\n\n", (num_scopes > 0 ? "#define" : "#undef "), (deferred_bit ? "#define" : "#undef "), (error_maps_bit ? "#define" : "#undef "), (table_opt == OPTIMIZE_SPACE ? "#define" : "#undef ")); } if (c_bit) fprintf(sysprs, "#define original_state(state) (-%s[state])\n" "#define asi(state) asb[original_state(state)]\n" "#define nasi(state) nasb[original_state(state)]\n" "#define in_symbol(state) in_symb[original_state(state)]\n\n", (table_opt == OPTIMIZE_TIME ? "check" : "base_check")); else if (cpp_bit) { fprintf(sysprs, "class LexStream;\n\n" "class %s_table\n" "{\n" "public:\n", prs_tag); if (error_maps_bit || debug_bit) fprintf(sysprs, " static int original_state(int state) " "{ return -%s[state]; }\n", (table_opt == OPTIMIZE_TIME ? "check" : "base_check")); if (error_maps_bit) { fprintf(sysprs, " static int asi(int state) " "{ return asb[original_state(state)]; }\n" " static int nasi(int state) " "{ return nasb[original_state(state)]; }\n"); if (num_scopes > 0) fprintf(sysprs, " static int in_symbol(int state) " "{ return in_symb[original_state(state)]; }\n"); } fprintf(sysprs, "\n"); } else if (java_bit) { fprintf(sysprs, "abstract class %s extends %s implements %s\n{\n", prs_tag, dcl_tag, def_tag); if (error_maps_bit || debug_bit) { fprintf(sysprs, " public final static int original
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -