From 923ce33be1e33b2feda2839b61abca76ee3fcd90 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 9 Apr 2015 03:58:50 +0200 Subject: output: correctly initialize parser state --- src/output.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/output.cpp') 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()); -- cgit v1.2.3