aboutsummaryrefslogtreecommitdiff
path: root/fusion.c
diff options
context:
space:
mode:
Diffstat (limited to 'fusion.c')
-rw-r--r--fusion.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/fusion.c b/fusion.c
index 1e4579f..3dc7dba 100644
--- a/fusion.c
+++ b/fusion.c
@@ -1,10 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
-#include "util-tables.c"
-#include "slr-table.c"
-#include "lr-parser.c"
-
+#include "parts/symbol.h"
enum symbol {
PLUS = 0,
MINUS,
@@ -23,6 +20,7 @@ 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; }
+#include "parts/grammar.h"
#define PROD(LHS, _, ...) {LHS, (symbol[]){__VA_ARGS__}, sizeof((symbol[]){__VA_ARGS__})/sizeof(symbol)}
struct production grammar[] = {
PROD(EP, ->, E, END_INPUT),
@@ -37,22 +35,25 @@ struct production grammar[] = {
const size_t total_productions = sizeof(grammar)/sizeof(*grammar);
-symbol toklist[] = {N0, PLUS, N1, MINUS, N0, N0, END_INPUT};
-symbol *tok = toklist;
+#include "parts/toklist.h"
+static symbol toklist[] = {N0, PLUS, N1, MINUS, N0, END_INPUT};
+static symbol *tok = toklist;
-symbol toklist_eat() { return *(tok++); }
-symbol toklist_peek() { return *tok; }
+symbol toklist_eat() { return *(tok++); } // unsafe
+symbol toklist_peek() { return *tok; } // unsafe
+
+#include "slr-table.c"
+#include "util-tables.c"
+#include "lr-parser.c"
int main(void)
{
util_tables_fill();
- table_allocate();
-
- itemset_handle((struct item[]){{0, 0}}, 1);
+ table_fill();
- lr_parser() && (exit(1), 1);
+ int r = 0;
+ r = lr_parser();
- seen_sets_free();
table_free();
util_tables_free();