aboutsummaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
Diffstat (limited to 'demos')
-rw-r--r--demos/instant-parser.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/demos/instant-parser.c b/demos/instant-parser.c
index 06990f6..8af2318 100644
--- a/demos/instant-parser.c
+++ b/demos/instant-parser.c
@@ -43,6 +43,21 @@ static symbol *tok = toklist;
symbol toklist_eat() { return *(tok++); } // unsafe
symbol toklist_peek() { return *tok; } // unsafe
+int __prod0_action(int *stack_head) { return *(stack_head-4); }
+int __prod1_action(int *stack_head) { return *(stack_head-7) + *(stack_head-1); }
+int __prod2_action(int *stack_head) { return *(stack_head-7) + *(stack_head-1); }
+int __prod3_action(int *stack_head) { return *(stack_head - 1); }
+int __prod4_action(int *stack_head) { return *(stack_head - 4); }
+int __prod5_action(int *stack_head) { return *(stack_head - 1); }
+int __prod6_action(int *stack_head) { return 0; }
+int __prod7_action(int *stack_head) { return 1; }
+
+typedef int (*semantic_action_fn)(int *stack_head);
+semantic_action_fn *semantic_actions = (semantic_action_fn[]){
+ __prod0_action, __prod1_action, __prod2_action, __prod3_action,
+ __prod4_action, __prod5_action, __prod6_action, __prod7_action,
+};
+
#include "slr-table.c"
#include "util-tables.c"
#include "lr-parser.c"
@@ -50,13 +65,13 @@ symbol toklist_peek() { return *tok; } // unsafe
int main(void)
{
util_tables_fill();
- table_fill();
+ int r = 0;
+ if((r = table_fill())) goto cleanup;
table_print();
+ printf("RESULT: %d\n", lr_parser());
- int r = 0;
- r = lr_parser();
-
+cleanup:
table_free();
util_tables_free();