From f2bef76fb369d4c9c3e53dca60eb78b75bb02d97 Mon Sep 17 00:00:00 2001 From: kartofen Date: Thu, 3 Jul 2025 19:11:36 +0300 Subject: working more or less parser generator (no semantic action, so pretty much useless --- demos/instant-parser.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'demos/instant-parser.c') diff --git a/demos/instant-parser.c b/demos/instant-parser.c index 3a82b07..57d1f2f 100644 --- a/demos/instant-parser.c +++ b/demos/instant-parser.c @@ -16,13 +16,13 @@ enum symbol { size_t total_symbols = SYMBOLS_END; -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; } +IMPLEMENT_FUNCPTR(int, symbol_is_terminal, (symbol s), { return s < EP; }) +IMPLEMENT_FUNCPTR(int, symbol_is_input_end, (symbol s), { return s == END_INPUT; }) +IMPLEMENT_FUNCPTR(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[] = { +static struct production _grammar[] = { PROD(EP, ->, E, END_INPUT), PROD(E, -->, E, PLUS, T), PROD(E, -->, E, MINUS, T), @@ -33,7 +33,8 @@ struct production grammar[] = { PROD(N, -->, N1), }; -const size_t total_productions = sizeof(grammar)/sizeof(*grammar); +struct production *grammar = _grammar; +size_t total_productions = sizeof(_grammar)/sizeof(*_grammar); #include "parts/toklist.h" static symbol toklist[] = {N0, PLUS, N1, MINUS, N0, END_INPUT}; @@ -51,6 +52,8 @@ int main(void) util_tables_fill(); table_fill(); + table_print(); + int r = 0; r = lr_parser(); -- cgit v1.2.3