|
@ -4,7 +4,7 @@ |
|
|
#include <string.h> |
|
|
#include <string.h> |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
; |
|
|
; |
|
|
enum op { String, Query, Star, Plus } ; |
|
|
|
|
|
|
|
|
enum op { String, Query, Star, Plus, Or, And } ; |
|
|
|
|
|
|
|
|
typedef union Node Node; |
|
|
typedef union Node Node; |
|
|
|
|
|
|
|
@ -12,6 +12,9 @@ struct String { enum op type; char *string; }; |
|
|
struct Query { enum op type; Node *children[1]; }; |
|
|
struct Query { enum op type; Node *children[1]; }; |
|
|
struct Star { enum op type; Node *children[1]; }; |
|
|
struct Star { enum op type; Node *children[1]; }; |
|
|
struct Plus { enum op type; Node *children[1]; }; |
|
|
struct Plus { enum op type; Node *children[1]; }; |
|
|
|
|
|
struct Or { enum op type; Node *children[2]; }; |
|
|
|
|
|
struct And { enum op type; Node *children[2]; }; |
|
|
|
|
|
struct Class { enum op type; char *stringValue; int len; }; |
|
|
|
|
|
|
|
|
union Node { |
|
|
union Node { |
|
|
enum op type; |
|
|
enum op type; |
|
@ -19,6 +22,9 @@ union Node { |
|
|
struct Query Query; |
|
|
struct Query Query; |
|
|
struct Star Star; |
|
|
struct Star Star; |
|
|
struct Plus Plus; |
|
|
struct Plus Plus; |
|
|
|
|
|
struct Or Or; |
|
|
|
|
|
struct And And; |
|
|
|
|
|
struct Class Class; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
Node *mkString(char *s) |
|
|
Node *mkString(char *s) |
|
@ -29,6 +35,8 @@ Node *mkString(char *s) |
|
|
return node; |
|
|
return node; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Node *mkQuery(Node *n) |
|
|
Node *mkQuery(Node *n) |
|
|
{ |
|
|
{ |
|
|
Node *node= calloc(1, sizeof(struct Query)); |
|
|
Node *node= calloc(1, sizeof(struct Query)); |
|
@ -37,6 +45,22 @@ Node *mkQuery(Node *n) |
|
|
return node; |
|
|
return node; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Node *mkOr(Node *node1, Node *node2) |
|
|
|
|
|
{ |
|
|
|
|
|
Node *node= calloc(1, sizeof(struct Or)); |
|
|
|
|
|
node->Or.children[0]= node1; |
|
|
|
|
|
node->Or.children[1]= node2; |
|
|
|
|
|
return node; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Node *mkAnd(Node *node1, Node *node2) |
|
|
|
|
|
{ |
|
|
|
|
|
Node *node= calloc(1, sizeof(struct And)); |
|
|
|
|
|
node->And.children[0]= node1; |
|
|
|
|
|
node->And.children[1]= node2; |
|
|
|
|
|
return node; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Node *mkStar(Node *n) |
|
|
Node *mkStar(Node *n) |
|
|
{ |
|
|
{ |
|
|
Node *node= calloc(1, sizeof(struct Star)); |
|
|
Node *node= calloc(1, sizeof(struct Star)); |
|
@ -45,6 +69,14 @@ Node *mkStar(Node *n) |
|
|
return node; |
|
|
return node; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Node *mkClass(char* str) |
|
|
|
|
|
{ |
|
|
|
|
|
Node *node= calloc(1, sizeof(struct Class)); |
|
|
|
|
|
node->Class.stringValue= str; |
|
|
|
|
|
node->Class.len=strlen(str); |
|
|
|
|
|
return node; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Node *mkPlus(Node *n) |
|
|
Node *mkPlus(Node *n) |
|
|
{ |
|
|
{ |
|
|
Node *node= calloc(1, sizeof(struct Plus)); |
|
|
Node *node= calloc(1, sizeof(struct Plus)); |
|
@ -71,6 +103,16 @@ void print(Node *node) |
|
|
print(node->Query.children[0]); |
|
|
print(node->Query.children[0]); |
|
|
printf("+"); |
|
|
printf("+"); |
|
|
return; |
|
|
return; |
|
|
|
|
|
case Or: |
|
|
|
|
|
print(node->Or.children[0]); |
|
|
|
|
|
print(node->Or.children[1]); |
|
|
|
|
|
printf("Or"); |
|
|
|
|
|
return; |
|
|
|
|
|
case And: |
|
|
|
|
|
print(node->And.children[0]); |
|
|
|
|
|
print(node->And.children[1]); |
|
|
|
|
|
printf("And"); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
abort(); |
|
|
abort(); |
|
|
} |
|
|
} |
|
@ -104,7 +146,10 @@ atom = string | class |
|
|
|
|
|
|
|
|
string = '"' < [^"]* > '"' { $$ = mkString(yytext) } - |
|
|
string = '"' < [^"]* > '"' { $$ = mkString(yytext) } - |
|
|
|
|
|
|
|
|
class = '[' ... ']' |
|
|
|
|
|
|
|
|
class = '[' <[]*> ']' { $$=mkClass(yytext) } - |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- = space* |
|
|
- = space* |
|
|
|
|
|
|
|
|