From f2bef76fb369d4c9c3e53dca60eb78b75bb02d97 Mon Sep 17 00:00:00 2001 From: kartofen Date: Thu, 3 Jul 2025 19:11:36 +0300 Subject: working more or less parser generator (no semantic action, so pretty much useless --- parts/grammar.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'parts/grammar.h') 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 -- cgit v1.2.3