📄 tabutil.c
字号:
PRNT(msg_line); if (scopes_bit) { for (i = 1; i <= scope_rhs_size; i++) { if (scope_right_side[i] != 0) scope_right_side[i] = symbol_map[scope_right_side[i]]; } for (i = 1; i <= num_scopes; i++) { scope[i].look_ahead = symbol_map[scope[i].look_ahead]; if (table_opt == OPTIMIZE_TIME) scope[i].lhs_symbol = symbol_map[scope[i].lhs_symbol]; else scope[i].lhs_symbol = symbol_map[scope[i].lhs_symbol] - num_terminals; } k = 0; for (i = 1; i <= num_scopes; i++) { field(scope[i].prefix, 4); k++; if (k == 18) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); k = 0; } } if (k != 0) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); } k = 0; for (i = 1; i <= num_scopes; i++) { field(scope[i].suffix, 4); k++; if (k == 18) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); k = 0; } } if (k != 0) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); } k = 0; for (i = 1; i <= num_scopes; i++) { field(scope[i].lhs_symbol, 4); k++; if (k == 18) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); k = 0; } } if (k != 0) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); } k = 0; for (i = 1; i <= num_scopes; i++) { field(scope[i].look_ahead, 4); k++; if (k == 18) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); k = 0; } } if (k != 0) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); } k = 0; for (i = 1; i <= num_scopes; i++) { field(scope[i].state_set, 4); k++; if (k == 18) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); k = 0; } } if (k != 0) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); } k = 0; for (i = 1; i <= scope_rhs_size; i++) { field(scope_right_side[i], 4); k++; if (k == 18) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); k = 0; } } if (k != 0) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); } k = 0; for (i = 1; i <= scope_state_size; i++) { if (scope_state[i] == 0) field(0, 6); else field(state_index[scope_state[i]] + num_rules, 6); k++; if (k == 12) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); k = 0; } } if (k != 0) { *output_ptr++ = '\n'; BUFFER_CHECK(systab); } if (table_opt == OPTIMIZE_TIME) { num_bytes = 5 * num_scopes + scope_rhs_size+ scope_state_size; if (num_symbols > 255) num_bytes += (2 * num_scopes + scope_rhs_size); } else { num_bytes = 5 * num_scopes + scope_rhs_size+ 2 * scope_state_size; if (num_non_terminals > 255) num_bytes += num_scopes; if (num_terminals > 255) num_bytes += num_scopes; if (num_symbols > 255) num_bytes += scope_rhs_size; } if (scope_rhs_size > 255) num_bytes += (2 * num_scopes); if (scope_state_size > 255) num_bytes += num_scopes; sprintf(msg_line, " Storage required for SCOPE map: %d Bytes", num_bytes); PRNT(msg_line); } if (original != NULL) { ffree(original); } ffree(symbol_root); ffree(symbol_count); ffree(temp); ffree(state_start); ffree(state_stack); ffree(term_list); return;}/*********************************************************************//* COMPUTE_ACTION_SYMBOLS_RANGE: *//*********************************************************************//* *//* This procedure computes the range of the ACTION_SYMBOLS map after *//* Optimal Partitioning has been used to compress that map. Its *//* first argument is an array, STATE_START, that indicates the *//* starting location in the compressed vector for each state. When *//* a value of STATE_START is negative it indicates that the state in *//* question shares its elements with another state. Its second *//* argument, STATE_STACK, is an array that contains the elements of *//* the partition created by PARTSET. Each element of the partition *//* is organized as a circular list where the smallest sets appear *//* first in the list. *//* *//*********************************************************************/void compute_action_symbols_range(short *state_start, short *state_stack, short *state_list, short *action_symbols_range){ int i, j, k, state_no, state, symbol, symbol_root; BOOLEAN end_node; short *symbol_list; symbol_list = Allocate_short_array(num_symbols + 1); /*********************************************************************/ /* We now write out the range elements of the ACTION_SYMBOLS map. */ /* Recall that if STATE_START has a negative value, then the set in */ /* question is sharing elements and does not need to be processed. */ /*********************************************************************/ k = 0; for ALL_SYMBOLS(j) symbol_list[j] = OMEGA; /* Initialize all links to OMEGA */ for ALL_STATES(i) { state_no = state_list[i]; if (state_start[state_no] > 0) { symbol_root = 0; /* Add "fence" element: 0 to list */ symbol_list[symbol_root] = NIL; /*************************************************************/ /* Pop a state from the stack, and add each of its elements */ /* that has not yet been processed into the list. */ /* Continue until stack is empty... */ /* Recall that the stack is represented by a circular queue. */ /*************************************************************/ for (end_node = ((state = state_no) == NIL); ! end_node; end_node = (state == state_no)) { struct shift_header_type sh; struct reduce_header_type red; state = state_stack[state]; sh = shift[statset[state].shift_number]; for (j = 1; j <= sh.size; j++) { symbol = SHIFT_SYMBOL(sh, j); if (symbol_list[symbol] == OMEGA) { symbol_list[symbol] = symbol_root; symbol_root = symbol; } } red = reduce[state]; for (j = 1; j <= red.size; j++) { symbol = REDUCE_SYMBOL(red, j); if (symbol_list[symbol] == OMEGA) { symbol_list[symbol] = symbol_root; symbol_root = symbol; } } } /*************************************************************/ /* Write the list out. */ /*************************************************************/ for (symbol = symbol_root; symbol != NIL; symbol = symbol_root) { symbol_root = symbol_list[symbol]; symbol_list[symbol] = OMEGA; action_symbols_range[k++] = symbol; } } } ffree(symbol_list); return;}/*********************************************************************//* COMPUTE_NACTION_SYMBOLS_RANGE: *//*********************************************************************//* This procedure computes the range of the NACTION_SYMBOLS map. It *//* organization is analoguous to COMPUTE_ACTION_SYMBOLS_RANGE. *//*********************************************************************/void compute_naction_symbols_range(short *state_start, short *state_stack, short *state_list, short *naction_symbols_range){ int i, j, k, state_no, state, symbol, symbol_root; BOOLEAN end_node; short *symbol_list; symbol_list = Allocate_short_array(num_symbols + 1); /*********************************************************************/ /* We now write out the range elements of the NACTION_SYMBOLS map. */ /* Recall that if STATE_START has a negative value, then the set in */ /* question is sharing elements and does not need to be processed. */ /*********************************************************************/ k = 0; for ALL_SYMBOLS(j) symbol_list[j] = OMEGA; /* Initialize all links to OMEGA */ for ALL_STATES(i) { state_no = state_list[i]; if (state_start[state_no] > 0) { symbol_root = 0; /* Add "fence" element: 0 to list */ symbol_list[symbol_root] = NIL; /*************************************************************/ /* Pop a state from the stack, and add each of its elements */ /* that has not yet been processed into the list. */ /* Continue until stack is empty... */ /* Recall that the stack is represented by a circular queue. */ /*************************************************************/ for (end_node = ((state = state_no) == NIL); ! end_node; end_node = (state == state_no)) { state = state_stack[state]; for (j = gd_index[state]; j <= gd_index[state + 1] - 1; j++) { symbol = gd_range[j]; if (symbol_list[symbol] == OMEGA) { symbol_list[symbol] = symbol_root; symbol_root = symbol; } } } /**********************************************************/ /* Write the list out. */ /**********************************************************/ for (symbol = symbol_root; symbol != NIL; symbol = symbol_root) { symbol_root = symbol_list[symbol]; symbol_list[symbol] = OMEGA; naction_symbols_range[k++] = symbol; } } } ffree(symbol_list); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -