/* ---- /Tools/TypeMap/OpSigParser.y ---- ---- This file is part of SECONDO. Copyright (C) 2014, Faculty of Mathematics and Computer Science, Database Systems for New Applications. SECONDO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. SECONDO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SECONDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ---- */ %{ /* Includes */ #include "OpSigParser.tab.h" #include #include #include #include #include #ifdef YYDEBUG #undef YYDEBUG #endif #define YYDEBUG 1 #ifdef YYERROR_VERBOSE #undef YYERROR_VERBOSE #endif #define YYERROR_VERBOSE 1 using namespace std; /* Some variables */ extern FILE* opsigin; //const char* infile = "../Tools/TypeMap/sigs"; //string outfile = "../Tools/TypeMap/OpSigs.tmp"; string outfile2 = "../Tools/TypeMap/OpSigsOpdPar.tmp"; string outfile3 = "../Tools/TypeMap/OpSigsArgs.tmp"; ofstream ofile; ofstream ofile2; ofstream ofile3; extern int opsiglex(); void opsigerror( const char* s ) { cerr << endl << s << endl << endl; } string varToLower(string varNameIn); vector opsigs; vector opsigs2; vector opsigs3; /* Type string is not possible in union */ string collectSig = ""; string collectSig2 = ""; string collectSiglist = ""; string collectSiglist2 = ""; string collectArgs = ""; string collectArgs2 = ""; string collectRes = ""; string collectPreds = ""; string collectSig3 = ""; string collectDecls = ""; string collectSiglist3 = ""; string collectEnum = ""; string collectArgs3 = ""; %} %union { const char* tokenchar; } /* use opsig instead of yy to avoid naming conflicts with other parsers of the system */ %name-prefix "opsig" %token ZZALG ZZWHERE ZZIN ZZPARAM ZZCROSSPRODUCT ZZFOLLOWS ZZSEMICOLON ZZERROR %token ZZATTR ZZATTRS ZZCOMBINE ZZCONCAT ZZDISTATTRS ZZMINUS ZZCREATEATTR ZZIDENT ZZSYMBOL ZZINTI %type opname type varname attrsindex varindex datatypes datatype /* ---- The output is specified as follows: = = (|) = | ; | . ---- */ %% start : signatures ; signatures : algsig | signatures algsig ; algsig : ZZALG ZZIDENT sigs { string str2 = $2; /* Output in outfile */ string algSigs = ""; int size = opsigs.size(); for(int i=0; i str(10); str[0] = $2; str[1] = $5; str[2] = $8; str[3] = $12; str[4] = $15; str[5] = $18; str[6] = $21; str[7] = $24; str[8] = $27; str[9] = $30; for(int i=0; i<10; i++) { if (str[i] == "Comma" ) { str[i] = ","; } if (str[i] == "Semicolon" ) { str[i] = ";"; } if (str[i] == "Space" ) { str[i] = " "; } if (str[i] == "Empty" ) { str[i] = ""; } } collectArgs = ""; collectArgs2 = ""; collectArgs3 = ""; collectArgs3 += "\"" + str[0] + str[1] + str[2] + "\" "; collectArgs3 += "\"" + str[3] + str[4] + str[5] + str[6]; collectArgs3 += str[7] + str[8] + str[9] +"\""; str.clear(); } ; resulttype : type {/* resOP: e.g. + */ string str1 = $1; collectRes = ""; collectRes += str1; } | type'('varname')' {/* resOP: e.g. feed/consume/filter */ string str1 = $1; string str3 = $3; string str32 = ""; str32 = varToLower(str3); collectRes = ""; collectRes += "(" + str1 + " "; collectRes += "(var " + str32 + " 1))"; } | '('varname',' varname')' {/* resOP: e.g. attr */ collectRes = ""; collectRes += "( append "; collectRes += "(var attrNo 1) (var attrType 1) )"; } | type'('type'('varname attrsindex')' ')' {/* resOP: e.g. hashjoin */ string str1 = $1; string str3 = $3; string str5 = $5; string str6 = $6; string str52 = ""; str52 = varToLower(str5); collectRes = ""; collectRes += "(" + str1 + " (" + str3 + " "; collectRes += "(var " + str52 + " " + str6 + ")))"; } | '('varname varindex',' type'('type'('varname attrsindex')' ')' ')' {/* resOP: e.g. project */ string str2 = $2; string str3 = $3; string str5 = $5; string str7 = $7; string str9 = $9; string str10 = $10; string str22 = ""; string str92 = ""; str22 = varToLower(str2); str92 = varToLower(str9); collectRes = ""; collectRes += "( append "; collectRes += "(var " + str22 + " " + str3 + ")\n "; collectRes += "(" + str5 + " (" + str7 + " "; collectRes += "(var " + str92 + " " + str10 + "))) )"; } ; condpreds : condpred | condpreds ',' condpred ; condpred : ZZATTR'('varname',' varname',' varname',' varname')' { /* Ident */ string str1 = $1; string str3 = $3; string str5 = $5; string str32 = ""; string str52 = ""; str32 = varToLower(str3); str52 = varToLower(str5); collectPreds += "(" + str1 + " "; collectPreds += "(var " + str32 + " 1) "; collectPreds += "(var " + str52 + " 1)\n "; collectPreds += "(var attrType 1) (var attrNo 1))\n "; } | ZZATTR'('varname varindex',' varname attrsindex',' varname varindex',' varname varindex')' { /* Ident_i */ string str1 = $1; string str3 = $3; string str4 = $4; string str6 = $6; string str7 = $7; string str10 = $10; string str13 = $13; string str32 = ""; string str62 = ""; str32 = varToLower(str3); str62 = varToLower(str6); collectPreds += "(" + str1 + " "; collectPreds += "(var " + str32 + " " + str4 + ") "; collectPreds += "(var " + str62 + " " + str7 + ")\n "; collectPreds += "(var attrType " + str10 + ") "; collectPreds += "(var attrNo " + str13 + "))\n "; } | ZZATTRS'('varname varindex',' varname attrsindex',' varname varindex',' varname varindex')' { string str1 = $1; string str3 = $3; string str4 = $4; string str6 = $6; string str7 = $7; string str9 = $9; string str10 = $10; string str12 = $12; string str13 = $13; string str32 = ""; string str62 = ""; string str92 = ""; string str122 = ""; str32 = varToLower(str3); str62 = varToLower(str6); str92 = varToLower(str9); str122 = varToLower(str12); collectPreds += "(" + str1 + " "; collectPreds += "(var " + str32 + " " + str4 + ") "; collectPreds += "(var " + str62 + " " + str7 + ")\n "; collectPreds += "(var " + str92 + " " + str10 + ") "; collectPreds += "(var " + str122 + " " + str13 + "))\n "; } | ZZCOMBINE'('varname',' varname',' varname attrsindex')' { /* Ident */ string str1 = $1; string str3 = $3; string str5 = $5; string str7 = $7; string str8 = $8; string str32 = ""; string str52 = ""; string str72 = ""; str32 = varToLower(str3); str52 = varToLower(str5); str72 = varToLower(str7); collectPreds += "(" + str1 + " "; collectPreds += "(var " + str32 + " 1) "; collectPreds += "(var " + str52 + " 1)\n "; collectPreds += "(var " + str72 + " " + str8 + "))\n "; } | ZZCOMBINE'('varname varindex',' varname varindex',' varname attrsindex')' { /* Ident_i */ string str1 = $1; string str3 = $3; string str4 = $4; string str6 = $6; string str7 = $7; string str9 = $9; string str10 = $10; string str32 = ""; string str62 = ""; string str92 = ""; str32 = varToLower(str3); str62 = varToLower(str6); str92 = varToLower(str9); collectPreds += "(" + str1 + " "; collectPreds += "(var " + str32 + " " + str4 + ") "; collectPreds += "(var " + str62 + " " + str7 + ")\n "; collectPreds += "(var " + str92 + " " + str10 + "))\n "; } | ZZCONCAT'('varname attrsindex',' varname attrsindex',' varname attrsindex')' { string str1 = $1; string str3 = $3; string str4 = $4; string str6 = $6; string str7 = $7; string str9 = $9; string str10 = $10; string str32 = ""; string str62 = ""; string str92 = ""; str32 = varToLower(str3); str62 = varToLower(str6); str92 = varToLower(str9); collectPreds += "(" + str1 + " "; collectPreds += "(var " + str32 + " " + str4 + ") "; collectPreds += "(var " + str62 + " " + str7 + ")\n "; collectPreds += "(var " + str92 + " " + str10 + "))\n "; } | ZZCREATEATTR'('varname varindex',' type'('type'('varname attrsindex')' ')' ',' varname attrsindex')' | ZZDISTATTRS'('varname attrsindex')' { string str1 = $1; string str3 = $3; string str4 = $4; string str32 = ""; str32 = varToLower(str3); collectPreds += "(" + str1 + " "; collectPreds += "(var " + str32 + " " + str4 + "))\n "; } | ZZMINUS'('varname attrsindex',' varname varindex',' varname attrsindex')' ; decls : ZZWHERE varname ZZIN '{'datatypes'}' { string str2 = $2; string str5 = $5; string str22 = ""; str22 = varToLower(str2); collectDecls = ""; collectDecls += "((var " + str22 + " 1) "; collectDecls += "(" + collectEnum + ")) "; } ; datatypes : datatype { string str1 = $1; collectEnum = ""; collectEnum += str1; } | datatypes datatype { string str2 = $2; collectEnum += " " + str2; } ; opname : ZZIDENT | ZZIDENT '_' ZZIDENT { /* for ops with '_' */ string str1 = $1; string str3 = $3; string strOp = str1 + "_" + str3; char* buffer = new char[strOp.length()]; strcpy(buffer, strOp.c_str()); $$ = buffer; } | ZZSYMBOL ; varname : ZZIDENT ; type : ZZIDENT ; attrsindex : '_'ZZINTI { $$ = $2; } ; varindex : '_'ZZINTI { $$ = $2; } | '_'ZZIDENT { $$ = $2; } ; datatype : type ',' | type ; semicolon : ZZSEMICOLON { collectPreds = ""; } %% /* Functions */ string varToLower(string varNameIn) { string varNameOut = ""; for (int i=0; i