diff options
author | kartofen <mladenovnasko0@gmail.com> | 2025-07-07 00:45:12 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2025-07-07 00:45:12 +0300 |
commit | a6cb97af1a2a5491f54fcfa7064641dc0aafd898 (patch) | |
tree | 63904b369bb97849470e7a8d6a776b43c6eb4efc /demos/instant-parser.c | |
parent | b4261ac4a79651bd8fd1bd03d38bbf49ee89b615 (diff) |
add readme
Diffstat (limited to 'demos/instant-parser.c')
-rw-r--r-- | demos/instant-parser.c | 23 |
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(); |