debug in progress
This commit is contained in:
parent
e2c1929360
commit
102e54ba7d
|
@ -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
|
||||
=========================================================*/
|
||||
|
|
|
@ -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
|
||||
|
|
62
src/linter.c
62
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 */
|
||||
|
|
Loading…
Reference in New Issue