aboutsummaryrefslogtreecommitdiff
path: root/demos/instant-parser.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2025-07-03 19:11:36 +0300
committerkartofen <mladenovnasko0@gmail.com>2025-07-03 19:11:36 +0300
commitf2bef76fb369d4c9c3e53dca60eb78b75bb02d97 (patch)
tree94de181d7dae1d35310e1e9bfbf761b0fc536adf /demos/instant-parser.c
parent5064a7ebce75a26d0405c92040f1a40187fcc7e3 (diff)
working more or less parser generator (no semantic action, so pretty much useless
Diffstat (limited to 'demos/instant-parser.c')
-rw-r--r--demos/instant-parser.c13
1 files changed, 8 insertions, 5 deletions
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();