diff --git a/.vscode/ipch/3f948aff0d25318c/.parser.ipch.icloud b/.vscode/ipch/3f948aff0d25318c/.parser.ipch.icloud new file mode 100644 index 0000000000000000000000000000000000000000..a5cd22705c4c261114804c8daf67080dd056c898 Binary files /dev/null and b/.vscode/ipch/3f948aff0d25318c/.parser.ipch.icloud differ diff --git a/.vscode/ipch/3f948aff0d25318c/parser.ipch b/.vscode/ipch/3f948aff0d25318c/parser.ipch deleted file mode 100644 index d2961aa66ae401e224c9fef47380f3876c74ecfc..0000000000000000000000000000000000000000 Binary files a/.vscode/ipch/3f948aff0d25318c/parser.ipch and /dev/null differ diff --git a/SQLPGrammar_new.y b/SQLPGrammar_new.y index 041eb6de676e646b183a7a94149fa8edf514742f..324f7d1c9460f083fe3232a2c6be502dd2addd5c 100644 --- a/SQLPGrammar_new.y +++ b/SQLPGrammar_new.y @@ -34,30 +34,43 @@ SQLPProgram Query : UnionQuery { - printf("Union Query\n"); + printf("Query 1\n"); $$ = $1; } - | UnionQuery LIMIT Constant // todo: how to represent Constant in parse tree + | UnionQuery LIMIT INTEGER + { + printf("Query 2\n"); + $$ = create_limit_operator($1, $3); + } | SelectQuery { - printf("Select Query\n"); + printf("Query 3\n"); $$ = $1; } - | SelectQuery LIMIT Constant + | SelectQuery LIMIT INTEGER + { + printf("Query 4\n"); + $$ = create_limit_operator($1, $3); + } ; SelectQuery : SELECT SelectList Body { - printf("SQLP Query\n"); + printf("SelectQuery 1\n"); $$ = create_proj_operator($2, $3); } - | SELECT ELIM SelectList Body // todo: how to represent ELIM in parse tree + | SELECT ELIM SelectList Body + { + printf("SelectQuery 2\n"); + // todo: add ELIM + $$ = create_proj_operator($3, $4); + } ; -BodyContent // todo: create BodyContent since njoin does not apply to FROM +BodyContent // create BodyContent since njoin does not apply to FROM : TableList { printf("BodyContent 1\n"); diff --git a/util.c b/util.c index 78f038af5730e262b7055c3374538892c26c2514..b4f3f7faeac785727cf5a53acfc9eb8023ac3a4b 100644 --- a/util.c +++ b/util.c @@ -28,7 +28,6 @@ cons_cell* create_cons_cell_w_atom(char* val, cons_cell* cdr) { } cons_cell* create_spcol(cons_cell* var, cons_cell* pf) { - cons_cell* pf_cons = create_cons_cell(pf, NULL); cons_cell* var_cons = create_cons_cell(var, pf); char operator[6] = "SPCOL\0"; cons_cell* operator_cons = create_cons_cell_w_atom(operator, var_cons); @@ -84,6 +83,7 @@ cons_cell* create_op(char *op) { return create_cons_cell_w_atom(operator, op_cons); } +// todo: why need ra cons_cell* create_comp_operator(cons_cell* op, cons_cell* term1, cons_cell* term2, cons_cell* ra) { cons_cell* ra_cons = create_cons_cell(ra, NULL); cons_cell* term2_cons = create_cons_cell(term2, ra_cons); @@ -103,7 +103,7 @@ cons_cell* create_atom_operator(cons_cell* table, cons_cell* var) { return operator_cons; } - +// todo: why pass NULL cons_cell* create_union_all_operator(cons_cell* ra1, cons_cell* ra2) { cons_cell* ra2_cons = create_cons_cell(ra2, NULL); cons_cell* ra1_cons = create_cons_cell(ra1, ra2_cons); @@ -168,11 +168,13 @@ cons_cell* create_proj_operator(cons_cell* assign, cons_cell* ra) { return operator_cons; } -cons_cell* create_not_operator(cons_cell* ra1) { - cons_cell* ra1_cons = create_cons_cell(ra1, NULL); +// todo: ra2? +cons_cell* create_not_operator(cons_cell* ra1, cons_cell* ra2) { + cons_cell* ra2_cons = create_cons_cell(ra2, NULL); + cons_cell* ra1_cons = create_cons_cell(ra1, ra2_cons); char operator[4] = "NOT\0"; cons_cell* operator_cons = create_cons_cell_w_atom(operator, ra1_cons); - return create_cons_cell_w_atom(operator, ra1_cons); + return operator_cons; } cons_cell* create_exist_operator(cons_cell* ra1) { @@ -191,7 +193,7 @@ cons_cell* create_limit_operator(cons_cell* ra1, cons_cell* ra2) { return operator_cons; } -cons_cell* create_elim_operator(cons_cell* ra1, cons_cell* ra2) { +cons_cell* create_elim_operator(cons_cell* ra1) { cons_cell* ra1_cons = create_cons_cell(ra1, NULL); char operator[5] = "ELIM\0"; cons_cell* operator_cons = create_cons_cell_w_atom(operator, ra1_cons); diff --git a/util.h b/util.h index f70f3dfcacb17b5cd6677ff5fb1815130ff26adc..a32e998f84504a3873c016a3d1d81f0842ddfbfc 100644 --- a/util.h +++ b/util.h @@ -76,10 +76,10 @@ cons_cell* create_union_operator(cons_cell* ra1, cons_cell* ra2); cons_cell* create_cross_operator(cons_cell* ra1, cons_cell* ra2); cons_cell* create_rename_operator(cons_cell* table, cons_cell* var); cons_cell* create_proj_operator(cons_cell* assign, cons_cell* ra); -cons_cell* create_not_operator(cons_cell* ra1); +cons_cell* create_not_operator(cons_cell* ra1, cons_cell* ra2); cons_cell* create_exist_operator(cons_cell* ra1); cons_cell* create_limit_operator(cons_cell* ra1, cons_cell* ra2); -cons_cell* create_elim_operator(cons_cell* ra1, cons_cell* ra2); +cons_cell* create_elim_operator(cons_cell* ra1); cons_cell* create_eval_operator(cons_cell* logic, cons_cell* cross); // Prints an in order traversal of the tree