diff --git a/external/bsd/byacc/dist/output.c b/external/bsd/byacc/dist/output.c index 7b5520a..f389adb 100644 --- a/external/bsd/byacc/dist/output.c +++ b/external/bsd/byacc/dist/output.c @@ -898,6 +898,44 @@ output_stored_text(FILE * fp) } static void +output_errmsgs(void) +{ + int i; + action *a; + + start_str_table("errmsg"); + for (i = 0; i < nstates; ++i) + { + int ok = 0; + fprintf(output_file, "/* state %d */ ", i); + for (a = parser[i]; a != NULL; a = a->next) + { + if (!ISTOKEN(a->symbol)) + { + fprintf(stderr, "%s: expected only token symbols: %d\n", + myname, a->symbol); + continue; + } + if (a->symbol == 0) /* $accept */ + continue; + if (!ok) + fprintf(output_file, "\"expected "); + ok = 1; + fprintf(output_file, "%s%s%s", + (a != parser[i] && a->next == NULL? "or " : ""), + (a->symbol == 1? "end of file" : symbol_name[a->symbol]), + (a->next == NULL? "" : + (a == parser[i] && a->next->next == NULL? " " : ", "))); + } + if (ok) + fprintf(output_file, "\"%s\n", (i + 1 < nstates? "," : "")); + else + fprintf(output_file, "0%s\n", (i + 1 < nstates? "," : "")); + } + end_table(); +} + +static void output_debug(void) { int i, j, k, max; @@ -1380,7 +1418,7 @@ free_reductions(void) } static void -output_yyerror_call(const char *msg) +output_yyerror_callx(const char *before, const char *msg, const char *after) { FILE *fp = code_file; @@ -1391,9 +1429,22 @@ output_yyerror_call(const char *msg) for (p = parse_param; p; p = p->next) fprintf(fp, "%s, ", p->name); } - puts_code(fp, "\""); + puts_code(fp, before); puts_code(fp, msg); - putl_code(fp, "\");\n"); + puts_code(fp, after); + putl_code(fp, ");\n"); +} + +static void +output_yyerror_call_expr(const char *msg_expr) +{ + output_yyerror_callx("", msg_expr, ""); +} + +static void +output_yyerror_call(const char *msg) +{ + output_yyerror_callx("\"", msg, "\""); } static void @@ -1474,6 +1525,7 @@ output(void) output_rule_data(); output_yydefred(); output_actions(); + output_errmsgs(); free_parser(); output_debug(); if (rflag) @@ -1499,7 +1551,8 @@ output(void) write_section(code_file, body_vars); } write_section(code_file, body_2); - output_yyerror_call("syntax error"); + output_yyerror_call_expr("yyerrmsg[yystate]?" + " yyerrmsg[yystate] : \"syntax error\""); write_section(code_file, body_3); output_semantic_actions(); write_section(code_file, trailer);