|
|
@ -7,6 +7,7 @@ typedef struct Exploration Exploration; |
|
|
|
|
|
|
|
|
|
|
|
enum opcode { |
|
|
|
<<<<<<< HEAD |
|
|
|
String, |
|
|
|
And, |
|
|
|
Or, |
|
|
@ -16,6 +17,17 @@ enum opcode { |
|
|
|
Question_mark, |
|
|
|
Exclamation_mark, |
|
|
|
Dot |
|
|
|
======= |
|
|
|
STRING, |
|
|
|
AND, |
|
|
|
OR, |
|
|
|
STAR, |
|
|
|
PLUS, |
|
|
|
CLASS, |
|
|
|
QUESTION_MARK, |
|
|
|
EXCLAMATION_MARK, |
|
|
|
DOT |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
}; |
|
|
|
struct Exploration |
|
|
|
{ |
|
|
@ -53,6 +65,17 @@ int currentChar(Exploration *exploration) |
|
|
|
{ |
|
|
|
return exploration->text[exploration->position]; |
|
|
|
} |
|
|
|
<<<<<<< HEAD |
|
|
|
======= |
|
|
|
|
|
|
|
char *currentText(Exploration *exploration) |
|
|
|
{ |
|
|
|
return exploration->text + exploration->position; |
|
|
|
} |
|
|
|
|
|
|
|
struct String { enum opcode type; char *stringValue; int len;}; |
|
|
|
struct Class { enum opcode type; char *stringValue; int len;}; |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
|
|
|
|
char *currentText(Exploration *exploration) |
|
|
|
{ |
|
|
@ -71,6 +94,7 @@ struct Dot { enum opcode type;}; |
|
|
|
union Node |
|
|
|
{ |
|
|
|
enum opcode type; |
|
|
|
<<<<<<< HEAD |
|
|
|
struct String String; |
|
|
|
struct Class Class; |
|
|
|
struct And And; |
|
|
@ -80,6 +104,13 @@ union Node |
|
|
|
struct Question_mark Question_mark; |
|
|
|
struct Exclamation_mark Exclamation_mark; |
|
|
|
struct Dot Dot; |
|
|
|
======= |
|
|
|
union { |
|
|
|
struct String STRING; |
|
|
|
struct Class CLASS; |
|
|
|
Node *children[2]; |
|
|
|
}; |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -94,9 +125,15 @@ Node *mkNode(size_t size,enum opcode type) |
|
|
|
|
|
|
|
Node *mkString(char *value) |
|
|
|
{ |
|
|
|
<<<<<<< HEAD |
|
|
|
Node *node= new(String); |
|
|
|
node->String.stringValue= value; |
|
|
|
node->String.len=strlen(value); |
|
|
|
======= |
|
|
|
Node *node= mkNode(STRING); |
|
|
|
node->STRING.stringValue= value; |
|
|
|
node->STRING.len=strlen(value); |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
@ -146,6 +183,7 @@ Node *mkQuestionMark(Node *child) |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
<<<<<<< HEAD |
|
|
|
Node *mkExclamationMark(Node *child) |
|
|
|
{ |
|
|
|
Node *node= new(Exclamation_mark); |
|
|
@ -161,6 +199,41 @@ Node *mkDot() |
|
|
|
if (node==0){ |
|
|
|
node=new(Dot); |
|
|
|
} |
|
|
|
======= |
|
|
|
Node *mkOr(Node *node1, Node *node2) |
|
|
|
{ |
|
|
|
Node *node= mkNode(OR); |
|
|
|
node->children[0]= node1; |
|
|
|
node->children[1]= node2; |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkClass(char* str) |
|
|
|
{ |
|
|
|
Node *node= mkNode(CLASS); |
|
|
|
node->STRING.stringValue= str; |
|
|
|
node->STRING.len=strlen(str); |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkQuestionMark(Node *child) |
|
|
|
{ |
|
|
|
Node *node= mkNode(QUESTION_MARK); |
|
|
|
node->children[0]= child; |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkExclamationMark(Node *child) |
|
|
|
{ |
|
|
|
Node *node= mkNode(EXCLAMATION_MARK); |
|
|
|
node->children[0]= child; |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkDot() |
|
|
|
{ |
|
|
|
Node *node= mkNode(DOT); |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
@ -178,12 +251,21 @@ const char* getTypeName(enum opcode type) |
|
|
|
{ |
|
|
|
switch (type) |
|
|
|
{ |
|
|
|
<<<<<<< HEAD |
|
|
|
case Star: return "Star"; |
|
|
|
case Exclamation_mark: return "NOT"; |
|
|
|
case Dot: return "Dot"; |
|
|
|
case Question_mark: return "QMARK"; |
|
|
|
case Plus : return "Plus"; |
|
|
|
case Class : return "Class"; |
|
|
|
======= |
|
|
|
case STAR: return "STAR"; |
|
|
|
case EXCLAMATION_MARK: return "NOT"; |
|
|
|
case DOT: return "DOT"; |
|
|
|
case QUESTION_MARK: return "QMARK"; |
|
|
|
case PLUS : return "PLUS"; |
|
|
|
case CLASS : return "CLASS"; |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
default : printf("unexpected use");return 0; |
|
|
|
abort(); |
|
|
|
} |
|
|
@ -197,6 +279,7 @@ void println(Node *node, int indent) |
|
|
|
} |
|
|
|
indent++; |
|
|
|
switch (node->type) { |
|
|
|
<<<<<<< HEAD |
|
|
|
case String: printf("%.*s", get(node, String, len), get(node, String, stringValue)); return; |
|
|
|
case And: { |
|
|
|
printf("AND\n"); |
|
|
@ -233,6 +316,31 @@ void println(Node *node, int indent) |
|
|
|
|
|
|
|
} |
|
|
|
printf("Unexpected type %i",node->type); |
|
|
|
======= |
|
|
|
case STRING: printf("%.*s", get(node, STRING, len), get(node, STRING, stringValue)); return; |
|
|
|
case AND: { |
|
|
|
printf("AND\n"); |
|
|
|
println(node->children[0],indent);printf("\n"); |
|
|
|
println(node->children[1],indent);printf("\n");return; |
|
|
|
} |
|
|
|
case OR: { |
|
|
|
printf("OR\n"); |
|
|
|
println(node->children[0],indent);printf("\n"); |
|
|
|
println(node->children[1],indent);printf("\n");return; |
|
|
|
} |
|
|
|
case DOT:{ |
|
|
|
printf("DOT\n");return; |
|
|
|
} |
|
|
|
case CLASS:{ |
|
|
|
printf("CLASS : Char in [%.*s]\n",get(node, CLASS, len),get(node, CLASS, stringValue));return; |
|
|
|
} |
|
|
|
default : { |
|
|
|
printf("%s\n",getTypeName(node->type)); |
|
|
|
println(node->children[0],indent);printf("\n");return; |
|
|
|
} |
|
|
|
} |
|
|
|
abort(); |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -240,6 +348,7 @@ void println(Node *node, int indent) |
|
|
|
int execute(Node *node, Exploration *in) |
|
|
|
{ |
|
|
|
switch (node->type) { |
|
|
|
<<<<<<< HEAD |
|
|
|
case String: { |
|
|
|
if (strncmp(currentText(in), get(node,String,stringValue), get(node,String,len))) { |
|
|
|
return 0; |
|
|
@ -281,11 +390,55 @@ int execute(Node *node, Exploration *in) |
|
|
|
return 0; |
|
|
|
} |
|
|
|
if (strchr(get(node,Class,stringValue), currentChar(in))) { |
|
|
|
======= |
|
|
|
case STRING: { |
|
|
|
if (strncmp(currentText(in), node->STRING.stringValue, node->STRING.len)) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
advance(in, node->STRING.len); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
case AND: { |
|
|
|
int pos= getPosition(in); |
|
|
|
if (!execute(node->children[0], in)) //si il y a eu une erreur |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
} //si ça s'est bien passé |
|
|
|
if (!execute(node->children[1], in)) { |
|
|
|
setPosition(in, pos); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
case OR: { |
|
|
|
if (execute(node->children[0], in)) { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
return execute(node->children[1], in); |
|
|
|
} |
|
|
|
case STAR: { |
|
|
|
while (execute(node->children[0], in)); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
case PLUS: { |
|
|
|
if (!execute(node->children[0], in)) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
while (execute(node->children[0], in)); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
case CLASS: { |
|
|
|
if (!currentChar(in)) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
if (strchr(node->STRING.stringValue, currentChar(in))) { |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
advance(in, 1); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
<<<<<<< HEAD |
|
|
|
case Question_mark: { |
|
|
|
execute(get(node,Question_mark,children[0]), in); |
|
|
|
return 1; |
|
|
@ -293,12 +446,25 @@ int execute(Node *node, Exploration *in) |
|
|
|
case Exclamation_mark: { |
|
|
|
int pos= getPosition(in); |
|
|
|
if (!execute(get(node,Exclamation_mark,children[0]), in)) { |
|
|
|
======= |
|
|
|
case QUESTION_MARK: { |
|
|
|
execute(node->children[0], in); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
case EXCLAMATION_MARK: { |
|
|
|
int pos= getPosition(in); |
|
|
|
if (!execute(node->children[0], in)) { |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
return 1; |
|
|
|
} |
|
|
|
setPosition(in, pos); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
<<<<<<< HEAD |
|
|
|
case Dot: { |
|
|
|
======= |
|
|
|
case DOT: { |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
if (atEnd(in)) { |
|
|
|
return 0; |
|
|
|
} |
|
|
@ -332,7 +498,11 @@ int main(int argc, char **argv) |
|
|
|
mkStar(mkString("c"))));*/ |
|
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD |
|
|
|
Node *program= mkOr(mkString("don't match pls"),mkStar(mkDot())); |
|
|
|
======= |
|
|
|
Node *program= mkStar(mkClass("abc")); |
|
|
|
>>>>>>> c0cb24584cb692cf472ced68d40700ba949cdeee |
|
|
|
Node *program3=mkAnd(mkAnd(mkPlus(mkString("hello world")),mkExclamationMark(mkString("how are u world !?"))),mkStar(mkClass("abcde"))); |
|
|
|
|
|
|
|
if (!execute(program, in) || !atEnd(in)) |
|
|
|