Explorar el Código

Update lexer.c

main
Vank143 hace 4 años
cometido por GitHub
padre
commit
6bed983708
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: 4AEE18F83AFDEB23
Se han modificado 1 ficheros con 26 adiciones y 38 borrados
  1. +26
    -38
      lexer.c

+ 26
- 38
lexer.c Ver fichero

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

Cargando…
Cancelar
Guardar