aboutsummaryrefslogtreecommitdiff
path: root/demos/sample-files/lalr-defs.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2025-07-06 21:18:28 +0300
committerkartofen <mladenovnasko0@gmail.com>2025-07-06 21:18:28 +0300
commitb4261ac4a79651bd8fd1bd03d38bbf49ee89b615 (patch)
tree3b86e7afe5d16899d691122c3271944dc41d324e /demos/sample-files/lalr-defs.c
parentb65dd53885eabb8f39a3115039563edc08efb2b4 (diff)
modular table building
Diffstat (limited to 'demos/sample-files/lalr-defs.c')
-rw-r--r--demos/sample-files/lalr-defs.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/demos/sample-files/lalr-defs.c b/demos/sample-files/lalr-defs.c
new file mode 100644
index 0000000..6147661
--- /dev/null
+++ b/demos/sample-files/lalr-defs.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <stddef.h>
+
+#include "parts/symbol.h"
+enum symbol {
+ ID, EQUAL, STAR,
+ END_INPUT,
+ EP, E, L, R,
+ SYMBOLS_END,
+};
+
+size_t total_symbols = 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)}
+static struct production _grammar[] = {
+ PROD(EP, ->, E, END_INPUT),
+ PROD(E, -->, L, EQUAL, R),
+ PROD(E, -->, R),
+ PROD(L, -->, STAR, R),
+ PROD(L, -->, ID),
+ PROD(R, -->, L),
+};
+
+struct production *grammar = _grammar;
+size_t total_productions = sizeof(_grammar)/sizeof(*_grammar);
+
+// #include "???.h"
+char **semantic_action_str = (char *([])){
+ "", "", "", "", "", "",
+};