From 5426d9e2a6b820e34809d639838b26643df9ab17 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Tue, 8 Feb 2022 00:29:10 +0800 Subject: fix errors There are multiple subtle errors in the previous version, both in the codes and in the description of the BNF format. This version should fix some problems now. This version can successfully parse the grammar of its own grammar format, which is quite nice. See test/check_reader.c for parsing this format. --- src/bsr.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'src/bsr.c') diff --git a/src/bsr.c b/src/bsr.c index 4b7953a..2736a1b 100644 --- a/src/bsr.c +++ b/src/bsr.c @@ -242,8 +242,60 @@ print_bsr_f(pair5 label) print_name(list_nth(grammar_names(bsr_print_grammar), label.x)); printf(" := "); + /* List *string = rg_nth(grammar_rule(bsr_print_grammar, label.x), + * label.u); + * + * char s[5]; + * str *strp = (str *) new_utf8(s, 5); + * + * for (NUM i = 0; i < list_length(string); i++) { + * TNT *tntp = (TNT *)list_nth(string, i); + * PTD *ptdp = NULL; + * switch (tntp->type) { + * case TERMINAL: + * printf("'"); + * if (encode + * (tntp->data.t, strp)) { + * destroy_str(strp, 0); + * fleprintf0("Fail to encode\n"); + * return; + * } + * printf("%s'", s); + * str_set_length(strp, 5); + * break; + * case NONTERMINAL: + * for (int k = 0; + * (UNUM) k < + * ((cpa *) list_nth(grammar_names(bsr_print_grammar), + * tntp->data.nt))->size; + * k++) { + * if (encode + * (*(((cpa *)list_nth + * (grammar_names(bsr_print_grammar), + * tntp->data.nt))->array+k), + * strp)) { + * destroy_str(strp, 0); + * fleprintf0("Fail to encode!\n"); + * return; + * } + * printf("%s", s); + * str_set_length(strp, 5); + * } + * break; + * default: + * ptdp = (PTD *) list_nth + * (grammar_preds(bsr_print_grammar), tntp->data.pt); + * printf("[%s]", get_data(ptd_user_name(ptdp))); + * break; + * } + * if (i+1