diff --git a/SQLPGrammar_new.y b/SQLPGrammar_new.y index 324f7d1c9460f083fe3232a2c6be502dd2addd5c..919f0a413e8b4f647dcbf8841e330c9f973fd3e1 100644 --- a/SQLPGrammar_new.y +++ b/SQLPGrammar_new.y @@ -17,7 +17,8 @@ %token ON DETERMINED COVER QUERY GIVEN FROM SELECT WHERE ORDER %token PRECOMPUTED ONE EXIST FOR ALL TRANSACTION INTCLASS STRCLASS %token INTEGER REAL DOUBLEREAL STRING MAXLEN RANGE TO -%token INSERT END CHANGE DELETE DECLARE RETURN UNION +%token INSERT END CHANGE DELETE DECLARE RETURN UNION UNIONALL +%token ELIM LIMIT NJOIN %start SQLPProgram %% @@ -74,7 +75,7 @@ BodyContent // create BodyContent since njoin does not apply to FROM : TableList { printf("BodyContent 1\n"); - $$ = $1 + $$ = $1; } | TableList WHERE Pred { @@ -84,20 +85,20 @@ BodyContent // create BodyContent since njoin does not apply to FROM | '(' TableList ')' NJOIN BodyContent { printf("BodyContent 3\n"); - $$ = create_njoin_operator($1, $3) + $$ = create_njoin_operator($1, $3); } | '(' TableList WHERE Pred ')' NJOIN BodyContent { printf("BodyContent 3\n"); - $$ = create_njoin_operator(create_eval_operator($4, $2), $6) + $$ = create_njoin_operator(create_eval_operator($4, $2), $6); } Body : FROM BodyContent { - printf("Body \n") - $$ = $2 + printf("Body \n"); + $$ = $2; } ; @@ -105,7 +106,7 @@ TableList : TableIdentifier VarIdentifier { printf("TableList 1\n"); - $$ = create_rename_operator($1, $2);s + $$ = create_rename_operator($1, $2); } | TableIdentifier VarIdentifier ',' TableList // keep right-recursive { @@ -126,10 +127,10 @@ UnionQuery printf("UnionQuery 2\n"); $$ = create_union_all_operator($2, $5); } - : SelectQuery + | SelectQuery { printf("UnionQuery 3\n"); - $$ = $1 + $$ = $1; } ; @@ -139,13 +140,13 @@ SelectList printf("SelectList 2\n"); $$ = create_rename_operator($1, NULL); } - | Col as AttrIdentifier // todo: create_as_operator + | Col AS AttrIdentifier // todo: create_as_operator | Col ',' SelectList { printf("SelectList 4\n"); $$ = create_rename_operator($1, $2); } - | Col as AttrIdentifier ',' SelectList + | Col AS AttrIdentifier ',' SelectList ; Col @@ -226,12 +227,12 @@ Pred : Conj { printf("Pred 1\n"); - $$ = $1 + $$ = $1; } | Pred OR Conj { printf("Pred 2 \n"); - $$ = create_or_operator($1, $3) + $$ = create_or_operator($1, $3); } @@ -239,7 +240,7 @@ Conj : BasicPred { printf("Conj 1 \n"); - $$ = $1 + $$ = $1; } | BasicPred AND Conj { @@ -263,24 +264,24 @@ BasicPred | NOT BasicPred { printf("BasicPred 3 \n"); - $$ = create_not_operator($2); + $$ = create_not_operator($2, NULL); } | '(' Pred ')' { printf("BasicPred 4\n"); - $$ = $1 + $$ = $1; } Term : Constant { printf("Term 1\n"); - $$ = create_constant($1) + $$ = $1; } | Col { printf("Term 2\n"); - $$ = create_col($1) + $$ = $1; } diff --git a/SQLPParser_new.c b/SQLPParser_new.c new file mode 100644 index 0000000000000000000000000000000000000000..4ff41171eab3ba11d1092b4da29af67211725d23 --- /dev/null +++ b/SQLPParser_new.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 1989, G. E. Weddell. + * + * This file is part of RDM. + * + * RDM 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 3 of the License, or + * (at your option) any later version. + * + * RDM 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 RDM. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdio.h> +#include "util.h" +#include "lex.yy.c" +#include "SQLPGrammar_new.tab.c" + +int main() +{ + int Result; + strcpy(LineBuffer, ""); + printf("(\n"); + Result = yyparse(); + if (Result) + printf("**error**"); + else + fprintf(stderr, "checking semantics.\n"); + printf(")\n"); + return (Result); +} diff --git a/SQLPScanner_new.l b/SQLPScanner_new.l index 1d6ae18acd391c7fe1a9b13ed4e046a8876440b7..41a075c9813c29a5f57b57134f876206bd207d5b 100644 --- a/SQLPScanner_new.l +++ b/SQLPScanner_new.l @@ -51,6 +51,7 @@ E [Ee][+-]?{D}+ "delete" { strcat(LineBuffer, yytext); return(DELETE); } "desc" { strcat(LineBuffer, yytext); return(DESC); } "union" { strcat(LineBuffer, yytext); return(UNION); } +"unionall" { strcat(LineBuffer, yytext); return(UNIONALL); } "determined" { strcat(LineBuffer, yytext); return(DETERMINED); } "distributed" { strcat(LineBuffer, yytext); return(DISTRIBUTED); } "dynamic" { strcat(LineBuffer, yytext); return(DYNAMIC); } @@ -61,6 +62,7 @@ E [Ee][+-]?{D}+ "from" { strcat(LineBuffer, yytext); return(FROM); } "given" { strcat(LineBuffer, yytext); return(GIVEN); } "has" { strcat(LineBuffer, yytext); return(HAS); } +"njoin" { strcat(LineBuffer, yytext); return(NJOIN); } "implies" { strcat(LineBuffer, yytext); return(IMPLIES); } "index" { strcat(LineBuffer, yytext); return(INDEX); } "insert" { strcat(LineBuffer, yytext); return(INSERT); }