// Returns the index of the nonterminal relative to the first nonterminal ssize_t nonterminal_index(uint32_t symbol, grammar_p g){ ssize_t sym_index = symbol_index(symbol, g); if (sym_index == -1) return -1; return sym_index - g->terminal_count; }
extern void find_the_actions(void) { int i; int32 j; char action_name[MAX_IDENTIFIER_LENGTH]; char action_sub[MAX_IDENTIFIER_LENGTH+4]; if (module_switch) for (i=0; i<no_actions; i++) action_byte_offset[i] = 0; else for (i=0; i<no_actions; i++) { strcpy(action_name, (char *) symbs[action_symbol[i]]); action_name[strlen(action_name) - 3] = '\0'; /* remove "__A" */ strcpy(action_sub, action_name); strcat(action_sub, "Sub"); j = symbol_index(action_sub, -1); if (sflags[j] & UNKNOWN_SFLAG) { error_named_at("No ...Sub action routine found for action:", action_name, slines[action_symbol[i]]); } else if (stypes[j] != ROUTINE_T) { error_named_at("No ...Sub action routine found for action:", action_name, slines[action_symbol[i]]); error_named_at("-- ...Sub symbol found, but not a routine:", action_sub, slines[j]); } else { action_byte_offset[i] = svals[j]; sflags[j] |= USED_SFLAG; } } }
extern void make_fake_action(void) { int i; char action_sub[MAX_IDENTIFIER_LENGTH+4]; get_next_token(); if (token_type != SYMBOL_TT) { ebf_error("new fake action name", token_text); panic_mode_error_recovery(); return; } sprintf(action_sub, "%s__A", token_text); i = symbol_index(action_sub, -1); if (!(sflags[i] & UNKNOWN_SFLAG)) { ebf_error("new fake action name", token_text); panic_mode_error_recovery(); return; } assign_symbol(i, ((grammar_version_number==1)?256:4096)+no_fake_actions++, FAKE_ACTION_T); new_action(token_text, i); if (debugfile_switch) { write_debug_byte(FAKE_ACTION_DBR); write_debug_byte(svals[i]/256); write_debug_byte(svals[i]%256); write_debug_string(token_text); } return; }
extern assembly_operand action_of_name(char *name) { /* Returns the action number of the given name, creating it as a new action name if it isn't already known as such. */ char action_sub[MAX_IDENTIFIER_LENGTH+4]; int j; assembly_operand AO; sprintf(action_sub, "%s__A", name); j = symbol_index(action_sub, -1); if (stypes[j] == FAKE_ACTION_T) { AO.value = svals[j]; AO.marker = 0; if (!glulx_mode) AO.type = LONG_CONSTANT_OT; else set_constant_ot(&AO); sflags[j] |= USED_SFLAG; return AO; } if (sflags[j] & UNKNOWN_SFLAG) { if (no_actions>=MAX_ACTIONS) memoryerror("MAX_ACTIONS",MAX_ACTIONS); new_action(name, no_actions); action_symbol[no_actions] = j; assign_symbol(j, no_actions++, CONSTANT_T); sflags[j] |= ACTION_SFLAG; } sflags[j] |= USED_SFLAG; AO.value = svals[j]; AO.marker = ACTION_MV; if (!glulx_mode) { AO.type = (module_switch)?LONG_CONSTANT_OT:SHORT_CONSTANT_OT; if (svals[j] >= 256) AO.type = LONG_CONSTANT_OT; } else { AO.type = CONSTANT_OT; } return AO; }
extern void make_fake_action(void) { int i; char action_sub[MAX_IDENTIFIER_LENGTH+4]; debug_location_beginning beginning_debug_location = get_token_location_beginning(); get_next_token(); if (token_type != SYMBOL_TT) { discard_token_location(beginning_debug_location); ebf_error("new fake action name", token_text); panic_mode_error_recovery(); return; } sprintf(action_sub, "%s__A", token_text); i = symbol_index(action_sub, -1); if (!(sflags[i] & UNKNOWN_SFLAG)) { discard_token_location(beginning_debug_location); ebf_error("new fake action name", token_text); panic_mode_error_recovery(); return; } assign_symbol(i, ((grammar_version_number==1)?256:4096)+no_fake_actions++, FAKE_ACTION_T); new_action(token_text, i); if (debugfile_switch) { debug_file_printf("<fake-action>"); debug_file_printf("<identifier>##%s</identifier>", token_text); debug_file_printf("<value>%d</value>", svals[i]); get_next_token(); write_debug_locations (get_token_location_end(beginning_debug_location)); put_token_back(); debug_file_printf("</fake-action>"); } return; }
extern void find_the_actions(void) { int i; int32 j; char action_sub[MAX_IDENTIFIER_LENGTH+4]; if (module_switch) for (i=0; i<no_actions; i++) action_byte_offset[i] = 0; else for (i=0; i<no_actions; i++) { strcpy(action_sub, (char *) symbs[action_symbol[i]]); strcpy(action_sub + strlen(action_sub) - 3, "Sub"); j = symbol_index(action_sub, -1); if (sflags[j] & UNKNOWN_SFLAG) error_named("There is no action routine called", action_sub); else if (stypes[j] != ROUTINE_T) error_named("Not an action routine:", action_sub); else { action_byte_offset[i] = svals[j]; sflags[j] |= USED_SFLAG; } } }