|
|
@ -3,22 +3,29 @@ |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <string.h> |
|
|
|
#define YYRULECOUNT 9 |
|
|
|
#define YYRULECOUNT 11 |
|
|
|
#line 1 "parse.leg" |
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
#include <string.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include "inputBuffer.c" |
|
|
|
; |
|
|
|
enum op { String, Query, Star, Plus } ; |
|
|
|
enum op { String, Query, Star, Plus, Or, And, Class, Dot, Exc } ; |
|
|
|
|
|
|
|
|
|
|
|
typedef union Node Node; |
|
|
|
|
|
|
|
struct String { enum op type; char *string; }; |
|
|
|
struct String { enum op type; char *string; int len; }; |
|
|
|
struct Query { enum op type; Node *children[1]; }; |
|
|
|
struct Star { 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; }; |
|
|
|
struct Dot { enum op type;}; |
|
|
|
struct Exc { enum op type; Node *children[1]; }; |
|
|
|
|
|
|
|
union Node { |
|
|
|
enum op type; |
|
|
@ -26,58 +33,127 @@ union Node { |
|
|
|
struct Query Query; |
|
|
|
struct Star Star; |
|
|
|
struct Plus Plus; |
|
|
|
struct Or Or; |
|
|
|
struct And And; |
|
|
|
struct Class Class; |
|
|
|
struct Dot Dot; |
|
|
|
struct Exc Exc; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
#define new(type) mkNode(sizeof(struct type),type) |
|
|
|
|
|
|
|
Node *mkNode(size_t size,enum op type) |
|
|
|
{ |
|
|
|
Node *node= calloc(1, size); |
|
|
|
node->type= type; |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkString(char *s) |
|
|
|
{ |
|
|
|
Node *node= calloc(1, sizeof(struct String)); |
|
|
|
node->type= String; |
|
|
|
Node *node= new(String); |
|
|
|
node->String.string= strdup(s); |
|
|
|
node->String.len=strlen(s); |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkQuery(Node *n) |
|
|
|
{ |
|
|
|
Node *node= calloc(1, sizeof(struct Query)); |
|
|
|
node->type= Query; |
|
|
|
Node *node= new(Query); |
|
|
|
node->Query.children[0]= n; |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkOr(Node *node1, Node *node2) |
|
|
|
{ |
|
|
|
Node *node= new(Or); |
|
|
|
node->Or.children[0]= node1; |
|
|
|
node->Or.children[1]= node2; |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkAnd(Node *node1, Node *node2) |
|
|
|
{ |
|
|
|
Node *node= new(And); |
|
|
|
node->And.children[0]= node1; |
|
|
|
node->And.children[1]= node2; |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkStar(Node *n) |
|
|
|
{ |
|
|
|
Node *node= calloc(1, sizeof(struct Star)); |
|
|
|
node->type= Star; |
|
|
|
Node *node= new(Star); |
|
|
|
node->Star.children[0]= n; |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkClass(char* str) |
|
|
|
{ |
|
|
|
Node *node= new(Class); |
|
|
|
node->Class.stringValue= str; |
|
|
|
node->Class.len=strlen(str); |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkPlus(Node *n) |
|
|
|
{ |
|
|
|
Node *node= calloc(1, sizeof(struct Plus)); |
|
|
|
node->type= Plus; |
|
|
|
Node *node= new(Plus); |
|
|
|
node->Plus.children[0]= n; |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkDot() |
|
|
|
{ |
|
|
|
Node *node= new(Dot); |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
Node *mkExc(Node *n) |
|
|
|
{ |
|
|
|
Node *node= new(Exc); |
|
|
|
node->Exc.children[0]= n; |
|
|
|
return node; |
|
|
|
} |
|
|
|
|
|
|
|
void print(Node *node) |
|
|
|
{ |
|
|
|
switch (node->type) { |
|
|
|
case String: |
|
|
|
printf("\"%s\"", node->String.string); |
|
|
|
return; |
|
|
|
printf("\"%s\"", node->String.string); |
|
|
|
return; |
|
|
|
case Query: |
|
|
|
print(node->Query.children[0]); |
|
|
|
printf("?"); |
|
|
|
return; |
|
|
|
print(node->Query.children[0]); |
|
|
|
printf("?"); |
|
|
|
return; |
|
|
|
case Star: |
|
|
|
print(node->Query.children[0]); |
|
|
|
printf("*"); |
|
|
|
return; |
|
|
|
print(node->Query.children[0]); |
|
|
|
printf("*"); |
|
|
|
return; |
|
|
|
case Plus: |
|
|
|
print(node->Query.children[0]); |
|
|
|
printf("+"); |
|
|
|
return; |
|
|
|
print(node->Query.children[0]); |
|
|
|
return; |
|
|
|
case Or: |
|
|
|
print(node->Or.children[0]); |
|
|
|
printf("Or"); |
|
|
|
print(node->Or.children[1]); |
|
|
|
return; |
|
|
|
case And: |
|
|
|
print(node->And.children[0]); |
|
|
|
printf("And"); |
|
|
|
print(node->And.children[1]); |
|
|
|
return; |
|
|
|
case Class: |
|
|
|
printf("Class"); |
|
|
|
printf("\"%s\"", node->Class.stringValue); |
|
|
|
return; |
|
|
|
case Dot: |
|
|
|
printf("Dot"); |
|
|
|
return; |
|
|
|
case Exc: |
|
|
|
printf("!"); |
|
|
|
print(node->Exc.children[0]); |
|
|
|
return; |
|
|
|
} |
|
|
|
abort(); |
|
|
|
} |
|
|
@ -87,9 +163,19 @@ void println(Node *node) |
|
|
|
print(node); |
|
|
|
printf("\n"); |
|
|
|
} |
|
|
|
InputBuffer *inputBuffer=0; |
|
|
|
|
|
|
|
#define YYSTYPE Node * |
|
|
|
#define YY_INPUT(buff,result,maxSize) \ |
|
|
|
{if (atEnd(inputBuffer)){ \ |
|
|
|
result=0; \ |
|
|
|
} \ |
|
|
|
else { \ |
|
|
|
*buff=currentChar(inputBuffer); \ |
|
|
|
advance(inputBuffer,1); \ |
|
|
|
result=1; \ |
|
|
|
}} |
|
|
|
|
|
|
|
#define YYSTYPE Node * |
|
|
|
YYSTYPE yylval = 0; |
|
|
|
|
|
|
|
|
|
|
@ -361,16 +447,46 @@ YY_LOCAL(void) yySet(yycontext *yy, char *text, int count) { yy->__val[count]= |
|
|
|
|
|
|
|
#define YYACCEPT yyAccept(yy, yythunkpos0) |
|
|
|
|
|
|
|
YY_RULE(int) yy_space(yycontext *yy); /* 9 */ |
|
|
|
YY_RULE(int) yy_class(yycontext *yy); /* 8 */ |
|
|
|
YY_RULE(int) yy_string(yycontext *yy); /* 7 */ |
|
|
|
YY_RULE(int) yy_atom(yycontext *yy); /* 6 */ |
|
|
|
YY_RULE(int) yy_postfix(yycontext *yy); /* 5 */ |
|
|
|
YY_RULE(int) yy_space(yycontext *yy); /* 11 */ |
|
|
|
YY_RULE(int) yy_dot(yycontext *yy); /* 10 */ |
|
|
|
YY_RULE(int) yy_class(yycontext *yy); /* 9 */ |
|
|
|
YY_RULE(int) yy_string(yycontext *yy); /* 8 */ |
|
|
|
YY_RULE(int) yy_atom(yycontext *yy); /* 7 */ |
|
|
|
YY_RULE(int) yy_postfix(yycontext *yy); /* 6 */ |
|
|
|
YY_RULE(int) yy_prefix(yycontext *yy); /* 5 */ |
|
|
|
YY_RULE(int) yy_and(yycontext *yy); /* 4 */ |
|
|
|
YY_RULE(int) yy_or(yycontext *yy); /* 3 */ |
|
|
|
YY_RULE(int) yy__(yycontext *yy); /* 2 */ |
|
|
|
YY_RULE(int) yy_start(yycontext *yy); /* 1 */ |
|
|
|
|
|
|
|
YY_ACTION(void) yy_1_dot(yycontext *yy, char *yytext, int yyleng) |
|
|
|
{ |
|
|
|
#define __ yy->__ |
|
|
|
#define yypos yy->__pos |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_1_dot\n")); |
|
|
|
{ |
|
|
|
#line 198 |
|
|
|
__=mkDot(); |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
|
#undef yypos |
|
|
|
#undef yy |
|
|
|
} |
|
|
|
YY_ACTION(void) yy_1_class(yycontext *yy, char *yytext, int yyleng) |
|
|
|
{ |
|
|
|
#define __ yy->__ |
|
|
|
#define yypos yy->__pos |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_1_class\n")); |
|
|
|
{ |
|
|
|
#line 196 |
|
|
|
__=mkClass(yytext) ; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
|
#undef yypos |
|
|
|
#undef yy |
|
|
|
} |
|
|
|
YY_ACTION(void) yy_1_string(yycontext *yy, char *yytext, int yyleng) |
|
|
|
{ |
|
|
|
#define __ yy->__ |
|
|
@ -378,7 +494,7 @@ YY_ACTION(void) yy_1_string(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_1_string\n")); |
|
|
|
{ |
|
|
|
#line 105 |
|
|
|
#line 194 |
|
|
|
__ = mkString(yytext) ; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
@ -393,7 +509,7 @@ YY_ACTION(void) yy_4_postfix(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_4_postfix\n")); |
|
|
|
{ |
|
|
|
#line 101 |
|
|
|
#line 190 |
|
|
|
__ = s; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
@ -409,7 +525,7 @@ YY_ACTION(void) yy_3_postfix(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_3_postfix\n")); |
|
|
|
{ |
|
|
|
#line 100 |
|
|
|
#line 189 |
|
|
|
s = mkPlus(s) ; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
@ -425,7 +541,7 @@ YY_ACTION(void) yy_2_postfix(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_2_postfix\n")); |
|
|
|
{ |
|
|
|
#line 99 |
|
|
|
#line 188 |
|
|
|
s = mkStar(s) ; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
@ -441,7 +557,7 @@ YY_ACTION(void) yy_1_postfix(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_1_postfix\n")); |
|
|
|
{ |
|
|
|
#line 98 |
|
|
|
#line 187 |
|
|
|
s = mkQuery(s) ; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
@ -449,6 +565,38 @@ YY_ACTION(void) yy_1_postfix(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#undef yy |
|
|
|
#undef s |
|
|
|
} |
|
|
|
YY_ACTION(void) yy_2_prefix(yycontext *yy, char *yytext, int yyleng) |
|
|
|
{ |
|
|
|
#define p yy->__val[-1] |
|
|
|
#define __ yy->__ |
|
|
|
#define yypos yy->__pos |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_2_prefix\n")); |
|
|
|
{ |
|
|
|
#line 185 |
|
|
|
__ = p; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
|
#undef yypos |
|
|
|
#undef yy |
|
|
|
#undef p |
|
|
|
} |
|
|
|
YY_ACTION(void) yy_1_prefix(yycontext *yy, char *yytext, int yyleng) |
|
|
|
{ |
|
|
|
#define p yy->__val[-1] |
|
|
|
#define __ yy->__ |
|
|
|
#define yypos yy->__pos |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_1_prefix\n")); |
|
|
|
{ |
|
|
|
#line 184 |
|
|
|
__ = mkExc(p); |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
|
#undef yypos |
|
|
|
#undef yy |
|
|
|
#undef p |
|
|
|
} |
|
|
|
YY_ACTION(void) yy_2_and(yycontext *yy, char *yytext, int yyleng) |
|
|
|
{ |
|
|
|
#define a yy->__val[-1] |
|
|
@ -458,7 +606,7 @@ YY_ACTION(void) yy_2_and(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_2_and\n")); |
|
|
|
{ |
|
|
|
#line 96 |
|
|
|
#line 182 |
|
|
|
__ = p ; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
@ -476,8 +624,8 @@ YY_ACTION(void) yy_1_and(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_1_and\n")); |
|
|
|
{ |
|
|
|
#line 95 |
|
|
|
__ = mkAnd(p, a) ; |
|
|
|
#line 181 |
|
|
|
__ = mkAnd(p, a); ; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
|
#undef yypos |
|
|
@ -494,7 +642,7 @@ YY_ACTION(void) yy_2_or(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_2_or\n")); |
|
|
|
{ |
|
|
|
#line 93 |
|
|
|
#line 179 |
|
|
|
__ = a ; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
@ -512,8 +660,8 @@ YY_ACTION(void) yy_1_or(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_1_or\n")); |
|
|
|
{ |
|
|
|
#line 92 |
|
|
|
__ = mkOr(o, a) ; |
|
|
|
#line 178 |
|
|
|
__ = mkOr(o, a) ; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
|
#undef yypos |
|
|
@ -529,7 +677,7 @@ YY_ACTION(void) yy_1_start(yycontext *yy, char *yytext, int yyleng) |
|
|
|
#define yythunkpos yy->__thunkpos |
|
|
|
yyprintf((stderr, "do yy_1_start\n")); |
|
|
|
{ |
|
|
|
#line 90 |
|
|
|
#line 176 |
|
|
|
yylval = o ; |
|
|
|
} |
|
|
|
#undef yythunkpos |
|
|
@ -560,18 +708,18 @@ YY_RULE(int) yy_space(yycontext *yy) |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "space", yy->__buf+yy->__pos)); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
YY_RULE(int) yy_class(yycontext *yy) |
|
|
|
YY_RULE(int) yy_dot(yycontext *yy) |
|
|
|
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; |
|
|
|
yyprintf((stderr, "%s\n", "class")); if (!yymatchChar(yy, '[')) goto l9; if (!yymatchDot(yy)) goto l9; if (!yymatchDot(yy)) goto l9; if (!yymatchDot(yy)) goto l9; if (!yymatchChar(yy, ']')) goto l9; |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "class", yy->__buf+yy->__pos)); |
|
|
|
yyprintf((stderr, "%s\n", "dot")); if (!yy__(yy)) goto l9; if (!yymatchChar(yy, '.')) goto l9; if (!yy__(yy)) goto l9; yyDo(yy, yy_1_dot, yy->__begin, yy->__end); if (!yy__(yy)) goto l9; |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "dot", yy->__buf+yy->__pos)); |
|
|
|
return 1; |
|
|
|
l9:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "class", yy->__buf+yy->__pos)); |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "dot", yy->__buf+yy->__pos)); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
YY_RULE(int) yy_string(yycontext *yy) |
|
|
|
YY_RULE(int) yy_class(yycontext *yy) |
|
|
|
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; |
|
|
|
yyprintf((stderr, "%s\n", "string")); if (!yymatchChar(yy, '"')) goto l10; yyText(yy, yy->__begin, yy->__end); { |
|
|
|
yyprintf((stderr, "%s\n", "class")); if (!yymatchChar(yy, '[')) goto l10; if (!yy__(yy)) goto l10; yyText(yy, yy->__begin, yy->__end); { |
|
|
|
#define yytext yy->__text |
|
|
|
#define yyleng yy->__textlen |
|
|
|
if (!(YY_BEGIN)) goto l10; |
|
|
@ -579,7 +727,10 @@ if (!(YY_BEGIN)) goto l10; |
|
|
|
#undef yyleng |
|
|
|
} |
|
|
|
l11:; |
|
|
|
{ int yypos12= yy->__pos, yythunkpos12= yy->__thunkpos; if (!yymatchClass(yy, (unsigned char *)"\377\377\377\377\373\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377")) goto l12; goto l11; |
|
|
|
{ int yypos12= yy->__pos, yythunkpos12= yy->__thunkpos; |
|
|
|
{ int yypos13= yy->__pos, yythunkpos13= yy->__thunkpos; if (!yymatchChar(yy, ']')) goto l13; goto l12; |
|
|
|
l13:; yy->__pos= yypos13; yy->__thunkpos= yythunkpos13; |
|
|
|
} if (!yy_string(yy)) goto l12; goto l11; |
|
|
|
l12:; yy->__pos= yypos12; yy->__thunkpos= yythunkpos12; |
|
|
|
} yyText(yy, yy->__begin, yy->__end); { |
|
|
|
#define yytext yy->__text |
|
|
@ -587,86 +738,125 @@ if (!(YY_BEGIN)) goto l10; |
|
|
|
if (!(YY_END)) goto l10; |
|
|
|
#undef yytext |
|
|
|
#undef yyleng |
|
|
|
} if (!yymatchChar(yy, '"')) goto l10; yyDo(yy, yy_1_string, yy->__begin, yy->__end); if (!yy__(yy)) goto l10; |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "string", yy->__buf+yy->__pos)); |
|
|
|
} if (!yymatchChar(yy, ']')) goto l10; yyDo(yy, yy_1_class, yy->__begin, yy->__end); if (!yy__(yy)) goto l10; |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "class", yy->__buf+yy->__pos)); |
|
|
|
return 1; |
|
|
|
l10:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "class", yy->__buf+yy->__pos)); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
YY_RULE(int) yy_string(yycontext *yy) |
|
|
|
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; |
|
|
|
yyprintf((stderr, "%s\n", "string")); if (!yymatchChar(yy, '"')) goto l14; yyText(yy, yy->__begin, yy->__end); { |
|
|
|
#define yytext yy->__text |
|
|
|
#define yyleng yy->__textlen |
|
|
|
if (!(YY_BEGIN)) goto l14; |
|
|
|
#undef yytext |
|
|
|
#undef yyleng |
|
|
|
} |
|
|
|
l15:; |
|
|
|
{ int yypos16= yy->__pos, yythunkpos16= yy->__thunkpos; if (!yymatchClass(yy, (unsigned char *)"\377\377\377\377\373\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377")) goto l16; goto l15; |
|
|
|
l16:; yy->__pos= yypos16; yy->__thunkpos= yythunkpos16; |
|
|
|
} yyText(yy, yy->__begin, yy->__end); { |
|
|
|
#define yytext yy->__text |
|
|
|
#define yyleng yy->__textlen |
|
|
|
if (!(YY_END)) goto l14; |
|
|
|
#undef yytext |
|
|
|
#undef yyleng |
|
|
|
} if (!yymatchChar(yy, '"')) goto l14; yyDo(yy, yy_1_string, yy->__begin, yy->__end); if (!yy__(yy)) goto l14; |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "string", yy->__buf+yy->__pos)); |
|
|
|
return 1; |
|
|
|
l14:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "string", yy->__buf+yy->__pos)); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
YY_RULE(int) yy_atom(yycontext *yy) |
|
|
|
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; |
|
|
|
yyprintf((stderr, "%s\n", "atom")); |
|
|
|
{ int yypos14= yy->__pos, yythunkpos14= yy->__thunkpos; if (!yy_string(yy)) goto l15; goto l14; |
|
|
|
l15:; yy->__pos= yypos14; yy->__thunkpos= yythunkpos14; if (!yy_class(yy)) goto l13; |
|
|
|
{ int yypos18= yy->__pos, yythunkpos18= yy->__thunkpos; if (!yy_string(yy)) goto l19; goto l18; |
|
|
|
l19:; yy->__pos= yypos18; yy->__thunkpos= yythunkpos18; if (!yy_class(yy)) goto l20; goto l18; |
|
|
|
l20:; yy->__pos= yypos18; yy->__thunkpos= yythunkpos18; if (!yy_dot(yy)) goto l17; |
|
|
|
} |
|
|
|
l14:; |
|
|
|
l18:; |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "atom", yy->__buf+yy->__pos)); |
|
|
|
return 1; |
|
|
|
l13:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
l17:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "atom", yy->__buf+yy->__pos)); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
YY_RULE(int) yy_postfix(yycontext *yy) |
|
|
|
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; yyDo(yy, yyPush, 1, 0); |
|
|
|
yyprintf((stderr, "%s\n", "postfix")); if (!yy_atom(yy)) goto l16; yyDo(yy, yySet, -1, 0); |
|
|
|
{ int yypos17= yy->__pos, yythunkpos17= yy->__thunkpos; |
|
|
|
{ int yypos19= yy->__pos, yythunkpos19= yy->__thunkpos; if (!yymatchChar(yy, '?')) goto l20; if (!yy__(yy)) goto l20; yyDo(yy, yy_1_postfix, yy->__begin, yy->__end); goto l19; |
|
|
|
l20:; yy->__pos= yypos19; yy->__thunkpos= yythunkpos19; if (!yymatchChar(yy, '*')) goto l21; if (!yy__(yy)) goto l21; yyDo(yy, yy_2_postfix, yy->__begin, yy->__end); goto l19; |
|
|
|
l21:; yy->__pos= yypos19; yy->__thunkpos= yythunkpos19; if (!yymatchChar(yy, '+')) goto l17; if (!yy__(yy)) goto l17; yyDo(yy, yy_3_postfix, yy->__begin, yy->__end); |
|
|
|
yyprintf((stderr, "%s\n", "postfix")); if (!yy_atom(yy)) goto l21; yyDo(yy, yySet, -1, 0); |
|
|
|
{ int yypos22= yy->__pos, yythunkpos22= yy->__thunkpos; |
|
|
|
{ int yypos24= yy->__pos, yythunkpos24= yy->__thunkpos; if (!yymatchChar(yy, '?')) goto l25; if (!yy__(yy)) goto l25; yyDo(yy, yy_1_postfix, yy->__begin, yy->__end); goto l24; |
|
|
|
l25:; yy->__pos= yypos24; yy->__thunkpos= yythunkpos24; if (!yymatchChar(yy, '*')) goto l26; if (!yy__(yy)) goto l26; yyDo(yy, yy_2_postfix, yy->__begin, yy->__end); goto l24; |
|
|
|
l26:; yy->__pos= yypos24; yy->__thunkpos= yythunkpos24; if (!yymatchChar(yy, '+')) goto l22; if (!yy__(yy)) goto l22; yyDo(yy, yy_3_postfix, yy->__begin, yy->__end); |
|
|
|
} |
|
|
|
l19:; goto l18; |
|
|
|
l17:; yy->__pos= yypos17; yy->__thunkpos= yythunkpos17; |
|
|
|
l24:; goto l23; |
|
|
|
l22:; yy->__pos= yypos22; yy->__thunkpos= yythunkpos22; |
|
|
|
} |
|
|
|
l18:; yyDo(yy, yy_4_postfix, yy->__begin, yy->__end); |
|
|
|
l23:; yyDo(yy, yy_4_postfix, yy->__begin, yy->__end); |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "postfix", yy->__buf+yy->__pos)); yyDo(yy, yyPop, 1, 0); |
|
|
|
return 1; |
|
|
|
l16:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
l21:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "postfix", yy->__buf+yy->__pos)); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
YY_RULE(int) yy_prefix(yycontext *yy) |
|
|
|
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; yyDo(yy, yyPush, 1, 0); |
|
|
|
yyprintf((stderr, "%s\n", "prefix")); |
|
|
|
{ int yypos28= yy->__pos, yythunkpos28= yy->__thunkpos; if (!yymatchChar(yy, '!')) goto l29; if (!yy__(yy)) goto l29; if (!yy_postfix(yy)) goto l29; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_prefix, yy->__begin, yy->__end); goto l28; |
|
|
|
l29:; yy->__pos= yypos28; yy->__thunkpos= yythunkpos28; if (!yy_postfix(yy)) goto l27; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_2_prefix, yy->__begin, yy->__end); |
|
|
|
} |
|
|
|
l28:; |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "prefix", yy->__buf+yy->__pos)); yyDo(yy, yyPop, 1, 0); |
|
|
|
return 1; |
|
|
|
l27:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "prefix", yy->__buf+yy->__pos)); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
YY_RULE(int) yy_and(yycontext *yy) |
|
|
|
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; yyDo(yy, yyPush, 2, 0); |
|
|
|
yyprintf((stderr, "%s\n", "and")); |
|
|
|
{ int yypos23= yy->__pos, yythunkpos23= yy->__thunkpos; if (!yy_postfix(yy)) goto l24; yyDo(yy, yySet, -2, 0); if (!yy_and(yy)) goto l24; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_and, yy->__begin, yy->__end); goto l23; |
|
|
|
l24:; yy->__pos= yypos23; yy->__thunkpos= yythunkpos23; if (!yy_postfix(yy)) goto l22; yyDo(yy, yySet, -2, 0); yyDo(yy, yy_2_and, yy->__begin, yy->__end); |
|
|
|
{ int yypos31= yy->__pos, yythunkpos31= yy->__thunkpos; if (!yy_prefix(yy)) goto l32; yyDo(yy, yySet, -2, 0); if (!yy_and(yy)) goto l32; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_and, yy->__begin, yy->__end); goto l31; |
|
|
|
l32:; yy->__pos= yypos31; yy->__thunkpos= yythunkpos31; if (!yy_prefix(yy)) goto l30; yyDo(yy, yySet, -2, 0); yyDo(yy, yy_2_and, yy->__begin, yy->__end); |
|
|
|
} |
|
|
|
l23:; |
|
|
|
l31:; |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "and", yy->__buf+yy->__pos)); yyDo(yy, yyPop, 2, 0); |
|
|
|
return 1; |
|
|
|
l22:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
l30:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "and", yy->__buf+yy->__pos)); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
YY_RULE(int) yy_or(yycontext *yy) |
|
|
|
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; yyDo(yy, yyPush, 2, 0); |
|
|
|
yyprintf((stderr, "%s\n", "or")); |
|
|
|
{ int yypos26= yy->__pos, yythunkpos26= yy->__thunkpos; if (!yy_and(yy)) goto l27; yyDo(yy, yySet, -2, 0); if (!yymatchChar(yy, '|')) goto l27; if (!yy__(yy)) goto l27; if (!yy_or(yy)) goto l27; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_or, yy->__begin, yy->__end); goto l26; |
|
|
|
l27:; yy->__pos= yypos26; yy->__thunkpos= yythunkpos26; if (!yy_and(yy)) goto l25; yyDo(yy, yySet, -2, 0); yyDo(yy, yy_2_or, yy->__begin, yy->__end); |
|
|
|
{ int yypos34= yy->__pos, yythunkpos34= yy->__thunkpos; if (!yy_and(yy)) goto l35; yyDo(yy, yySet, -2, 0); if (!yy__(yy)) goto l35; if (!yymatchChar(yy, '|')) goto l35; if (!yy__(yy)) goto l35; if (!yy_or(yy)) goto l35; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_or, yy->__begin, yy->__end); goto l34; |
|
|
|
l35:; yy->__pos= yypos34; yy->__thunkpos= yythunkpos34; if (!yy_and(yy)) goto l33; yyDo(yy, yySet, -2, 0); yyDo(yy, yy_2_or, yy->__begin, yy->__end); |
|
|
|
} |
|
|
|
l26:; |
|
|
|
l34:; |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "or", yy->__buf+yy->__pos)); yyDo(yy, yyPop, 2, 0); |
|
|
|
return 1; |
|
|
|
l25:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
l33:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "or", yy->__buf+yy->__pos)); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
YY_RULE(int) yy__(yycontext *yy) |
|
|
|
{ |
|
|
|
yyprintf((stderr, "%s\n", "_")); |
|
|
|
l29:; |
|
|
|
{ int yypos30= yy->__pos, yythunkpos30= yy->__thunkpos; if (!yy_space(yy)) goto l30; goto l29; |
|
|
|
l30:; yy->__pos= yypos30; yy->__thunkpos= yythunkpos30; |
|
|
|
l37:; |
|
|
|
{ int yypos38= yy->__pos, yythunkpos38= yy->__thunkpos; if (!yy_space(yy)) goto l38; goto l37; |
|
|
|
l38:; yy->__pos= yypos38; yy->__thunkpos= yythunkpos38; |
|
|
|
} |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "_", yy->__buf+yy->__pos)); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
YY_RULE(int) yy_start(yycontext *yy) |
|
|
|
{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; yyDo(yy, yyPush, 1, 0); |
|
|
|
yyprintf((stderr, "%s\n", "start")); if (!yy__(yy)) goto l31; if (!yy_or(yy)) goto l31; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_start, yy->__begin, yy->__end); |
|
|
|
yyprintf((stderr, "%s\n", "start")); if (!yy__(yy)) goto l39; if (!yy_or(yy)) goto l39; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_start, yy->__begin, yy->__end); |
|
|
|
yyprintf((stderr, " ok %s @ %s\n", "start", yy->__buf+yy->__pos)); yyDo(yy, yyPop, 1, 0); |
|
|
|
return 1; |
|
|
|
l31:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
l39:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; |
|
|
|
yyprintf((stderr, " fail %s @ %s\n", "start", yy->__buf+yy->__pos)); |
|
|
|
return 0; |
|
|
|
} |
|
|
@ -718,14 +908,119 @@ YY_PARSE(yycontext *) YYRELEASE(yycontext *yyctx) |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
#line 113 "parse.leg" |
|
|
|
#line 205 "parse.leg" |
|
|
|
|
|
|
|
|
|
|
|
Node *_checktype(Node *object, enum op type) |
|
|
|
{ |
|
|
|
if (object->type == type) return object; |
|
|
|
fprintf(stderr, "\naccesing type %i as if it were a %i\n", object->type, type); |
|
|
|
exit(1); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
#define get(object, type, member) (_checktype(object, type)->type.member) |
|
|
|
|
|
|
|
int execute(Node *node, InputBuffer *in) |
|
|
|
{ |
|
|
|
switch (node->type) { |
|
|
|
case String: { |
|
|
|
if (strncmp(currentText(in), get(node,String,string), get(node,String,len))) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
advance(in, get(node,String,len)); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
case And: { |
|
|
|
int pos= getPosition(in); |
|
|
|
if (!execute(get(node,And,children[0]), in)) //si il y a eu une erreur |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
} //si ça s'est bien passé |
|
|
|
if (!execute(get(node,And,children[1]), in)) { |
|
|
|
setPosition(in, pos); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
case Or: { |
|
|
|
if (execute(get(node,Or,children[0]), in)) { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
return execute(get(node,Or,children[1]), in); |
|
|
|
} |
|
|
|
case Star: { |
|
|
|
while (execute(get(node,Star,children[0]), in)); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
case Plus: { |
|
|
|
if (!execute(get(node,Plus,children[0]), in)) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
while (execute(get(node,Plus,children[0]), in)); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
case Class: { |
|
|
|
if (!currentChar(in)) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
if (strchr(get(node,Class,stringValue), currentChar(in))) { |
|
|
|
advance(in, 1); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
case Query: { |
|
|
|
execute(get(node,Query,children[0]), in); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
case Exc: { |
|
|
|
int pos= getPosition(in); |
|
|
|
if (!execute(get(node,Exc,children[0]), in)) { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
setPosition(in, pos); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
case Dot: { |
|
|
|
if (atEnd(in)) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
advance(in, 1); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
printf("this cannot happen\n"); |
|
|
|
abort(); |
|
|
|
} |
|
|
|
|
|
|
|
int main(int argc, char **argv) |
|
|
|
{ |
|
|
|
while (yyparse()) { |
|
|
|
println(yylval); |
|
|
|
if(argc<2) return 0; |
|
|
|
|
|
|
|
inputBuffer = mkInputBuffer(argv[1]); |
|
|
|
|
|
|
|
if (!yyparse()) { |
|
|
|
printf("Error\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
println(yylval); |
|
|
|
char *line=0; |
|
|
|
size_t line_max=0; |
|
|
|
ssize_t line_len=0; |
|
|
|
while((line_len=getline(&line,&line_max,stdin))>=0){ |
|
|
|
if(line_len>0 && line[line_len-1]=='\n'){ |
|
|
|
line[line_len-1]=0; |
|
|
|
} |
|
|
|
initInputBuffer(inputBuffer,line); |
|
|
|
if (!execute(yylval, inputBuffer) || !atEnd(inputBuffer)){ |
|
|
|
printf("no match, current position : %i\n", getPosition(inputBuffer)); |
|
|
|
} |
|
|
|
else{ |
|
|
|
printf("match, current position : %i\n", getPosition(inputBuffer)); |
|
|
|
}// 0 => no match, 1 => match |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|