diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/output.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/output.cpp b/src/output.cpp index 33c6bb1..d14b1b9 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -183,8 +183,8 @@ void output_t::emit_state_shift(unsigned i) { else std::fprintf(source_file, "\t\t\tcase %s%s:\n", token_prefix(), token.get_value().c_str()); - std::fprintf(source_file, "\t\t\t\tparser->stack[++parser->top].state = %u;\n", unsigned(it->second)); std::fprintf(source_file, "\t\t\t\tparser->stack[parser->top].value.token = *value;\n"); + std::fprintf(source_file, "\t\t\t\tparser->stack[++parser->top].state = %u;\n", unsigned(it->second)); std::fprintf(source_file, "\t\t\t\treturn 1;\n\n"); } @@ -326,7 +326,10 @@ void output_t::emit_source() { std::fprintf(source_file, "};\n\n\n"); std::fprintf(source_file, "%scontext_t * %salloc(void *(*alloc_func)(size_t)) {\n", prefix(), prefix()); - std::fprintf(source_file, "\treturn (%scontext_t *)alloc_func(sizeof(%scontext_t));\n", prefix(), prefix()); + std::fprintf(source_file, "\t%scontext_t *parser = (%scontext_t *)alloc_func(sizeof(%scontext_t));\n", prefix(), prefix(), prefix()); + std::fprintf(source_file, "\tparser->top = 0;\n"); + std::fprintf(source_file, "\tparser->stack[0].state = 0;\n"); + std::fprintf(source_file, "\treturn parser;\n"); std::fprintf(source_file, "}\n\n"); std::fprintf(source_file, "void %sfree(%scontext_t *parser, void (*free_func)(void *)) {\n", prefix(), prefix()); |