summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/output.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/output.cpp b/src/output.cpp
index e1ca496..7f074ab 100644
--- a/src/output.cpp
+++ b/src/output.cpp
@@ -96,7 +96,12 @@ void output_t::emit_header() {
emit_tokens();
emit_token_value();
- std::fprintf(header_file, "typedef struct %scontext %scontext_t;\n", prefix(), prefix());
+ std::fprintf(header_file, "typedef struct %scontext %scontext_t;\n\n", prefix(), prefix());
+
+ std::fprintf(header_file, "%scontext_t * %salloc(void *(*alloc_func)(size_t));\n", prefix(), prefix());
+ std::fprintf(header_file, "void %sfree(%scontext_t *parser, void (*free_func)(void *));\n\n", prefix(), prefix());
+
+ std::fprintf(header_file, "int %spush(%scontext_t *parser, int token, const %stoken_value_t *value);\n", prefix(), prefix(), prefix());
}
void output_t::emit_reduction(unsigned rule_id) {
@@ -295,7 +300,15 @@ void output_t::emit_source() {
std::fprintf(source_file, "struct %scontext {\n", prefix());
std::fprintf(source_file, "\tunsigned top;\n");
std::fprintf(source_file, "\t%scontext_state_t stack[%u];\n", prefix(), stack_size);
- std::fprintf(source_file, "};\n\n");
+ 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, "}\n\n");
+
+ std::fprintf(source_file, "void %sfree(%scontext_t *parser, void (*free_func)(void *)) {\n", prefix(), prefix());
+ std::fprintf(source_file, "\tfree_func(parser);\n");
+ std::fprintf(source_file, "}\n\n");
emit_reductions();