diff options
author | JSDurand <mmemmew@gmail.com> | 2022-02-06 23:35:42 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2022-02-06 23:50:22 +0800 |
commit | aaa12504c6095b2cdfa213a3d4b269bbd5e7038a (patch) | |
tree | 9513833a65f0f2687b238fe6d0415bd5877ed8ae /src/test | |
parent | 3d709982b66314b23b5957041580dd4918561a53 (diff) |
dfa: add the type of "ranged dfas"
Strictly speaking, they are not DFA's at all. They contain ranges
which can determine whether or not a character belongs to the
specified predicate terminal.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/check_dfa.c | 10 | ||||
-rw-r--r-- | src/test/check_pred.c | 15 |
2 files changed, 19 insertions, 6 deletions
diff --git a/src/test/check_dfa.c b/src/test/check_dfa.c index a728fb8..426eee4 100644 --- a/src/test/check_dfa.c +++ b/src/test/check_dfa.c @@ -104,5 +104,15 @@ main(int UNUSED argc, char ** UNUSED argv) * printf("the result = %d\n", result); */ if (dfap) destroy_dfa(dfap); + + dfap = dfa_from_ranges(3, (NUM []) { 1, 10, 'a', 'z', 'A', 'Z' }); + + if (dfap) { + printf("Successfully created a DFA from an array of ranges\n"); + print_dfa(dfap); + } + + if (dfap) destroy_dfa(dfap); + return 0; } diff --git a/src/test/check_pred.c b/src/test/check_pred.c index 14081d5..8a3e613 100644 --- a/src/test/check_pred.c +++ b/src/test/check_pred.c @@ -1,3 +1,4 @@ +#include "limits.h" #include "time.h" #include "../cnp.h" @@ -88,7 +89,7 @@ main(int UNUSED argc, char ** UNUSED argv) *(user_name+4) = 'i'; *(user_name+5) = 0; - user_name_s = new_utf8(user_name, 5); + user_name_s = (str *) new_utf8(user_name, 5); SAFE_MALLOC(char, raw_name, 8, return 1;); @@ -101,7 +102,7 @@ main(int UNUSED argc, char ** UNUSED argv) *(raw_name+6) = 'Z'; *(raw_name+7) = 0; - raw_name_s = new_utf8(raw_name, 6); + raw_name_s = (str *) new_utf8(raw_name, 6); SAFE_MALLOC(NUM, pred_bytes, 52, return 1;); @@ -111,9 +112,11 @@ main(int UNUSED argc, char ** UNUSED argv) for (int i = 0; i < 26; i++) *(pred_bytes+pred_bytes_len++) = 'A' + i; - if (add_to_list(preds, new_ptd(user_name_s, raw_name_s, - dfa_from_bytes_neg - (pred_bytes_len, pred_bytes)))) { + if (add_to_list(preds, + new_ptd(user_name_s, raw_name_s, + dfa_from_ranges_both + (2, (NUM[]) { 'a', 'z', 'A', 'Z' }, + 2, (NUM[]) { 'b', 'w', 'B', 'W' })))) { fleprintf0("Fail to add a predicate\n"); return 1; } @@ -126,7 +129,7 @@ main(int UNUSED argc, char ** UNUSED argv) print_grammar(g); - utf8 *string = new_utf8("++--__,.(){}><|", 15); + utf8 *string = new_utf8("aaaxxxxaaaaaaaa", 15); printf("\nPrinting the input...\n%s\n", get_data((str *) string)); |