X-Git-Url: https://ocean-lang.org/code/?a=blobdiff_plain;f=csrc%2Fparsergen.mdc;h=93065928492d0d164433fbce946e47e814f8c2d5;hb=399f329936d9b11f48257f0f6aa323d65ccc6aaf;hp=19703bce82000b2ce642a29e9e6ad5c15bd91d3a;hpb=b5039c5ba828498822903abe4b68cde2a8124aa5;p=ocean diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index 19703bc..9306592 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -2601,14 +2601,14 @@ since the last state which could have been at the start of a line. if (!tk) tk = tok_copy(token_next(tokens)); next.sym = tk->num; - if (trace) - parser_trace(trace, &p, &next, tk, states, non_term, config->known_count); + parser_trace(trace, &p, &next, tk, states, non_term, config->known_count); if (next.sym == TK_in) { next.starts_indented = 1; next.indents = 1; free(tk); tk = NULL; + parser_trace_action(trace, "Record"); continue; } if (next.sym == TK_out) { @@ -2625,6 +2625,7 @@ since the last state which could have been at the start of a line. } free(tk); tk = NULL; + parser_trace_action(trace, "Cancel"); continue; } // fall through and force a REDUCE (as 'shift' @@ -2634,6 +2635,7 @@ since the last state which could have been at the start of a line. if (! tos->newline_permitted) { free(tk); tk = NULL; + parser_trace_action(trace, "Discard"); continue; } } @@ -2641,6 +2643,7 @@ since the last state which could have been at the start of a line. tk = NULL; next.starts_indented = 0; next.indents = 0; + parser_trace_action(trace, "Shift"); continue; } if (states[tos->state].reduce_prod >= 0) { @@ -2673,6 +2676,7 @@ since the last state which could have been at the start of a line. accepted = 1; ret = res; } + parser_trace_action(trace, "Reduce"); continue; } if (tk->num == TK_out) { @@ -2683,6 +2687,7 @@ since the last state which could have been at the start of a line. frame.sym = states[tos->state].shift_sym; shift(&p, &frame, tok_copy(*tk), states); // FIXME need to report this error somehow + parser_trace_action(trace, "Synthesize"); continue; } /* Error. We walk up the stack until we @@ -2692,6 +2697,7 @@ since the last state which could have been at the start of a line. * Then we discard input tokens until * we find one that is acceptable. */ + parser_trace_action(trace, "ERROR"); err_tk = tok_copy(*tk); next.sym = TK_error; @@ -2777,6 +2783,8 @@ end inside square brackets. const char *non_term[], int knowns) { int i; + if (!trace) + return; for (i = 0; i < p->tos; i++) { struct frame *f = &p->stack[i]; if (i) { @@ -2806,7 +2814,13 @@ end inside square brackets. if (n->indents) fprintf(trace, "%c%d", n->starts_indented?':':'.', n->indents); - fputs("]\n", trace); + fputs("]", trace); + } + + void parser_trace_action(FILE *trace, char *action) + { + if (trace) + fprintf(trace, " - %s\n", action); } # A Worked Example