|
@ -38,7 +38,7 @@ int endExploration(Exploration *exploration) |
|
|
return 1; |
|
|
return 1; |
|
|
} else |
|
|
} else |
|
|
{ |
|
|
{ |
|
|
return 0; |
|
|
|
|
|
|
|
|
return -1; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -101,50 +101,46 @@ int execute(Node *node, Exploration *in) |
|
|
{ |
|
|
{ |
|
|
switch (node->type) { |
|
|
switch (node->type) { |
|
|
case STRING: { |
|
|
case STRING: { |
|
|
|
|
|
int pos= in->position; |
|
|
for (int i=0; i < strlen(node->stringValue);i++) |
|
|
for (int i=0; i < strlen(node->stringValue);i++) |
|
|
{ |
|
|
{ |
|
|
if (advance(in) != node->stringValue[i]) |
|
|
if (advance(in) != node->stringValue[i]) |
|
|
{ |
|
|
{ |
|
|
|
|
|
setPosition(in, pos); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (endExploration(in)==1) |
|
|
|
|
|
{ |
|
|
|
|
|
return 1; |
|
|
|
|
|
} else |
|
|
|
|
|
{ |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return endExploration(in); |
|
|
} |
|
|
} |
|
|
case AND: { |
|
|
case AND: { |
|
|
|
|
|
int pos= in->position; |
|
|
if (execute(node->children[0], in) == 0) //si il y a eu une erreur |
|
|
if (execute(node->children[0], in) == 0) //si il y a eu une erreur |
|
|
{ |
|
|
{ |
|
|
|
|
|
setPosition(in, pos); |
|
|
return 0; |
|
|
return 0; |
|
|
} else //si ça s'est bien passé |
|
|
} else //si ça s'est bien passé |
|
|
{ |
|
|
{ |
|
|
return execute(node->children[1], in); |
|
|
|
|
|
|
|
|
int result= execute(node->children[1], in); |
|
|
|
|
|
if (result == 0) { |
|
|
|
|
|
setPosition(in, pos); |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
case STAR: { |
|
|
case STAR: { |
|
|
if(execute(node->children[0], in) == 1){ |
|
|
|
|
|
execute(node->children[0], in); |
|
|
|
|
|
} |
|
|
|
|
|
else return 1; |
|
|
|
|
|
|
|
|
int pos= in->position; |
|
|
|
|
|
int result; |
|
|
|
|
|
while ((result= execute(node->children[0], in)) == -1){ |
|
|
|
|
|
pos= in->position;; |
|
|
|
|
|
} |
|
|
|
|
|
if (result == 0) { |
|
|
|
|
|
setPosition(in, pos); |
|
|
|
|
|
} |
|
|
|
|
|
return endExploration(in); |
|
|
} |
|
|
} |
|
|
case PLUS: { |
|
|
case PLUS: { |
|
|
if(execute(node->children[0],in)==0){ |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
else{ |
|
|
|
|
|
while(execute(node->children[0], in) == 1){ |
|
|
|
|
|
|
|
|
|
|
|
execute(node->children[0], in); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Node *newNode= mkAnd(node->children[0], mkStar(node->children[0])); |
|
|
|
|
|
return execute(newNode,in); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
printf("this cannot happen\n"); |
|
|
printf("this cannot happen\n"); |
|
@ -158,7 +154,6 @@ int main(int argc, char **argv) |
|
|
|
|
|
|
|
|
/*Node *program= |
|
|
/*Node *program= |
|
|
mkString("aabbcc"); |
|
|
mkString("aabbcc"); |
|
|
|
|
|
|
|
|
Node *program= |
|
|
Node *program= |
|
|
mkAnd(mkString("aab"), |
|
|
mkAnd(mkString("aab"), |
|
|
mkString("bcc"));*/ |
|
|
mkString("bcc"));*/ |
|
@ -168,16 +163,11 @@ int main(int argc, char **argv) |
|
|
mkAnd(mkString("bb"), |
|
|
mkAnd(mkString("bb"), |
|
|
mkString("cc")));*/ |
|
|
mkString("cc")));*/ |
|
|
|
|
|
|
|
|
/* Node *program= |
|
|
|
|
|
mkAnd( mkString("aabbcc"), |
|
|
|
|
|
mkAnd(mkStar(mkString("c")), // "a"*"b"*"c"* |
|
|
|
|
|
mkAnd(mkStar(mkString("b")), |
|
|
|
|
|
mkStar(mkString("c"))))); |
|
|
|
|
|
*/ |
|
|
|
|
|
Node *program= |
|
|
|
|
|
|
|
|
Node *program= |
|
|
mkAnd(mkPlus(mkString("a")), // "a"*"b"*"c"* |
|
|
mkAnd(mkPlus(mkString("a")), // "a"*"b"*"c"* |
|
|
mkAnd(mkPlus(mkString("b")), |
|
|
|
|
|
mkPlus(mkString("c")))); |
|
|
|
|
|
|
|
|
mkAnd(mkStar(mkString("b")), |
|
|
|
|
|
mkStar(mkString("c")))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (execute(program, in)<=0) |
|
|
if (execute(program, in)<=0) |
|
|
{ |
|
|
{ |
|
@ -193,11 +183,9 @@ int main(int argc, char **argv) |
|
|
/*Input *in1= mkInput("hello"); |
|
|
/*Input *in1= mkInput("hello"); |
|
|
Input *in2= mkInput("world"); |
|
|
Input *in2= mkInput("world"); |
|
|
Input *in3= mkInput("hello world"); |
|
|
Input *in3= mkInput("hello world"); |
|
|
|
|
|
|
|
|
Node *program= |
|
|
Node *program= |
|
|
mkOr(mkString("hello"), // "hello" | "world" |
|
|
mkOr(mkString("hello"), // "hello" | "world" |
|
|
mkString("world")); |
|
|
mkString("world")); |
|
|
|
|
|
|
|
|
printf("%i\n", execute(program, in)); // 0 => no match, 1 => match*/ |
|
|
printf("%i\n", execute(program, in)); // 0 => no match, 1 => match*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|