diff options
author | kartofen <mladenovnasko0@gmail.com> | 2025-07-01 00:11:29 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2025-07-01 00:11:29 +0300 |
commit | a67266ff72280b85fed7ec498967a855a5735639 (patch) | |
tree | f53d551e49e2263b5208b9adf1d4c50943f4d59d /util-tables.c | |
parent | 7743cb4f8a06ab79a521c4346aac74b47c8ce224 (diff) |
major refactor, more modular (wow because obviously modularity is always a good thing yes), and etc
Diffstat (limited to 'util-tables.c')
-rw-r--r-- | util-tables.c | 18 |
1 files changed, 9 insertions, 9 deletions
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) |