From 102e54ba7d84e0d7fca8fbb414a9a6eaa996f79b Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 16 May 2017 10:05:16 +0200 Subject: [PATCH] debug in progress --- src/lib/automate/automate.c | 15 ++++++++- src/lib/automate/automate.h | 4 +-- src/linter.c | 62 ++++++++++++------------------------- 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/src/lib/automate/automate.c b/src/lib/automate/automate.c index 181a753..503f4b8 100644 --- a/src/lib/automate/automate.c +++ b/src/lib/automate/automate.c @@ -30,7 +30,17 @@ unsigned int browse(struct Automate* pAutomate, const char* pString, const char char* dotmem = malloc( sizeof(char) ); pAutomate->path = realloc(pAutomate->path, 1 ); - /* [1] For each char + /* [1] merge automates + =========================================================*/ + while( pAutomate->aedges > 0 ) + mergeAutomate(pAutomate, pAutomate->aedges-1); + + + + + + + /* [2] For each char =========================================================*/ c = 0; len = strlen(pString); @@ -385,6 +395,9 @@ void mergeAutomate(struct Automate* pMaster, const char pSlaveIndex){ struct Automate* pSlave = &pMaster->aedge[pSlaveIndex]; + while( pSlave->aedges > 0 ) + mergeAutomate(pSlave, pSlave->aedges-1); + /* [1] Merge @pSlave edges into @pMaster edges =========================================================*/ diff --git a/src/lib/automate/automate.h b/src/lib/automate/automate.h index 2d57d58..e112dac 100644 --- a/src/lib/automate/automate.h +++ b/src/lib/automate/automate.h @@ -24,7 +24,7 @@ } AutomateType; - #define ADB 0x00 + #define ADB 0x01 struct AutomateDot{ char n; // number of edges @@ -48,7 +48,7 @@ char dCurrent; // current dot index char dFinal; // final dot index - char steps; // number of steps + unsigned int steps; // number of steps char* name; // automate name char* path; // automate path diff --git a/src/linter.c b/src/linter.c index fb42380..df74cd8 100644 --- a/src/linter.c +++ b/src/linter.c @@ -48,44 +48,26 @@ int main(int argc, char* argv[]){ linkDots(&number, 2, 4, STRING_T, 0); // q2 --s0--> q4 linkDots(&number, 3, 4, AUTOMATE_T, 0); // q4 --a0--> q4 - mergeAutomate(&number, 0); - - struct Automate alphanum = createAutomate("alphanum"); - addDot(&alphanum); // q0 - addDot(&alphanum); // q1 - addRangeTransition(&alphanum, "az\0"); // r0 - addRangeTransition(&alphanum, "AZ\0"); // r1 - addRangeTransition(&alphanum, "09\0"); // r2 - addListTransition(&alphanum, "-_\0"); // l0 - linkDots(&alphanum, 0, 1, LIST_T, 0); // q0 --l0--> q1 - linkDots(&alphanum, 0, 1, RANGE_T, 0); // q0 --r0--> q1 - linkDots(&alphanum, 0, 1, RANGE_T, 1); // q0 --r1--> q1 - linkDots(&alphanum, 0, 1, RANGE_T, 2); // q0 --r2--> q1 - - - struct Automate escapable = createAutomate("escapable"); - addDot(&escapable); // q0 - addDot(&escapable); // q1 - addListTransition(&escapable, "\"\\/bfnrt\0"); // r0 - linkDots(&escapable, 0, 1, RANGE_T, 0); // q0 --r0--> q1 + // struct Automate alphanum = createAutomate("alphanum"); + // addDot(&alphanum); // q0 + // addDot(&alphanum); // q1 struct Automate string = createAutomate("string"); addDot(&string); // q0 addDot(&string); // q1 addDot(&string); // q2 - addDot(&string); // q3 addStringTransition(&string, "\"\0"); // s0 - addStringTransition(&string, "\\\0"); // s1 - addAutomateTransition(&string, &alphanum); // a0 - addAutomateTransition(&string, &escapable); // a1 - linkDots(&string, 0, 1, STRING_T, 0); // q0 --s0--> q1 - linkDots(&string, 1, 1, AUTOMATE_T, 0); // q1 --a0--> q1 - linkDots(&string, 1, 2, STRING_T, 1); // q1 --s1--> q2 - linkDots(&string, 2, 1, AUTOMATE_T, 1); // q2 --a1--> q1 - linkDots(&string, 1, 3, STRING_T, 0); // q1 --s0--> q3 - mergeAutomate(&string, 1); - mergeAutomate(&string, 0); + addRangeTransition(&string, "az\0"); // r0 + addRangeTransition(&string, "AZ\0"); // r1 + addRangeTransition(&string, "09\0"); // r2 + addListTransition(&string, "-_\0"); // l0 + linkDots(&string, 0, 1, STRING_T, 0); // q0 --s0--> q1 + linkDots(&string, 1, 1, LIST_T, 0); // q0 --l0--> q1 + linkDots(&string, 1, 1, RANGE_T, 0); // q0 --r0--> q1 + linkDots(&string, 1, 1, RANGE_T, 1); // q0 --r1--> q1 + linkDots(&string, 1, 1, RANGE_T, 2); // q0 --r2--> q1 + linkDots(&string, 1, 2, STRING_T, 0); // q1 --s0--> q2 struct Automate value = createAutomate("value"); @@ -101,8 +83,6 @@ int main(int argc, char* argv[]){ linkDots(&value, 0, 1, STRING_T, 2); // q0 --s2--> q1 linkDots(&value, 0, 1, AUTOMATE_T, 0); // q0 --a0--> q1 linkDots(&value, 0, 1, AUTOMATE_T, 1); // q0 --a1--> q1 - mergeAutomate(&value, 1); - mergeAutomate(&value, 0); struct Automate array = createAutomate("array"); addDot(&array); // q0 @@ -111,35 +91,31 @@ int main(int argc, char* argv[]){ addDot(&array); // q3 addStringTransition(&array, "[\0"); // s0 addStringTransition(&array, "]\0"); // s1 - addStringTransition(&array, ",\0"); // s2 + addStringTransition(&array, ", \0"); // s2 addAutomateTransition(&array, &value); // a0 linkDots(&array, 0, 1, STRING_T, 0); // q0 --s0--> q1 linkDots(&array, 1, 2, AUTOMATE_T, 0); // q1 --a0--> q2 linkDots(&array, 2, 1, STRING_T, 2); // q2 --s2--> q1 linkDots(&array, 1, 3, STRING_T, 1); // q1 --s1--> q3 - mergeAutomate(&array, 0); - - // debug(array); char str[40] = {0}; - unsigned int browsed = 0; + strcpy(str, "[null, \"abc\", \"def\"]\0"); clock_t start, stop; - strcpy(str, "[\"abc\"]\0"); + unsigned int browsed = 0; start = clock(); browsed = browse(&array, str, 0); stop = clock(); + debug(array); + printf("browse '%s' : %d/%d\n", str, browsed, (int) strlen(str)); printf(" (*) final_state: %d/%d\n", array.dCurrent, array.dFinal); printf(" (*) in %d steps\n", array.steps); printf(" (*) in %.3lf seconds\n\n", (double)(stop-start)/CLOCKS_PER_SEC); for( c = 0 ; c < array.n ; c++ ){ - if( c > 0 ) printf(" -> "); - printf("q%d", array.path[c]); - } - printf(" -> q%d\n", array.dFinal); + printf("\n"); exit(0); /* Build RegExp */