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 --- util-tables.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'util-tables.c') diff --git a/util-tables.c b/util-tables.c index 0bd227d..83a015c 100644 --- a/util-tables.c +++ b/util-tables.c @@ -9,19 +9,15 @@ void *xcalloc(size_t n, size_t size) { void *addr = calloc(n, size); return addr extern void *xcalloc(size_t n, size_t size); #endif -typedef unsigned int symbol; -extern const size_t total_symbols; +// Requirements +#include "parts/symbol.h" +#include "parts/grammar.h" -extern struct production { - symbol LHS; - symbol *RHS; - size_t nRHS; -} grammar[]; -extern const size_t total_productions; +// Implements +#include "parts/util-tables.h" int **follow; int **first; -// int *nullable; void util_tables_fill() { @@ -110,6 +106,7 @@ void util_tables_print() #ifdef _UTIL_TABLES_STANDALONE +// implement symbol.h enum symbol { PLUS = 0, MINUS, @@ -121,12 +118,14 @@ enum symbol { EP, E, T, N, SYMBOLS_END, }; + const size_t total_symbols = SYMBOLS_END; int symbol_is_terminal(symbol s) { return s < E; } int symbol_is_nonterminal(symbol s) { return s >= E; } int symbol_is_input_end(symbol s) { return s == END_INPUT; } +// implement grammar.h #define PROD(LHS, _, ...) {LHS, (symbol[]){__VA_ARGS__}, sizeof((symbol[]){__VA_ARGS__})/sizeof(symbol)} struct production grammar[] = { PROD(EP, ->, E, END_INPUT), @@ -138,6 +137,7 @@ struct production grammar[] = { PROD(N, -->, N0), PROD(N, -->, N1), }; + const size_t total_productions = sizeof(grammar)/sizeof(*grammar); int main(void) -- cgit v1.2.3