diff options
| author | kartofen <kartofen.mail.0@protonmail.com> | 2025-07-07 00:45:12 +0300 |
|---|---|---|
| committer | kartofen <kartofen.mail.0@protonmail.com> | 2025-07-07 00:45:12 +0300 |
| commit | 364d124b961f2334fd9d2d380163f17c6575c26e (patch) | |
| tree | 63904b369bb97849470e7a8d6a776b43c6eb4efc /demos | |
| parent | 653d4b248e18f71eebea57cb39895fdb68f5c885 (diff) | |
add readme
Diffstat (limited to 'demos')
| -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(); |
