From 1c8cbfd09ff9dd02f6d8d938c45e3f29a35f6f32 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 5 Feb 2022 23:23:03 +0800 Subject: predicates start working now Now we have a working implementation of predicates. It now only remains to write the parser of grammars. Of course we shall generate this parser by this parser generator itself, because why not. ;-P --- src/dfa.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/dfa.c') diff --git a/src/dfa.c b/src/dfa.c index fb67047..9da201d 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -623,11 +623,14 @@ run_dfa(const dfa * const restrict table, const NUM code) break; } - char *s = MYALLOC(char, 5); + /* negative codes have special purposes */ + if (code < 0) return 0; + + char s[5]; str *strp = new_str(s, 5); if (encode(code, strp)) { - destroy_str(strp, 1); + destroy_str(strp, 0); fleprintf0("Fail to encode\n"); return 0; } @@ -636,33 +639,33 @@ run_dfa(const dfa * const restrict table, const NUM code) for (NUM i = 0; i < str_length(strp); i++) { unsigned char c = (unsigned char) *(s+i); + int lookup_value = 0; for (int j = 0, len = 0; len <= c;) { + len += *(*(table->data.table.table+current_row)+(j<<1)+1); lookup_value = *(*(table->data.table.table+current_row) +(j++<<1)); } - /* fleprintf("lookup_value = %d\n", lookup_value); */ - if (lookup_value > 0) { current_row = lookup_value; } else { switch (lookup_value) { case DFA_STATE_REJECT: - destroy_str(strp, 1); + destroy_str(strp, 0); return 0; break; case DFA_STATE_UNKNOWN: switch (table->type) { case DFA_TYPE_BOTH: case DFA_TYPE_POSITIVE: - destroy_str(strp, 1); + destroy_str(strp, 0); return 0; break; case DFA_TYPE_NEGATIVE: - destroy_str(strp, 1); + destroy_str(strp, 0); return 1; break; default: @@ -670,26 +673,26 @@ run_dfa(const dfa * const restrict table, const NUM code) the table is of the special type. But I am apparently paranoia. */ fleprintf0("Special table in the wrong place\n"); - destroy_str(strp, 1); + destroy_str(strp, 0); return 0; break; } break; case DFA_STATE_ACCEPT: - destroy_str(strp, 1); + destroy_str(strp, 0); return 1; break; default: fleprintf("Unknown state number for char %d: %d\n", c, lookup_value); - destroy_str(strp, 1); + destroy_str(strp, 0); return 0; break; } } } - destroy_str(strp, 1); + destroy_str(strp, 0); return 0; } -- cgit v1.2.3-18-g5258