summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-04-09 03:58:50 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-04-09 03:58:50 +0200
commit923ce33be1e33b2feda2839b61abca76ee3fcd90 (patch)
treec0660217d0058910d3319e1de25449dc08855486 /src
parent59258d1f71d36502cf778dd089409146fd085c12 (diff)
downloadsolar-923ce33be1e33b2feda2839b61abca76ee3fcd90.tar
solar-923ce33be1e33b2feda2839b61abca76ee3fcd90.zip
output: correctly initialize parser state
Diffstat (limited to 'src')
-rw-r--r--src/output.cpp7
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());