From 3d709982b66314b23b5957041580dd4918561a53 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sun, 6 Feb 2022 18:11:03 +0800 Subject: Add a script to build for debugging purposes I think this is a better practice than the previously used hard-coded configure option. --- src/cnp.c | 72 +++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 20 deletions(-) (limited to 'src/cnp.c') diff --git a/src/cnp.c b/src/cnp.c index ce5a527..3c76f52 100644 --- a/src/cnp.c +++ b/src/cnp.c @@ -654,11 +654,13 @@ cnp_parse(Grammar *g, str *string) while ((current_prodecor = pop_procr(env_r(env), env_u(env), ¤t_grade))) { - /* fleprintf("{ %ld, %ld, %ld, %ld, %ld }\n", - * current_prodecor->x, current_prodecor->y, - * current_prodecor->z, current_prodecor->u, - * current_grade); - * print_procr(env_r(env)); */ +#ifdef DEBUG + fleprintf("{ %ld, %ld, %ld, %ld, %ld }\n", + current_prodecor->x, current_prodecor->y, + current_prodecor->z, current_prodecor->u, + current_grade); + print_procr(env_r(env)); +#endif /* different cases */ @@ -683,8 +685,9 @@ cnp_parse(Grammar *g, str *string) goto continue_label; } - - /* fleprintf0("non empty rule\n"); */ +#ifdef DEBUG + fleprintf0("non empty rule\n"); +#endif /* if at the end of a rule, return if possible */ if (current_prodecor->z == list_length(right)) { @@ -696,28 +699,37 @@ cnp_parse(Grammar *g, str *string) goto continue_label; } - - /* fleprintf0("not at the end of the rule\n"); */ +#ifdef DEBUG + fleprintf0("not at the end of the rule\n"); +#endif /* if at the start of a rule, no need for test_select */ if (current_prodecor->z == 0) { - /* fleprintf0("at the start of the rule\n"); */ +#ifdef DEBUG + fleprintf0("at the start of the rule\n"); +#endif current_prodecor->z = 1; /* otherwise test select */ } else { - /* fleprintf0("start by test select\n"); */ +#ifdef DEBUG + fleprintf0("start by test select\n"); +#endif tnts = array_to_list(list_array(right)+current_prodecor->z, list_length(right)-current_prodecor->z); if (test_select(env, *(num_string+current_grade), current_prodecor->x, tnts)) { - /* fleprintf0("successful test\n"); */ +#ifdef DEBUG + fleprintf0("successful test\n"); +#endif free(tnts); tnts = NULL; ++(current_prodecor->z); } else { - /* fleprintf0("failed test\n"); */ +#ifdef DEBUG + fleprintf0("failed test\n"); +#endif free(tnts); tnts = NULL; goto continue_label; @@ -731,7 +743,9 @@ cnp_parse(Grammar *g, str *string) TERMINAL || ((TNT *) list_nth(right, current_prodecor->z-1))->type == PREDICATE) { - /* fleprintf0("found terminal\n"); */ +#ifdef DEBUG + fleprintf0("found terminal\n"); +#endif /* add to BSR set */ errorp = bsr_add(env_grammar(env), env_bsrp(env), @@ -747,7 +761,9 @@ cnp_parse(Grammar *g, str *string) if (current_prodecor->z == list_length(right)) { if (env_follow_p(env, current_prodecor->x, *(num_string+current_grade))) { - /* fleprintf0("we choose to return\n"); */ +#ifdef DEBUG + fleprintf0("we choose to return\n"); +#endif rtn(env, current_prodecor->x, current_prodecor->u, current_grade); /* fleprintf0("hi\n"); */ @@ -755,19 +771,25 @@ cnp_parse(Grammar *g, str *string) goto continue_label; } - /* fleprintf0("terminal not at the end\n"); */ +#ifdef DEBUG + fleprintf0("terminal not at the end\n"); +#endif /* else test select */ tnts = array_to_list(list_array(right)+current_prodecor->z, list_length(right)-current_prodecor->z); if (test_select(env, *(num_string+current_grade), current_prodecor->x, tnts)) { - /* fleprintf0("Successful test\n"); */ +#ifdef DEBUG + fleprintf0("Successful test\n"); +#endif free(tnts); tnts = NULL; (current_prodecor->z)++; } else { - /* fleprintf0("Failed test\n"); */ +#ifdef DEBUG + fleprintf0("Failed test\n"); +#endif /* printf("next thing is "); */ /* print_tnt(list_nth(right, current_prodecor->z)); */ /* printf("\n"); */ @@ -777,8 +799,18 @@ cnp_parse(Grammar *g, str *string) } } - /* fleprintf0("encountered non-terminal\n"); */ - +#ifdef DEBUG + fleprintf0("encountered non-terminal\n"); +#endif + + /* FIXME: Add the optimisation that when we know only one rule for + the encountered non-terminal is possible according to the + current input, either because the non-terminal is an "LL(1)" + non-terminal, or because the current input symbol says so, we + don't want to go through the process of adding a process + descriptor only to pop it up immediately. This can remove the + burden brought by the generalized techniques when they are not + needed. */ /* when a nonterminal is encountered, we call it */ cnp_call(env, (pair3) { .x = current_prodecor->x, -- cgit v1.2.3-18-g5258