diff options
author | kartofen <mladenovnasko0@gmail.com> | 2025-07-03 19:11:36 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2025-07-03 19:11:36 +0300 |
commit | f2bef76fb369d4c9c3e53dca60eb78b75bb02d97 (patch) | |
tree | 94de181d7dae1d35310e1e9bfbf761b0fc536adf /parts/grammar.h | |
parent | 5064a7ebce75a26d0405c92040f1a40187fcc7e3 (diff) |
working more or less parser generator (no semantic action, so pretty much useless
Diffstat (limited to 'parts/grammar.h')
-rw-r--r-- | parts/grammar.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/parts/grammar.h b/parts/grammar.h index 328f88e..a02a99e 100644 --- a/parts/grammar.h +++ b/parts/grammar.h @@ -5,9 +5,9 @@ extern struct production { symbol LHS; symbol *RHS; size_t nRHS; -} grammar[]; +} *grammar; -extern const size_t total_productions; +extern size_t total_productions; void grammar_print() { @@ -18,5 +18,15 @@ void grammar_print() printf("\n"); } } +void grammar_print_cstyle() + +{ + for(size_t i = 0; i < total_productions; i++) { + printf("{%d, (symbol[]){", grammar[i].LHS); + for(size_t j = 0; j < grammar[i].nRHS; j++) + printf("%d, ", grammar[i].RHS[j]); + printf("}, %zu},\n", grammar[i].nRHS); + } +} #endif |