From 192e8a0ca5aaf3659e129c05766ba4a977d9cac0 Mon Sep 17 00:00:00 2001 From: lquint Date: Mon, 12 Jul 2021 12:44:39 +0200 Subject: [PATCH] symbolTable in .leg --- parse | Bin 23640 -> 0 bytes parse.c | 423 ++++++++++++++++++++++++++++++++++++++++++------------ parse.leg | 176 +++++++++++++++++++++-- 3 files changed, 492 insertions(+), 107 deletions(-) delete mode 100755 parse diff --git a/parse b/parse deleted file mode 100755 index 1dc61d2e4a61015d084c358c057ce8ef797e3e05..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 23640 zcmcIs4SZD9m48VHL<~tl(1=hUXb`Z3@M+K>lR)sn@)3blRB#xQ2}JVcWI~e`G;Ppz zcA9SL&vwz`meSp|b!)Y5Vb!uBK$l=YY}#&>DwgPCoe)3LmMXR>v;TAMxo_T^%%p7h zw~ya&-u<7Cd+xdC-gn=9FYkfURm)RTQVe~h8Mhi#>K&~Rk1%q}**sBQGyAa>*FGVtiolw|2BdplT3=aD&F z975-dJx#UV?a(7XFZIX~!F5t!vbgj}eVR&hjoCHTTNlosT~j%$rn;`Fc~*1b!dVOF z=Qq~p&*gTLeUiOxjY=E}tC(W`c$5hv{?$42uAg_V=*PeM@V!|(7oPv=jXyd0Rg%rc zPxqUVVj8Vtg7B(xU(TZ6g>`xWaUb79ahx0CQhpNr)+9K!BaxlgfSdTmALLsi`He~N z$w}~F5`0$@{6G@?_9Xacli(i$H}Q)3G-tn>#0Bw4XNU{o~(s_TMP#x{QtW6qD-Dw=)Xs_HslP4#E|q*`0QlVEa@JP8E7 zwLa8T74Z9w+g7b8S?ZmeKWDyu8atbtzrgUW*s$7*`uy9f8-xD9hSf`J>g)U)d|PYC z=C<1UI|sgE)TPCcQIjSk$t z^ntm>f$M7w>1=o4&g)Hs1E;$6(d@u=9}utAfukes<6#FbOAzLDIPgqc+A#Jya3qL* z?04YVHfk8(bl^JIi2bYsAM22R-hn&kl`aQi&W3~Mt?`AP36-hq`aE2|naVUY`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W)^Hb~Te%uRP64Cnl zd1S#7fH-;-vH#clnw|s4sc+xUdz6ZvXS4yWr^^F4AxzhAdQ4{JdYBkpirD{~_L(~Q z0|?b$5Ql618F4tt(&40WDZ+fq!^F5C_sw*jp?hcTzit=hxAt9WsQ*1QG2{4!o_JKz Yu2+h<*GsH_#ResDQ40#yerx!D0716sX#fBK diff --git a/parse.c b/parse.c index a9408b4..042bbba 100644 --- a/parse.c +++ b/parse.c @@ -3,7 +3,7 @@ #include #include #include -#define YYRULECOUNT 11 +#define YYRULECOUNT 15 #line 1 "parse.leg" @@ -12,10 +12,17 @@ #include #include "inputBuffer.c" ; -enum op { String, Query, Star, Plus, Or, And, Class, Dot, Exc } ; +enum op { String, Query, Star, Plus, Or, And, Class, Dot, Exc, Id } ; typedef union Node Node; +typedef struct Symbol Symbol; +typedef struct Array Array; +typedef struct SymbolTable SymbolTable; +struct Array { + Node **elements; + int length; +}; struct String { enum op type; char *string; int len; }; struct Query { enum op type; Node *children[1]; }; @@ -24,8 +31,9 @@ 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 Dot { enum op type; }; struct Exc { enum op type; Node *children[1]; }; +struct Id { enum op type; Symbol *symbol; }; union Node { enum op type; @@ -38,8 +46,30 @@ union Node { struct Class Class; struct Dot Dot; struct Exc Exc; + struct Id Id; +}; + +struct Symbol{ + char* name; + Node *rule; +}; + +struct SymbolTable { + Symbol **elements; + int length; }; +#define SymbolTable_initialiser {0,0} +SymbolTable symbolTable= SymbolTable_initialiser; + +Symbol *createSymbol(char *name) { + Symbol *symbol= calloc(1, sizeof(Symbol)); + symbol->name= strdup(name); + return symbol; +} + + + #define new(type) mkNode(sizeof(struct type),type) @@ -58,6 +88,15 @@ Node *mkString(char *s) return node; } +Node *mkId(char *s){ + + Node *node= new(Id); + node->Id.symbol=createSymbol(s); + return node; +} + + + Node *mkQuery(Node *n) { Node *node= new(Query); @@ -116,6 +155,16 @@ Node *mkExc(Node *n) return node; } +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) + void print(Node *node) { switch (node->type) { @@ -154,6 +203,9 @@ void print(Node *node) printf("!"); print(node->Exc.children[0]); return; + case Id: + printf("%s\n",get(node,Id,symbol)->name); + return; } abort(); } @@ -175,6 +227,102 @@ else { \ result=1; \ }} + + +void move(SymbolTable *symbolTable, int a) { + symbolTable->length++; + symbolTable->elements= realloc(symbolTable->elements,sizeof(Node*) * symbolTable->length); + printf("begin\n"); + for (int i= symbolTable->length-1; i >a; i--) { + symbolTable->elements[i] = symbolTable->elements[i-1]; + printf("\n"); + for(int i= 0; ilength; i++) { + printf("number : %i, name : %s, value : a\n",i, symbolTable->elements[i]->name); + } + } + printf("end\n"); +} + +void addSymbolSorted(SymbolTable *symbolTable, Symbol *symbol) { + int a=0; + int b= symbolTable->length-1; + int c; + //1 no infinite loop with a and c = 0 et b =1 + while (1 < b - a ) { + c= (a+b)/2; + if (strcmp(symbolTable->elements[c]->name, symbol->name) < 0) { + a= c; + } else { + b= c; + } + } + //b>-1 <=> symboleTable->length > 0 + // this if is here to know if we put the symbol before or after a + if (b>-1 && strcmp(symbolTable->elements[a]->name, symbol->name) < 0) { + a++; + } + //we move all the symbols after a + move(symbolTable, a); + //we put the symbol at the right place + symbolTable->elements[a]->name = symbol->name; +} + +int findSymbol(SymbolTable *symbolTable, char *name) { + for (int i= 0; i < symbolTable->length;i++) { + if (strcmp(symbolTable->elements[i]->name, name) == 0) { + return 1; + } + } + Symbol *symbol = createSymbol(name); + addSymbolSorted(symbolTable, symbol); + return 0; +} + +Node *findSymbolSorted(SymbolTable *symbolTable, char *name) { + int a=0; + int b= symbolTable->length-1; + int c; + //1 no infinite loop with a and c = 0 et b =1 + while (1 < b - a ) { + c= (a+b)/2; + if (strcmp(symbolTable->elements[c]->name, name) < 0) { + a= c; + } else { + if (strcmp(symbolTable->elements[c]->name, name) > 0) { + b= c; + } else { + return symbolTable->elements[c]->rule; + } + } + } + //b>-1 <=> symboleTable->length > 0 + // this if is here to know if we put the symbol before or after a + if (b>-1 && strcmp(symbolTable->elements[a]->name, name) < 0) { + a++; + } + //we move all the symbols after a + move(symbolTable, a); + //we put the symbol at the right place + symbolTable->elements[a]= createSymbol(name); + return 0; +} + +void setRule(SymbolTable *symbolTable, char *name, Node *rule) { + for (int i= 0; i < symbolTable->length;i++) { + if (strcmp(symbolTable->elements[i]->name, name) == 0) { + symbolTable->elements[i]->rule= rule; + break; + } + } +} + +void arrayAppend(Array *array, Node *statement) { + array->length++; + array->elements= realloc(array->elements,sizeof(Node*) * array->length); + array->elements[array->length-1] = statement; + } + + #define YYSTYPE Node * YYSTYPE yylval = 0; @@ -447,16 +595,20 @@ 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); /* 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_space(yycontext *yy); /* 15 */ +YY_RULE(int) yy_rule(yycontext *yy); /* 14 */ +YY_RULE(int) yy_dot(yycontext *yy); /* 13 */ +YY_RULE(int) yy_class(yycontext *yy); /* 12 */ +YY_RULE(int) yy_string(yycontext *yy); /* 11 */ +YY_RULE(int) yy_atom(yycontext *yy); /* 10 */ +YY_RULE(int) yy_postfix(yycontext *yy); /* 9 */ +YY_RULE(int) yy_prefix(yycontext *yy); /* 8 */ +YY_RULE(int) yy_and(yycontext *yy); /* 7 */ +YY_RULE(int) yy_or(yycontext *yy); /* 6 */ +YY_RULE(int) yy_expression(yycontext *yy); /* 5 */ +YY_RULE(int) yy__(yycontext *yy); /* 4 */ +YY_RULE(int) yy_id(yycontext *yy); /* 3 */ +YY_RULE(int) yy_declaration(yycontext *yy); /* 2 */ YY_RULE(int) yy_start(yycontext *yy); /* 1 */ YY_ACTION(void) yy_1_dot(yycontext *yy, char *yytext, int yyleng) @@ -466,7 +618,7 @@ YY_ACTION(void) yy_1_dot(yycontext *yy, char *yytext, int yyleng) #define yythunkpos yy->__thunkpos yyprintf((stderr, "do yy_1_dot\n")); { -#line 198 +#line 352 __=mkDot(); } #undef yythunkpos @@ -480,7 +632,7 @@ YY_ACTION(void) yy_1_class(yycontext *yy, char *yytext, int yyleng) #define yythunkpos yy->__thunkpos yyprintf((stderr, "do yy_1_class\n")); { -#line 196 +#line 350 __=mkClass(yytext) ; } #undef yythunkpos @@ -494,13 +646,43 @@ YY_ACTION(void) yy_1_string(yycontext *yy, char *yytext, int yyleng) #define yythunkpos yy->__thunkpos yyprintf((stderr, "do yy_1_string\n")); { -#line 194 +#line 348 __ = mkString(yytext) ; } #undef yythunkpos #undef yypos #undef yy } +YY_ACTION(void) yy_1_id(yycontext *yy, char *yytext, int yyleng) +{ +#define __ yy->__ +#define yypos yy->__pos +#define yythunkpos yy->__thunkpos + yyprintf((stderr, "do yy_1_id\n")); + { +#line 346 + __ = mkId(yytext) ; + } +#undef yythunkpos +#undef yypos +#undef yy +} +YY_ACTION(void) yy_1_rule(yycontext *yy, char *yytext, int yyleng) +{ +#define i yy->__val[-1] +#define __ yy->__ +#define yypos yy->__pos +#define yythunkpos yy->__thunkpos + yyprintf((stderr, "do yy_1_rule\n")); + { +#line 344 + __ = mkId(yytext) ; + } +#undef yythunkpos +#undef yypos +#undef yy +#undef i +} YY_ACTION(void) yy_4_postfix(yycontext *yy, char *yytext, int yyleng) { #define s yy->__val[-1] @@ -509,7 +691,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 190 +#line 340 __ = s; } #undef yythunkpos @@ -525,7 +707,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 189 +#line 339 s = mkPlus(s) ; } #undef yythunkpos @@ -541,7 +723,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 188 +#line 338 s = mkStar(s) ; } #undef yythunkpos @@ -557,7 +739,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 187 +#line 337 s = mkQuery(s) ; } #undef yythunkpos @@ -573,7 +755,7 @@ YY_ACTION(void) yy_2_prefix(yycontext *yy, char *yytext, int yyleng) #define yythunkpos yy->__thunkpos yyprintf((stderr, "do yy_2_prefix\n")); { -#line 185 +#line 335 __ = p; } #undef yythunkpos @@ -589,7 +771,7 @@ YY_ACTION(void) yy_1_prefix(yycontext *yy, char *yytext, int yyleng) #define yythunkpos yy->__thunkpos yyprintf((stderr, "do yy_1_prefix\n")); { -#line 184 +#line 334 __ = mkExc(p); } #undef yythunkpos @@ -606,7 +788,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 182 +#line 332 __ = p ; } #undef yythunkpos @@ -624,7 +806,7 @@ YY_ACTION(void) yy_1_and(yycontext *yy, char *yytext, int yyleng) #define yythunkpos yy->__thunkpos yyprintf((stderr, "do yy_1_and\n")); { -#line 181 +#line 331 __ = mkAnd(p, a); ; } #undef yythunkpos @@ -642,7 +824,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 179 +#line 329 __ = a ; } #undef yythunkpos @@ -660,7 +842,7 @@ YY_ACTION(void) yy_1_or(yycontext *yy, char *yytext, int yyleng) #define yythunkpos yy->__thunkpos yyprintf((stderr, "do yy_1_or\n")); { -#line 178 +#line 328 __ = mkOr(o, a) ; } #undef yythunkpos @@ -669,21 +851,23 @@ YY_ACTION(void) yy_1_or(yycontext *yy, char *yytext, int yyleng) #undef o #undef a } -YY_ACTION(void) yy_1_start(yycontext *yy, char *yytext, int yyleng) +YY_ACTION(void) yy_1_declaration(yycontext *yy, char *yytext, int yyleng) { -#define o yy->__val[-1] +#define e yy->__val[-1] +#define i yy->__val[-2] #define __ yy->__ #define yypos yy->__pos #define yythunkpos yy->__thunkpos - yyprintf((stderr, "do yy_1_start\n")); + yyprintf((stderr, "do yy_1_declaration\n")); { -#line 176 - yylval = o ; +#line 326 + setRule(&symbolTable,get(i, Id, symbol)->name, e) ; } #undef yythunkpos #undef yypos #undef yy -#undef o +#undef e +#undef i } YY_RULE(int) yy_space(yycontext *yy) @@ -708,155 +892,206 @@ YY_RULE(int) yy_space(yycontext *yy) yyprintf((stderr, " fail %s @ %s\n", "space", yy->__buf+yy->__pos)); return 0; } +YY_RULE(int) yy_rule(yycontext *yy) +{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; yyDo(yy, yyPush, 1, 0); + yyprintf((stderr, "%s\n", "rule")); if (!yy_id(yy)) goto l9; yyDo(yy, yySet, -1, 0); + { int yypos10= yy->__pos, yythunkpos10= yy->__thunkpos; if (!yymatchChar(yy, '=')) goto l10; goto l9; + l10:; yy->__pos= yypos10; yy->__thunkpos= yythunkpos10; + } yyDo(yy, yy_1_rule, yy->__begin, yy->__end); + yyprintf((stderr, " ok %s @ %s\n", "rule", yy->__buf+yy->__pos)); yyDo(yy, yyPop, 1, 0); + return 1; + l9:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "rule", yy->__buf+yy->__pos)); + return 0; +} YY_RULE(int) yy_dot(yycontext *yy) { int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; - 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, "%s\n", "dot")); if (!yy__(yy)) goto l11; if (!yymatchChar(yy, '.')) goto l11; if (!yy__(yy)) goto l11; yyDo(yy, yy_1_dot, yy->__begin, yy->__end); if (!yy__(yy)) goto l11; yyprintf((stderr, " ok %s @ %s\n", "dot", yy->__buf+yy->__pos)); return 1; - l9:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + l11:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; yyprintf((stderr, " fail %s @ %s\n", "dot", yy->__buf+yy->__pos)); return 0; } YY_RULE(int) yy_class(yycontext *yy) { int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; - yyprintf((stderr, "%s\n", "class")); if (!yymatchChar(yy, '[')) goto l10; if (!yy__(yy)) goto l10; yyText(yy, yy->__begin, yy->__end); { + yyprintf((stderr, "%s\n", "class")); if (!yymatchChar(yy, '[')) goto l12; if (!yy__(yy)) goto l12; yyText(yy, yy->__begin, yy->__end); { #define yytext yy->__text #define yyleng yy->__textlen -if (!(YY_BEGIN)) goto l10; +if (!(YY_BEGIN)) goto l12; #undef yytext #undef yyleng } - 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; + l13:; + { int yypos14= yy->__pos, yythunkpos14= yy->__thunkpos; + { int yypos15= yy->__pos, yythunkpos15= yy->__thunkpos; if (!yymatchChar(yy, ']')) goto l15; goto l14; + l15:; yy->__pos= yypos15; yy->__thunkpos= yythunkpos15; + } if (!yy_string(yy)) goto l14; goto l13; + l14:; yy->__pos= yypos14; yy->__thunkpos= yythunkpos14; } yyText(yy, yy->__begin, yy->__end); { #define yytext yy->__text #define yyleng yy->__textlen -if (!(YY_END)) goto l10; +if (!(YY_END)) goto l12; #undef yytext #undef yyleng - } if (!yymatchChar(yy, ']')) goto l10; yyDo(yy, yy_1_class, yy->__begin, yy->__end); if (!yy__(yy)) goto l10; + } if (!yymatchChar(yy, ']')) goto l12; yyDo(yy, yy_1_class, yy->__begin, yy->__end); if (!yy__(yy)) goto l12; yyprintf((stderr, " ok %s @ %s\n", "class", yy->__buf+yy->__pos)); return 1; - l10:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + l12:; 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); { + yyprintf((stderr, "%s\n", "string")); if (!yymatchChar(yy, '"')) goto l16; yyText(yy, yy->__begin, yy->__end); { #define yytext yy->__text #define yyleng yy->__textlen -if (!(YY_BEGIN)) goto l14; +if (!(YY_BEGIN)) goto l16; #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; + l17:; + { int yypos18= yy->__pos, yythunkpos18= 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 l18; goto l17; + l18:; yy->__pos= yypos18; yy->__thunkpos= yythunkpos18; } yyText(yy, yy->__begin, yy->__end); { #define yytext yy->__text #define yyleng yy->__textlen -if (!(YY_END)) goto l14; +if (!(YY_END)) goto l16; #undef yytext #undef yyleng - } if (!yymatchChar(yy, '"')) goto l14; yyDo(yy, yy_1_string, yy->__begin, yy->__end); if (!yy__(yy)) goto l14; + } if (!yymatchChar(yy, '"')) goto l16; yyDo(yy, yy_1_string, yy->__begin, yy->__end); if (!yy__(yy)) goto l16; yyprintf((stderr, " ok %s @ %s\n", "string", yy->__buf+yy->__pos)); return 1; - l14:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + l16:; 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 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; + { int yypos20= yy->__pos, yythunkpos20= yy->__thunkpos; if (!yy_string(yy)) goto l21; goto l20; + l21:; yy->__pos= yypos20; yy->__thunkpos= yythunkpos20; if (!yy_class(yy)) goto l22; goto l20; + l22:; yy->__pos= yypos20; yy->__thunkpos= yythunkpos20; if (!yy_dot(yy)) goto l23; goto l20; + l23:; yy->__pos= yypos20; yy->__thunkpos= yythunkpos20; if (!yy_rule(yy)) goto l19; } - l18:; + l20:; yyprintf((stderr, " ok %s @ %s\n", "atom", yy->__buf+yy->__pos)); return 1; - l17:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + l19:; 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 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); + yyprintf((stderr, "%s\n", "postfix")); if (!yy_atom(yy)) goto l24; yyDo(yy, yySet, -1, 0); + { int yypos25= yy->__pos, yythunkpos25= yy->__thunkpos; + { int yypos27= yy->__pos, yythunkpos27= yy->__thunkpos; if (!yymatchChar(yy, '?')) goto l28; if (!yy__(yy)) goto l28; yyDo(yy, yy_1_postfix, yy->__begin, yy->__end); goto l27; + l28:; yy->__pos= yypos27; yy->__thunkpos= yythunkpos27; if (!yymatchChar(yy, '*')) goto l29; if (!yy__(yy)) goto l29; yyDo(yy, yy_2_postfix, yy->__begin, yy->__end); goto l27; + l29:; yy->__pos= yypos27; yy->__thunkpos= yythunkpos27; if (!yymatchChar(yy, '+')) goto l25; if (!yy__(yy)) goto l25; yyDo(yy, yy_3_postfix, yy->__begin, yy->__end); } - l24:; goto l23; - l22:; yy->__pos= yypos22; yy->__thunkpos= yythunkpos22; + l27:; goto l26; + l25:; yy->__pos= yypos25; yy->__thunkpos= yythunkpos25; } - l23:; yyDo(yy, yy_4_postfix, yy->__begin, yy->__end); + l26:; 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; - l21:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + l24:; 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); + { int yypos31= yy->__pos, yythunkpos31= yy->__thunkpos; if (!yymatchChar(yy, '!')) goto l32; if (!yy__(yy)) goto l32; if (!yy_postfix(yy)) goto l32; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_prefix, yy->__begin, yy->__end); goto l31; + l32:; yy->__pos= yypos31; yy->__thunkpos= yythunkpos31; if (!yy_postfix(yy)) goto l30; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_2_prefix, yy->__begin, yy->__end); } - l28:; + l31:; 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; + l30:; 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 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); + { int yypos34= yy->__pos, yythunkpos34= yy->__thunkpos; if (!yy_prefix(yy)) goto l35; yyDo(yy, yySet, -2, 0); if (!yy_and(yy)) goto l35; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_and, yy->__begin, yy->__end); goto l34; + l35:; yy->__pos= yypos34; yy->__thunkpos= yythunkpos34; if (!yy_prefix(yy)) goto l33; yyDo(yy, yySet, -2, 0); yyDo(yy, yy_2_and, yy->__begin, yy->__end); } - l31:; + l34:; yyprintf((stderr, " ok %s @ %s\n", "and", yy->__buf+yy->__pos)); yyDo(yy, yyPop, 2, 0); return 1; - l30:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + l33:; 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 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); + { int yypos37= yy->__pos, yythunkpos37= yy->__thunkpos; if (!yy_and(yy)) goto l38; yyDo(yy, yySet, -2, 0); if (!yy__(yy)) goto l38; if (!yymatchChar(yy, '|')) goto l38; if (!yy__(yy)) goto l38; if (!yy_or(yy)) goto l38; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_or, yy->__begin, yy->__end); goto l37; + l38:; yy->__pos= yypos37; yy->__thunkpos= yythunkpos37; if (!yy_and(yy)) goto l36; yyDo(yy, yySet, -2, 0); yyDo(yy, yy_2_or, yy->__begin, yy->__end); } - l34:; + l37:; yyprintf((stderr, " ok %s @ %s\n", "or", yy->__buf+yy->__pos)); yyDo(yy, yyPop, 2, 0); return 1; - l33:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + l36:; 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", "_")); - l37:; - { int yypos38= yy->__pos, yythunkpos38= yy->__thunkpos; if (!yy_space(yy)) goto l38; goto l37; - l38:; yy->__pos= yypos38; yy->__thunkpos= yythunkpos38; + l40:; + { int yypos41= yy->__pos, yythunkpos41= yy->__thunkpos; if (!yy_space(yy)) goto l41; goto l40; + l41:; yy->__pos= yypos41; yy->__thunkpos= yythunkpos41; } yyprintf((stderr, " ok %s @ %s\n", "_", yy->__buf+yy->__pos)); return 1; } +YY_RULE(int) yy_id(yycontext *yy) +{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; + yyprintf((stderr, "%s\n", "id")); yyText(yy, yy->__begin, yy->__end); { +#define yytext yy->__text +#define yyleng yy->__textlen +if (!(YY_BEGIN)) goto l42; +#undef yytext +#undef yyleng + } if (!yymatchClass(yy, (unsigned char *)"\000\000\000\000\000\000\000\000\376\377\377\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l42; + l43:; + { int yypos44= yy->__pos, yythunkpos44= yy->__thunkpos; if (!yymatchClass(yy, (unsigned char *)"\000\000\000\000\000\000\377\003\376\377\377\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l44; goto l43; + l44:; yy->__pos= yypos44; yy->__thunkpos= yythunkpos44; + } yyText(yy, yy->__begin, yy->__end); { +#define yytext yy->__text +#define yyleng yy->__textlen +if (!(YY_END)) goto l42; +#undef yytext +#undef yyleng + } if (!yy__(yy)) goto l42; yyDo(yy, yy_1_id, yy->__begin, yy->__end); + yyprintf((stderr, " ok %s @ %s\n", "id", yy->__buf+yy->__pos)); + return 1; + l42:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "id", yy->__buf+yy->__pos)); + return 0; +} +YY_RULE(int) yy_declaration(yycontext *yy) +{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; yyDo(yy, yyPush, 2, 0); + yyprintf((stderr, "%s\n", "declaration")); if (!yy_id(yy)) goto l45; yyDo(yy, yySet, -2, 0); if (!yymatchChar(yy, '=')) goto l45; if (!yy__(yy)) goto l45; if (!yy_expression(yy)) goto l45; yyDo(yy, yySet, -1, 0); yyDo(yy, yy_1_declaration, yy->__begin, yy->__end); + yyprintf((stderr, " ok %s @ %s\n", "declaration", yy->__buf+yy->__pos)); yyDo(yy, yyPop, 2, 0); + return 1; + l45:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + yyprintf((stderr, " fail %s @ %s\n", "declaration", yy->__buf+yy->__pos)); + return 0; +} 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 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); +{ int yypos0= yy->__pos, yythunkpos0= yy->__thunkpos; + yyprintf((stderr, "%s\n", "start")); if (!yy_declaration(yy)) goto l46; + l47:; + { int yypos48= yy->__pos, yythunkpos48= yy->__thunkpos; if (!yy_declaration(yy)) goto l48; goto l47; + l48:; yy->__pos= yypos48; yy->__thunkpos= yythunkpos48; + } + yyprintf((stderr, " ok %s @ %s\n", "start", yy->__buf+yy->__pos)); return 1; - l39:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; + l46:; yy->__pos= yypos0; yy->__thunkpos= yythunkpos0; yyprintf((stderr, " fail %s @ %s\n", "start", yy->__buf+yy->__pos)); return 0; } @@ -908,18 +1143,12 @@ YY_PARSE(yycontext *) YYRELEASE(yycontext *yyctx) } #endif -#line 205 "parse.leg" +#line 359 "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) { @@ -989,6 +1218,10 @@ int execute(Node *node, InputBuffer *in) advance(in, 1); return 1; } + case Id: { + Symbol *symbol= get(node, Id, symbol); + return execute(symbol->rule, in); + } } printf("this cannot happen\n"); abort(); diff --git a/parse.leg b/parse.leg index 4c6ee4f..fb91ec1 100644 --- a/parse.leg +++ b/parse.leg @@ -5,10 +5,17 @@ #include #include "inputBuffer.c" ; -enum op { String, Query, Star, Plus, Or, And, Class, Dot, Exc } ; +enum op { String, Query, Star, Plus, Or, And, Class, Dot, Exc, Id } ; typedef union Node Node; +typedef struct Symbol Symbol; +typedef struct Array Array; +typedef struct SymbolTable SymbolTable; +struct Array { + Node **elements; + int length; +}; struct String { enum op type; char *string; int len; }; struct Query { enum op type; Node *children[1]; }; @@ -17,8 +24,9 @@ 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 Dot { enum op type; }; struct Exc { enum op type; Node *children[1]; }; +struct Id { enum op type; Symbol *symbol; }; union Node { enum op type; @@ -31,8 +39,30 @@ union Node { struct Class Class; struct Dot Dot; struct Exc Exc; + struct Id Id; +}; + +struct Symbol{ + char* name; + Node *rule; +}; + +struct SymbolTable { + Symbol **elements; + int length; }; +#define SymbolTable_initialiser {0,0} +SymbolTable symbolTable= SymbolTable_initialiser; + +Symbol *createSymbol(char *name) { + Symbol *symbol= calloc(1, sizeof(Symbol)); + symbol->name= strdup(name); + return symbol; +} + + + #define new(type) mkNode(sizeof(struct type),type) @@ -51,6 +81,15 @@ Node *mkString(char *s) return node; } +Node *mkId(char *s){ + + Node *node= new(Id); + node->Id.symbol=createSymbol(s); + return node; +} + + + Node *mkQuery(Node *n) { Node *node= new(Query); @@ -109,6 +148,16 @@ Node *mkExc(Node *n) return node; } +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) + void print(Node *node) { switch (node->type) { @@ -147,6 +196,9 @@ void print(Node *node) printf("!"); print(node->Exc.children[0]); return; + case Id: + printf("%s\n",get(node,Id,symbol)->name); + return; } abort(); } @@ -168,12 +220,110 @@ else { \ result=1; \ }} + + +void move(SymbolTable *symbolTable, int a) { + symbolTable->length++; + symbolTable->elements= realloc(symbolTable->elements,sizeof(Node*) * symbolTable->length); + printf("begin\n"); + for (int i= symbolTable->length-1; i >a; i--) { + symbolTable->elements[i] = symbolTable->elements[i-1]; + printf("\n"); + for(int i= 0; ilength; i++) { + printf("number : %i, name : %s, value : a\n",i, symbolTable->elements[i]->name); + } + } + printf("end\n"); +} + +void addSymbolSorted(SymbolTable *symbolTable, Symbol *symbol) { + int a=0; + int b= symbolTable->length-1; + int c; + //1 no infinite loop with a and c = 0 et b =1 + while (1 < b - a ) { + c= (a+b)/2; + if (strcmp(symbolTable->elements[c]->name, symbol->name) < 0) { + a= c; + } else { + b= c; + } + } + //b>-1 <=> symboleTable->length > 0 + // this if is here to know if we put the symbol before or after a + if (b>-1 && strcmp(symbolTable->elements[a]->name, symbol->name) < 0) { + a++; + } + //we move all the symbols after a + move(symbolTable, a); + //we put the symbol at the right place + symbolTable->elements[a]->name = symbol->name; +} + +int findSymbol(SymbolTable *symbolTable, char *name) { + for (int i= 0; i < symbolTable->length;i++) { + if (strcmp(symbolTable->elements[i]->name, name) == 0) { + return 1; + } + } + Symbol *symbol = createSymbol(name); + addSymbolSorted(symbolTable, symbol); + return 0; +} + +Node *findSymbolSorted(SymbolTable *symbolTable, char *name) { + int a=0; + int b= symbolTable->length-1; + int c; + //1 no infinite loop with a and c = 0 et b =1 + while (1 < b - a ) { + c= (a+b)/2; + if (strcmp(symbolTable->elements[c]->name, name) < 0) { + a= c; + } else { + if (strcmp(symbolTable->elements[c]->name, name) > 0) { + b= c; + } else { + return symbolTable->elements[c]->rule; + } + } + } + //b>-1 <=> symboleTable->length > 0 + // this if is here to know if we put the symbol before or after a + if (b>-1 && strcmp(symbolTable->elements[a]->name, name) < 0) { + a++; + } + //we move all the symbols after a + move(symbolTable, a); + //we put the symbol at the right place + symbolTable->elements[a]= createSymbol(name); + return 0; +} + +void setRule(SymbolTable *symbolTable, char *name, Node *rule) { + for (int i= 0; i < symbolTable->length;i++) { + if (strcmp(symbolTable->elements[i]->name, name) == 0) { + symbolTable->elements[i]->rule= rule; + break; + } + } +} + +void arrayAppend(Array *array, Node *statement) { + array->length++; + array->elements= realloc(array->elements,sizeof(Node*) * array->length); + array->elements[array->length-1] = statement; + } + + #define YYSTYPE Node * YYSTYPE yylval = 0; %} -start = - o:or { yylval = o } +start = declaration+ + +declaration = i:id '=' - e:expression { setRule(&symbolTable,get(i, Id, symbol)->name, e) } or = a:and - "|" - o:or {$$ = mkOr(o, a) } | a:and { $$ = a } @@ -189,7 +339,11 @@ postfix = s:atom ( "?" - { s = mkQuery(s) } | "+" - { s = mkPlus(s) } )? { $$ = s} -atom = string | class | dot +atom = string | class | dot | rule + +rule = i:id !'=' { $$ = mkId(yytext) } + +id = < [a-zA-z_][a-zA-z_0-9]* > - { $$ = mkId(yytext) } string = '"' < [^"]* > '"' { $$ = mkString(yytext) } - @@ -204,15 +358,9 @@ space = [ \t] | '\n' '\r'* | '\r' '\n'* %% -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) { @@ -282,6 +430,10 @@ int execute(Node *node, InputBuffer *in) advance(in, 1); return 1; } + case Id: { + Symbol *symbol= get(node, Id, symbol); + return execute(symbol->rule, in); + } } printf("this cannot happen\n"); abort();