Skip to content
Snippets Groups Projects
Commit b77996c2 authored by Wanxin Li's avatar Wanxin Li
Browse files

added create_as_operator

parent b82756ee
No related branches found
No related tags found
No related merge requests found
......@@ -52,25 +52,32 @@ Query
SelectQuery
: SELECT
: SELECT SelectList
| SELECT Body
{
printf("SelectQuery 1 \n");
$$ = $2;
}
| SELECT SelectList Body
| SELECT SelectList
{
printf("SelectQuery 2 \n");
$$ = create_rename_operator($2, NULL);
}
| SELECT Body
{
printf("SelectQuery 3 \n");
$$ = create_rename_operator($2, NULL);
}
| SELECT SelectList Body
{
printf("SelectQuery 4 \n");
$$ = create_proj_operator($2, $3);
}
| SELECT DISTINCT Body
{
printf("SelectList 3 \n");
$$ = $3;
printf("SelectList 5 \n");
$$ = create_rename_operator($3, NULL);
}
| SELECT DISTINCT SelectList Body
{
printf("SelectList 4 \n");
printf("SelectList 6 \n");
$$ = create_proj_operator($2, $3);
}
;
......@@ -79,12 +86,13 @@ Body
: FROM TableList
{
printf("Body 1 \n");
$$ = $2;
$$ = create_rename_operator($2, NULL);
}
| FROM WHERE Pred
{
printf("Body 2 \n");
// todo
$$ = create_rename_operator($3, NULL);
}
| FROM TableList WHERE Pred
{
......@@ -99,7 +107,7 @@ TableList
printf("TableList 1\n");
$$ = create_rename_operator($1, $2);
}
| TableIdentifier VarIdentifier ',' TableList // keep right-recursive
| TableIdentifier VarIdentifier ',' TableList
{
printf("TableList 2\n");
$$ = create_cross_operator(create_rename_operator($1, $2), $4);
......@@ -108,7 +116,6 @@ TableList
UnionQuery
: '(' SelectQuery ')' UNION UnionQuery
{
printf("UnionQuery 1\n");
......@@ -122,23 +129,31 @@ UnionQuery
| '(' SelectQuery ')'
{
printf("UnionQuery 3\n");
$$ = $1;
$$ = create_rename_operator($1, NULL);
}
;
SelectList
: Col
{
printf("SelectList 2\n");
printf("SelectList 1\n");
$$ = create_rename_operator($1, NULL);
}
| Col AS AttrIdentifier // todo: create_as_operator
| Col AS AttrIdentifier
{
printf("SelectList 2\n");
$$ = create_as_operator($1, $3);
}
| Col ',' SelectList
{
printf("SelectList 4\n");
printf("SelectList 3\n");
$$ = create_rename_operator($1, $2);
}
| Col AS AttrIdentifier ',' SelectList
{
printf("SelectList 4\n");
$$ = create_rename_operator($1, create_as_operator($3, $5));
}
;
Col
......@@ -238,7 +253,6 @@ Conj
{
printf("Conj 2 \n");
$$ = create_and_operator($1, $3);
// $$ = create_not_operator($3);
}
BasicPred
......
......@@ -212,6 +212,13 @@ cons_cell* create_eval_operator(cons_cell* logic, cons_cell* cross) {
return create_cons_cell_w_atom(operator, var_cons);
}
cons_cell* create_as_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[3] = "AS\0";
return create_cons_cell_w_atom(operator, ra1_cons);
}
void print_cons_tree(cons_cell *root) {
print_cons_tree_helper(root, 0);
}
......
......@@ -83,6 +83,7 @@ cons_cell* create_elim_operator(cons_cell* ra1);
cons_cell* create_eval_operator(cons_cell* logic, cons_cell* cross);
cons_cell* create_and_operator(cons_cell* ra1, cons_cell* ra2);
cons_cell* create_or_operator(cons_cell* ra1, cons_cell* ra2);
cons_cell* create_as_operator(cons_cell* ra1, cons_cell* ra2);
// Prints an in order traversal of the tree
void print_cons_tree(cons_cell *root);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment