From a6cb97af1a2a5491f54fcfa7064641dc0aafd898 Mon Sep 17 00:00:00 2001 From: kartofen Date: Mon, 7 Jul 2025 00:45:12 +0300 Subject: add readme --- demos/instant-parser.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'demos/instant-parser.c') 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(); -- cgit v1.2.3