###### parser functions
+ static char *reserved_words[] = {
+ [TK_error] = "ERROR",
+ [TK_in] = "IN",
+ [TK_out] = "OUT",
+ [TK_newline] = "NEWLINE",
+ [TK_eof] = "$eof",
+ };
void parser_trace(FILE *trace, struct parser *p,
struct token *tk, const struct state states[],
const char *non_term[], int knowns)
for (i = 0; i < p->tos; i++) {
int sym = p->stack[i].sym;
fprintf(trace, "(%d) ", p->stack[i].state);
- if (sym < TK_reserved + knowns) {
+ if (sym < TK_reserved &&
+ reserved_words[sym] != NULL)
+ fputs(reserved_words[sym], trace);
+ else if (sym < TK_reserved + knowns) {
struct token *t = p->asn_stack[i];
text_dump(trace, t->txt, 20);
} else
fputs(" ", trace);
}
fprintf(trace, "(%d) [", p->state);
- text_dump(trace, tk->txt, 20);
+ if (tk->num < TK_reserved &&
+ reserved_words[tk->num] != NULL)
+ fputs(reserved_words[tk->num], trace);
+ else
+ text_dump(trace, tk->txt, 20);
fputs("]\n", trace);
}