diff options
author | JSDurand <mmemmew@gmail.com> | 2022-02-05 23:23:03 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2022-02-05 23:23:03 +0800 |
commit | 1c8cbfd09ff9dd02f6d8d938c45e3f29a35f6f32 (patch) | |
tree | e3d6bb3b5246bcfa38662615ad59663d5b0377d1 /src/dfa.c | |
parent | 510b10b96b546fcc6c6b6be85050305ddd192a41 (diff) |
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
Diffstat (limited to 'src/dfa.c')
-rw-r--r-- | src/dfa.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -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; } |