Skip to content
Snippets Groups Projects
Commit 71c7f977 authored by w328li's avatar w328li
Browse files

changed grammar rules according to June 12 discussion

todo: build parse tree
parent 1a732a2c
No related branches found
No related tags found
No related merge requests found
......@@ -30,8 +30,8 @@ SQLPProgram
{
printf("Input Query\n");
cons_cell *n = $1;
printf("Printing Tree\n");
print_cons_tree(n);
printf("Printing Tree\n");
print_cons_tree(n);
}
;
......@@ -41,11 +41,13 @@ Query
printf("Union Query\n");
$$ = $1;
}
| Union_Query Limit Constant // todo: limit by or limit?
| Select_Query
{
printf("Select Query\n");
$$ = $1;
}
| Select_Query Limit Constant
;
Select_Query
......@@ -54,6 +56,7 @@ Select_Query
printf("SQLP Query\n");
$$ = create_proj_operator($2, $3);
}
| SELECT ELIM Select_List Body
;
Elim
......@@ -67,46 +70,44 @@ Limit
;
Body
: FROM TablePath
: FROM TableList
{
printf("Body 1\n");
$$ = $2;
}
| FROM TablePath WHERE Pred
| FROM TableList WHERE Pred
{
printf("Body 2\n");
$$ = create_eval_operator($4, $2);
}
;
TablePath
TableList
: TableIdentifier VarIdentifier
{
printf("Table path 1\n");
printf("TableList 1\n");
$$ = create_rename_operator($1, $2);
}
| TableIdentifier VarIdentifier ',' TablePath
| TableIdentifier VarIdentifier ',' TableList // keep right-recursive
{
printf("Table path 2\n");
printf("TableList 2\n");
$$ = create_cross_operator(create_rename_operator($1, $2), $4);
}
;
Union_Query
: Union_Query UNION Select_Query
: '(' Select_Query ')' UNION Union_Query
{
printf("Union query\n");
$$ = create_union_all_operator($1, $3);
$$ = create_union_all_operator($1, $3); // todo: create_union_operator
}
| '(' Select_Query ')' UNIONALL Union_Query
: Select_Query
;
Select_List
: STAR
{
printf("Select_List 1\n");
$$ = create_atom("STAR");
}
| Col
: Col
{
printf("Select_List 2\n");
$$ = create_rename_operator($1, NULL);
......@@ -161,7 +162,7 @@ AttrIdentifier
$$ = create_var(yytext);
}
Operator
CompOperator
: EQ
{
printf("Operator EQ\n");
......@@ -195,62 +196,23 @@ Operator
;
Pred
: Col Operator Col
{
printf("Pred 1\n");
cons_cell* first_term = create_term($1);
cons_cell* second_term = create_term($3);
$$ = create_comp_operator($2, first_term, second_term, NULL);
}
| Col Operator Constant
{
printf("Pred 2\n");
cons_cell* first_term = create_term($1);
$$ = create_comp_operator($2, first_term, $3, NULL);
}
| Pred AND Col Operator Col
{
printf("Pred 3\n");
cons_cell* first_term = create_term($1);
cons_cell* second_term = create_term($3);
comp_cons = create_comp_operator($2, first_term, second_term, NULL);
$$ = create_and_operator($1, comp_cons);
}
| Pred AND Col Operator Constant
{
printf("Pred 4\n");
cons_cell* first_term = create_term($1);
cons_cell* second_term = create_term($3);
comp_cons = create_comp_operator($2, first_term, $3, NULL);
$$ = create_and_operator($1, comp_cons);
}
| Pred OR Col Operator Col
{
printf("Pred 5\n");
cons_cell* first_term = create_term($1);
cons_cell* second_term = create_term($3);
comp_cons = create_comp_operator($2, first_term, second_term, NULL);
$$ = create_or_operator($1, comp_cons);
}
| Pred OR Col Operator Constant
{
printf("Pred 6\n");
cons_cell* first_term = create_term($1);
cons_cell* second_term = create_term($3);
comp_cons = create_comp_operator($2, first_term, $3, NULL);
$$ = create_or_operator($1, comp_cons);
}
| NOT Pred
{
printf("Pred 7\n");
$$ = create_not_operator($1, NULL);
}
| EXIST '(' SELECT STAR Body ')'
{
printf("Pred 8\n")
// todo: create exist operator?
}
;
: Conj
| Pred OR Conj
| BasicPred
| Conj AND BasicPred
BasicPred
: Term CompOperator Term
| EXIST '(' Body ')'
| NOT BasicPred
| '(' Pred ')'
Term
: Constant
| TableList
Constant
: INTEGER
......@@ -268,3 +230,5 @@ Constant
printf("STRING is |%s|", yytext);
$$ = create_constant(yytext);
}
;
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