Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LDI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Grant Weddell
LDI
Commits
ce5b2608
Commit
ce5b2608
authored
6 years ago
by
JasonJPu
Browse files
Options
Downloads
Patches
Plain Diff
Add more grammar stuff
parent
f8af09ad
No related branches found
No related tags found
1 merge request
!1
SQLP parser with cons cells
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
SQLPGrammer2.y
+8
-24
8 additions, 24 deletions
SQLPGrammer2.y
util.c
+7
-9
7 additions, 9 deletions
util.c
with
15 additions
and
33 deletions
SQLPGrammer2.y
+
8
−
24
View file @
ce5b2608
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
util.c
+
7
−
9
View file @
ce5b2608
...
@@ -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
*
assign
1
,
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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment