From a67266ff72280b85fed7ec498967a855a5735639 Mon Sep 17 00:00:00 2001 From: kartofen Date: Tue, 1 Jul 2025 00:11:29 +0300 Subject: major refactor, more modular (wow because obviously modularity is always a good thing yes), and etc --- fusion.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'fusion.c') diff --git a/fusion.c b/fusion.c index 1e4579f..3dc7dba 100644 --- a/fusion.c +++ b/fusion.c @@ -1,10 +1,7 @@ #include #include -#include "util-tables.c" -#include "slr-table.c" -#include "lr-parser.c" - +#include "parts/symbol.h" enum symbol { PLUS = 0, MINUS, @@ -23,6 +20,7 @@ int symbol_is_terminal(symbol s) { return s < EP; } int symbol_is_input_end(symbol s) { return s == END_INPUT; } int symbol_is_valid(symbol s) { return s < SYMBOLS_END; } +#include "parts/grammar.h" #define PROD(LHS, _, ...) {LHS, (symbol[]){__VA_ARGS__}, sizeof((symbol[]){__VA_ARGS__})/sizeof(symbol)} struct production grammar[] = { PROD(EP, ->, E, END_INPUT), @@ -37,22 +35,25 @@ struct production grammar[] = { const size_t total_productions = sizeof(grammar)/sizeof(*grammar); -symbol toklist[] = {N0, PLUS, N1, MINUS, N0, N0, END_INPUT}; -symbol *tok = toklist; +#include "parts/toklist.h" +static symbol toklist[] = {N0, PLUS, N1, MINUS, N0, END_INPUT}; +static symbol *tok = toklist; -symbol toklist_eat() { return *(tok++); } -symbol toklist_peek() { return *tok; } +symbol toklist_eat() { return *(tok++); } // unsafe +symbol toklist_peek() { return *tok; } // unsafe + +#include "slr-table.c" +#include "util-tables.c" +#include "lr-parser.c" int main(void) { util_tables_fill(); - table_allocate(); - - itemset_handle((struct item[]){{0, 0}}, 1); + table_fill(); - lr_parser() && (exit(1), 1); + int r = 0; + r = lr_parser(); - seen_sets_free(); table_free(); util_tables_free(); -- cgit v1.2.3