summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-02-06 18:11:03 +0800
committerJSDurand <mmemmew@gmail.com>2022-02-06 18:11:03 +0800
commit3d709982b66314b23b5957041580dd4918561a53 (patch)
tree1c23bbd7695499e1d74ce2c35ce27f6851a7f642 /src
parent1c8cbfd09ff9dd02f6d8d938c45e3f29a35f6f32 (diff)
Add a script to build for debugging purposes
I think this is a better practice than the previously used hard-coded configure option.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/cnp.c72
-rw-r--r--src/config.h3
-rw-r--r--src/test/check_cnp.c5
-rw-r--r--src/test/check_pred.c21
5 files changed, 67 insertions, 36 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index d097f1f..77c2dfe 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-AM_CFLAGS = -Wall -Wextra -Wno-missing-field-initializers
+AM_CFLAGS = -Wall -Wextra -Wno-missing-field-initializers -O3
noinst_LIBRARIES = libeps.a
libeps_a_SOURCES = grammar.c list.c util.c reader.c str.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), &current_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,
diff --git a/src/config.h b/src/config.h
index 82712aa..64d2a3d 100644
--- a/src/config.h
+++ b/src/config.h
@@ -1,9 +1,6 @@
/* src/config.h. Generated from config.h.in by configure. */
/* src/config.h.in. Generated from configure.ac by autoheader. */
-/* Define if one wants to debug the program. */
-/* #undef DEBUG */
-
/* Name of package */
#define PACKAGE "eps"
diff --git a/src/test/check_cnp.c b/src/test/check_cnp.c
index f01a68c..5a9e720 100644
--- a/src/test/check_cnp.c
+++ b/src/test/check_cnp.c
@@ -54,7 +54,7 @@ print_label6(pair6 label)
add_to_list(rules, rule); \
} while (0)
-#define GRAMMAR 4
+#define GRAMMAR 2
int
main(int UNUSED argc, char ** UNUSED argv)
@@ -183,7 +183,8 @@ main(int UNUSED argc, char ** UNUSED argv)
string = new_utf8("aab", 3);
break;
case 2:
- string = new_utf8("[[[[[[[[[[[[[[[[[[[[[[[++[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]--]]]]]]]]]]]]]]]]]]]]]]]", 204);
+ /* taken from Wikipedia: <https://en.wikipedia.org/wiki/Brainfuck> */
+ string = new_utf8("++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.", 106);
break;
case 3:
string = new_utf8("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 100);
diff --git a/src/test/check_pred.c b/src/test/check_pred.c
index 2767c45..14081d5 100644
--- a/src/test/check_pred.c
+++ b/src/test/check_pred.c
@@ -90,15 +90,16 @@ main(int UNUSED argc, char ** UNUSED argv)
user_name_s = new_utf8(user_name, 5);
- SAFE_MALLOC(char, raw_name, 7, return 1;);
+ SAFE_MALLOC(char, raw_name, 8, return 1;);
- *(raw_name+0) = 'a';
- *(raw_name+1) = '-';
- *(raw_name+2) = 'z';
- *(raw_name+3) = 'A';
- *(raw_name+4) = '-';
- *(raw_name+5) = 'Z';
- *(raw_name+6) = 0;
+ *(raw_name+0) = '^';
+ *(raw_name+1) = 'a';
+ *(raw_name+2) = '-';
+ *(raw_name+3) = 'z';
+ *(raw_name+4) = 'A';
+ *(raw_name+5) = '-';
+ *(raw_name+6) = 'Z';
+ *(raw_name+7) = 0;
raw_name_s = new_utf8(raw_name, 6);
@@ -111,7 +112,7 @@ main(int UNUSED argc, char ** UNUSED argv)
*(pred_bytes+pred_bytes_len++) = 'A' + i;
if (add_to_list(preds, new_ptd(user_name_s, raw_name_s,
- dfa_from_bytes
+ dfa_from_bytes_neg
(pred_bytes_len, pred_bytes)))) {
fleprintf0("Fail to add a predicate\n");
return 1;
@@ -125,7 +126,7 @@ main(int UNUSED argc, char ** UNUSED argv)
print_grammar(g);
- utf8 *string = new_utf8("awdfsdjbfsjdhxy", 15);
+ utf8 *string = new_utf8("++--__,.(){}><|", 15);
printf("\nPrinting the input...\n%s\n", get_data((str *) string));