Skip to content
Snippets Groups Projects
Commit ce5b2608 authored by JasonJPu's avatar JasonJPu
Browse files

Add more grammar stuff

parent f8af09ad
No related branches found
No related tags found
1 merge request!1SQLP parser with cons cells
...@@ -49,18 +49,14 @@ Identifier ...@@ -49,18 +49,14 @@ Identifier
Query Query
: Union_Query : Union_Query
{ printf("Union Query\n"); { printf("Union Query\n");
$$ = new_node(1, Query); $$ = $1;
$$->children[0] = $1;
} }
; ;
Select_Query Select_Query
: SELECT Select_List Body : SELECT Select_List Body
{ printf("SQLP Query\n"); { printf("SQLP Query\n");
$$ = new_node(3, Select_Query); $$ = create_proj_operator($1, $2);
$$->children[0] = new_node(0, SELECT);
$$->children[1] = $2;
$$->children[2] = $3;
} }
; ;
...@@ -108,15 +104,11 @@ TablePath ...@@ -108,15 +104,11 @@ TablePath
Union_Query Union_Query
: Select_Query : Select_Query
{ printf("union query 1\n"); { printf("union query 1\n");
$$ = new_node(1, Union_Query); $$ = $1;
$$->children[0] = $1;
} }
| Union_Query UNION Select_Query | Union_Query UNION Select_Query
{ printf("union query 2\n"); { printf("union query 2\n");
$$ = new_node(3, Union_Query); $$ = create_union_all_operator($1, $3)
$$->children[0] = $1;
$$->children[1] = new_node(0, UNION);
$$->children[2] = $3;
} }
; ;
...@@ -128,30 +120,22 @@ Select_List ...@@ -128,30 +120,22 @@ Select_List
} }
| AttrPath | AttrPath
{ printf("select list attr path\n"); { printf("select list attr path\n");
$$ = new_node(1, Select_List); $$ = create_assign_operator($1, $1, NULL);
$$->children[0] = $1;
} }
| AttrPath ',' Select_List | AttrPath ',' Select_List
{ printf("Select list\n"); { printf("Select list\n");
$$ = new_node(3, Select_List); $$ = create_assign_operator($1, $1, $2);
$$->children[0] = $1;
$$->children[1] = new_node(0, COMMA);
$$->children[2] = $3;
} }
; ;
AttrPath AttrPath
: Identifier : Identifier
{ printf("path id\n"); { printf("path id\n");
$$ = new_node(1, AttrPath); $$ = create_pf($1, NULL);
$$->children[0] = $1;
} }
| Identifier '.' AttrPath | Identifier '.' AttrPath
{ printf("Path Function\n"); { printf("Path Function\n");
$$ = new_node(3, AttrPath); $$ = create_pf($1, $2);
$$->children[0] = $1;
$$->children[1] = new_node(0, DOT);
$$->children[2] = $3;
} }
; ;
Operator Operator
......
...@@ -51,7 +51,7 @@ cons_cell* create_atom_operator(char* tab_name, char* var) { ...@@ -51,7 +51,7 @@ cons_cell* create_atom_operator(char* tab_name, char* var) {
} }
cons_cell* create_union_operator(cons_cell* ra1, cons_cell* ra2) { cons_cell* create_union_all_operator(cons_cell* ra1, cons_cell* ra2) {
cons_cell* ra2_cons = create_cons_cell(ra2, NULL); cons_cell* ra2_cons = create_cons_cell(ra2, NULL);
cons_cell* ra1_cons = create_cons_cell(ra1, ra2_cons); cons_cell* ra1_cons = create_cons_cell(ra1, ra2_cons);
char operator[9] = "UNION_ALL"; char operator[9] = "UNION_ALL";
...@@ -68,19 +68,17 @@ cons_cell* create_cross_operator(cons_cell* ra1, cons_cell* ra2) { ...@@ -68,19 +68,17 @@ cons_cell* create_cross_operator(cons_cell* ra1, cons_cell* ra2) {
} }
// For when you want to assign column names to another name // For when you want to assign column names to another name
cons_cell* create_assign_operator(char* col1, char* col2) { cons_cell* create_assign_operator(char* original, char* new_name, cons_cell* next) {
cons_cell* col2_cons = create_cons_cell_w_atom(col2, NULL); cons_cell* new_name_cons = create_cons_cell_w_atom(new_name, next);
cons_cell* col1_cons = create_cons_cell_w_atom(col1, col2_cons); cons_cell* original_cons = create_cons_cell_w_atom(original, new_name_cons);
char operator[2] = "AS"; char operator[2] = "AS";
cons_cell* operator_cons = create_cons_cell_w_atom(operator, col1_cons); cons_cell* operator_cons = create_cons_cell_w_atom(operator, original_cons);
return operator_cons; return operator_cons;
} }
cons_cell* create_proj_operator(cons_cell* assign1, cons_cell* assign2, cons_cell* ra) { cons_cell* create_proj_operator(cons_cell* assign, cons_cell* ra) {
cons_cell* ra_cons = create_cons_cell(ra, NULL); cons_cell* ra_cons = create_cons_cell(ra, NULL);
cons_cell* assign2_cons = create_cons_cell(assign2, NULL); cons_cell* assign_cons = create_cons_cell(assign, ra_cons);
cons_cell* assign1_cons = create_cons_cell(assign1, assign2_cons);
cons_cell* assign_cons = create_cons_cell(assign1_cons, ra_cons);
char operator[4] = "PROJ"; char operator[4] = "PROJ";
cons_cell* operator_cons = create_cons_cell_w_atom(operator, assign_cons); cons_cell* operator_cons = create_cons_cell_w_atom(operator, assign_cons);
return operator_cons; return operator_cons;
......
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