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 --- lr-parser.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lr-parser.c') diff --git a/lr-parser.c b/lr-parser.c index 2358164..9f7ea24 100644 --- a/lr-parser.c +++ b/lr-parser.c @@ -1,6 +1,9 @@ #include #include +// TODO: check erros and fail safely and +// see connection with the lexer + // Requirements #include "parts/symbol.h" #include "parts/grammar.h" @@ -74,11 +77,11 @@ enum symbol { size_t total_symbols = SYMBOLS_END; -int symbol_is_valid(symbol s) { return s < SYMBOLS_END; } +IMPLEMENT_FUNCPTR(int, symbol_is_valid, (symbol s), { return s < SYMBOLS_END; }) // implement 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), @@ -89,7 +92,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); // implement table.h struct action **table = (struct action *([])){ -- cgit v1.2.3