📄 jikespg.g
字号:
{ if (image == empty || image == eolt_image || image == eoft_image || image > num_terminals) { restore_symbol(tok_string, kerror); sprintf(msg_line, "Illegal alias for symbol %s. " "Line %d, column %d.", tok_string, SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12); } alias_map(kerror, image); error_image = image; } else { restore_symbol(tok_string, kerror); sprintf(msg_line, "Symbol %s was previously defined. " "Line %d, column %d", tok_string, SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12); } break; case EOF_SYMBOL_TK: if (eoft_image > num_terminals) { if (image == empty || image == eolt_image || image == error_image || image > num_terminals) { restore_symbol(tok_string, keoft); sprintf(msg_line, "Illegal alias for symbol %s. " "Line %d, column %d.", tok_string, SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12); } alias_map(keoft, image); eoft_image = image; } else { restore_symbol(tok_string, keoft); sprintf(msg_line, "Symbol %s was previously defined. " "Line %d, column %d", tok_string, SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12); } break; default: /* if SYM1.kind == EOL_SYMBOL */ if (eolt_image == OMEGA) { if (image == empty || image == eoft_image || image == error_image || image > num_terminals) { sprintf(msg_line, "Illegal alias for symbol EOL. " "Line %d, column %d.", SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12); } eolt_image = image; } else { sprintf(msg_line, "Symbol EOL was previously defined. " "Line %d, column %d", SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12); } break; } return;}./ | bad_alias_lhs/:$no_action:/ | alias_lhs bad_alias_rhs/:$no_action:/ | alias_lhs produces bad_alias_rhs/:$no_action:/ alias_lhs ::= SYMBOL/:$no_action:/ | ERROR_SYMBOL/:$no_action:/ | EOL_SYMBOL/:$no_action:/ | EOF_SYMBOL/:$no_action:/ alias_rhs ::= SYMBOL/:$no_action:/ | ERROR_SYMBOL/:$no_action:/ | EOL_SYMBOL/:$no_action:/ | EOF_SYMBOL/:$no_action:/ | EMPTY_SYMBOL/:$no_action:/ | '|'/:$no_action:/ | produces/:$no_action:/ bad_alias_rhs ::= DEFINE_KEY/:$offset bad_alias_rhs, /* $rule_number */://.$locationstatic void bad_alias_rhs(void){ sprintf(msg_line, "Misplaced keyword found in Alias section. " "Line %d, column %d", SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12);}./ | TERMINALS_KEY/:$offset bad_alias_rhs, /* $rule_number */:/ | ALIAS_KEY/:$offset bad_alias_rhs, /* $rule_number */:/ | BLOCK/:$offset $action://.$locationstatic void act$rule_number(void){ sprintf(msg_line, "Misplaced block found in Alias section. " "Line %d, column %d", SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12);}./ bad_alias_lhs ::= bad_alias_rhs/:$no_action:/ | EMPTY_SYMBOL/:$offset $action://.$locationstatic void act$rule_number(void){ sprintf(msg_line, "Empty symbol cannot be aliased. " "Line %d, column %d", SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12);}./ | produces/:$offset missing_quote, /* $rule_number */://.$locationstatic void missing_quote(void){ sprintf(msg_line, "Symbol must be quoted when used as a " "grammar symbol. Line %d, column %d", ormark, SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12);}./ | '|'/:$offset missing_quote, /* $rule_number */:/ start_block ::= START_KEY {start_symbol}/:$no_action:/ start_symbol ::= SYMBOL/:$offset $action://.$location/*********************************************************************//*********************************************************************/static void act$rule_number(void){ register struct node *q; assign_symbol_no(SYM1.name, OMEGA); q = Allocate_node(); q -> value = symbol_image(SYM1.name); if (start_symbol_root == NULL) q -> next = q; else { q -> next = start_symbol_root -> next; start_symbol_root -> next = q; } start_symbol_root = q; num_rules++; num_items++; SHORT_CHECK(num_items); return;}./ | '|' -- No Good !!!/:$offset bad_start_symbol, /* $rule_number */://.$locationstatic void bad_start_symbol(void){ sprintf(msg_line, "Symbol cannot be used as Start symbol. " "Line %d, column %d", SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12);}./ | EMPTY_SYMBOL -- No good !!!/:$offset bad_start_symbol, /* $rule_number */:/ | ERROR_SYMBOL -- No good !!!/:$offset bad_start_symbol, /* $rule_number */:/ | produces -- No good !!!/:$offset bad_start_symbol, /* $rule_number */:/ | BLOCK -- No good !!!/:$offset $action://.$locationstatic void act$rule_number(void){ sprintf(msg_line, "Misplaced block found in Start section. " "Line %d, column %d", SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12);}./ | DEFINE_KEY -- No good !!!/:$offset misplaced_keyword_found_in_START_section, /* $rule_number */://.$locationstatic void misplaced_keyword_found_in_START_section(void){ sprintf(msg_line, "Misplaced keyword found in START section. " "Line %d, column %d", SYM1.start_line, SYM1.start_column); PRNTERR(msg_line); exit(12);}./ | TERMINALS_KEY -- No good !!!/:$offset misplaced_keyword_found_in_START_section, /* $rule_number */:/ | ALIAS_KEY -- No good !!!/:$offset misplaced_keyword_found_in_START_section, /* $rule_number */:/ | START_KEY -- No good !!!/:$offset misplaced_keyword_found_in_START_section, /* $rule_number */:/ rules_block ::= RULES_KEY/:$offset $action://.$locationstatic void act$rule_number(void){ register struct node *q; if (start_symbol_root == NULL) { q = Allocate_node(); q -> value = empty; q -> next = q; start_symbol_root = q; num_rules = 0; /* One rule */ num_items = 0; /* 0 items */ } build_symno(); return;}./ | RULES_KEY rule_list/:$offset $action://.$locationstatic void act$rule_number(void){ build_symno(); return;}./ produces ::= '::='/:$no_action:/ | '->'/:$no_action:/ rule_list ::= {action_block} SYMBOL produces/:$offset $action://.$locationstatic void act$rule_number(void){ register struct node *q; assign_symbol_no(SYM2.name, OMEGA); if (start_symbol_root == NULL) { q = Allocate_node(); q -> value = symbol_image(SYM2.name); q -> next = q; start_symbol_root = q; num_rules = 1; num_items = 1; }/*********************************************************************//* Since we don't know for sure how many start symbols we have, a *//* "while" loop is used to increment the size of rulehdr. However, *//* it is highly unlikely that this loop would ever execute more than *//* once if the size of RULE_INCREMENT is reasonable. *//*********************************************************************/ while (num_rules >= (int)rulehdr_size) { rulehdr_size += RULEHDR_INCREMENT; rulehdr = (struct rulehdr_type *) (rulehdr == (struct rulehdr_type *) NULL ? malloc(rulehdr_size * sizeof(struct rulehdr_type)) : realloc(rulehdr, rulehdr_size * sizeof(struct rulehdr_type))); if (rulehdr == (struct rulehdr_type *) NULL) nospace(__FILE__, __LINE__); } rulehdr[num_rules].sp = ((SYM3.kind == ARROW_TK) ? TRUE : FALSE); rulehdr[num_rules].lhs = symbol_image(SYM2.name); rulehdr[num_rules].rhs_root = NULL; return;}./ | rule_list '|'/:$offset $action://.$locationstatic void act$rule_number(void){ num_rules++; if (num_rules >= (int)rulehdr_size) { rulehdr_size += RULEHDR_INCREMENT; rulehdr = (struct rulehdr_type *) (rulehdr == (struct rulehdr_type *) NULL ? malloc(rulehdr_size * sizeof(struct rulehdr_type)) : realloc(rulehdr, rulehdr_size * sizeof(struct rulehdr_type))); if (rulehdr == (struct rulehdr_type *) NULL) nospace(__FILE__, __LINE__); } rulehdr[num_rules].sp = rulehdr[num_rules - 1].sp; rulehdr[num_rules].lhs = OMEGA; rulehdr[num_rules].rhs_root = NULL; return;}./ | rule_list SYMBOL produces/:$offset $action://.$locationstatic void act$rule_number(void){ num_rules++; if (num_rules >= (int)rulehdr_size) { rulehdr_size += RULEHDR_INCREMENT; rulehdr = (struct rulehdr_type *) (rulehdr == (struct rulehdr_type *) NULL ? malloc(rulehdr_size * sizeof(struct rulehdr_type)) : realloc(rulehdr, rulehdr_size * sizeof(struct rulehdr_type))); if (rulehdr == (struct rulehdr_type *) NULL) nospace(__FILE__, __LINE__); } rulehdr[num_rules].sp = ((SYM3.kind == ARROW_TK) ? TRUE : FALSE); assign_symbol_no(SYM2.name, OMEGA); rulehdr[num_rules].lhs = symbol_image(SYM2.name); rulehdr[num_rules].rhs_root = NULL; return;}./ | rule_list EMPTY_SYMBOL/:$no_action:/ | rule_list action_block/:$no_action:/ | rule_list ERROR_SYMBOL/:$offset $action://.$locationstatic void act$rule_number(void){ register struct node *q; char tok_string[SYMBOL_SIZE + 1]; if (error_image == DEFAULT_SYMBOL) { restore_symbol(tok_string, kerror); sprintf(msg_line, "%s not declared or aliased to terminal " "symbol. Line %d, column %d", tok_string, SYM2.start_line, SYM2.start_column); PRNTERR(msg_line); exit(12); } q = Allocate_node();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -