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
b2bb5ec4
Commit
b2bb5ec4
authored
4 years ago
by
Tony Zhang
Browse files
Options
Downloads
Patches
Plain Diff
Fix Query Parser
parent
cfbb3e6e
No related branches found
No related tags found
1 merge request
!6
Rewrite Parsers for SQLP Query, Schema, and Referring Type Expression
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
SQLPGrammar.y
+77
-69
77 additions, 69 deletions
SQLPGrammar.y
util.c
+6
-0
6 additions, 0 deletions
util.c
util.h
+2
-0
2 additions, 0 deletions
util.h
with
85 additions
and
69 deletions
SQLPGrammar.y
+
77
−
69
View file @
b2bb5ec4
...
@@ -21,11 +21,14 @@
...
@@ -21,11 +21,14 @@
SQLPQuery
SQLPQuery
: Query
: Query
{
{
$$ = NULL;
create_constant("TEST", "10");
$$ = create_cons_cell_w_atom("SQLP_QUERY", create_cons_cell_w_atom("QUERY", $1));
print_cons_tree($$);
}
}
| Body
| Body
{
{
$$ = NULL;
$$ = create_cons_cell_w_atom("SQLP_QUERY", create_cons_cell_w_atom("BODY", $1));
print_cons_tree($$);
};
};
Query
Query
...
@@ -41,85 +44,85 @@ Query
...
@@ -41,85 +44,85 @@ Query
Body
Body
: Pred
: Pred
{
{
$$ =
NULL
;
$$ =
create_list("PRED", $1)
;
}
}
| Atom
| Atom
{
{
$$ =
NULL
;
$$ =
$1
;
}
}
| NaturalJoinList
| NaturalJoinList
{
{
$$ =
NULL
;
$$ =
create_list("NATURAL_JOIN", $1)
;
}
}
| SubQuery
| SubQuery
{
{
$$ =
NULL
;
$$ =
$1
;
};
};
Atom
Atom
: TableIdentifier VarIdentifier
: TableIdentifier VarIdentifier
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("ATOM", create_cons_cell($1, create_cons_cell($2,
NULL
)))
;
};
};
NaturalJoinList
NaturalJoinList
:
NaturalJoinList JOIN '(' Body ')'
:
'(' Body ')' JOIN NaturalJoinList
{
{
$$ =
NULL
;
$$ =
create_cons_cell($2, $5)
;
}
}
| '(' Body ')'
| '(' Body ')'
{
{
$$ = NULL;
$$ =
create_cons_cell($2,
NULL
)
;
};
};
SubQuery
SubQuery
: Query VarIdentifier
: Query VarIdentifier
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("SUB_QUERY", create_cons_cell($2,
NULL
))
;
};
};
Select
Select
: SELECT SetOrBag Limit AsList Body
: SELECT SetOrBag Limit AsList Body
{
{
$$ =
NULL
;
$$ =
create_cons_cell_w_atom("SELECT", create_cons_cell($2, create_cons_cell($3, create_cons_cell(create_list("AS", $4), create_cons_cell($5, NULL)))))
;
};
};
SetOrBag
SetOrBag
: DISTINCT
: DISTINCT
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("DISTINCT",
NULL
)
;
}
}
| ALL
| ALL
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("ALL",
NULL
)
;
}
}
| /* empty */
| /* empty */
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("ALL",
NULL
)
;
};
};
Limit
Limit
: LIMIT I
NTEGER
: LIMIT I
nteger
{
{
$$ =
NULL
;
$$ =
create_cons_cell_w_atom("LIMIT", $2)
;
}
}
| NOLIMIT
| NOLIMIT
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("NO_LIMIT",
NULL
)
;
}
}
| /* empty */
| /* empty */
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("NO_LIMIT",
NULL
)
;
};
};
AsList
AsList
: As
: As
{
{
$$ =
$1
;
$$ =
create_cons_cell($1, NULL)
;
}
}
| As
List
',' As
| As ',' As
List
{
{
$$ =
NULL
;
$$ =
create_cons_cell($1, $3)
;
};
};
As
As
...
@@ -129,116 +132,121 @@ As
...
@@ -129,116 +132,121 @@ As
}
}
| Col AS AttrIdentifier
| Col AS AttrIdentifier
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("AS", create_cons_cell($1, create_cons_cell($3,
NULL
)))
;
};
};
Union
Union
: UNION SetOrBag Limit QueryList
: UNION SetOrBag Limit QueryList
{
{
$$ =
NULL
;
$$ =
create_cons_cell_w_atom("UNION", create_cons_cell($2, create_cons_cell($3, create_cons_cell(create_list("QUERY", $4), NULL))))
;
};
};
QueryList
QueryList
: Query
List
'
,
' '
(
' Query
')'
:
'('
Query '
)
' '
,
' Query
List
{
{
$$ =
NULL
;
$$ =
create_cons_cell($2, $5)
;
}
}
| '(' Query ')'
| '(' Query ')'
{
{
$$ = NULL;
$$ =
create_cons_cell($2,
NULL
)
;
}
}
Col
Col
: VarIdentifier '.' AttributePath
: VarIdentifier '.' AttributePath
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("COL", create_cons_cell($1, create_cons_cell(create_list("ATTRIBUTE", $3),
NULL
)))
;
};
};
AttributePath
: AttrIdentifier
{
$$ = NULL;
};
| AttributePath '.' AttrIdentifier
{
$$ = NULL;
};
VarIdentifier
: IDENTIFIER
{
$$ = NULL;
};
TableIdentifier
: IDENTIFIER
{
$$ = NULL;
};
AttrIdentifier
: IDENTIFIER
{
$$ = NULL;
};
Pred
Pred
: Conj
: Conj
{
{
$$ = NULL;
$$ =
create_cons_cell(create_list("CONJ", $1),
NULL
)
;
}
}
| '(' Conj OR Pred ')'
| '(' Conj OR Pred ')'
{
{
$$ =
NULL
;
$$ =
create_cons_cell(create_list("CONJ", $2), $4)
;
};
};
Conj
Conj
: BasicPred
: BasicPred
{
{
$$ = NULL;
$$ =
create_cons_cell($1,
NULL
)
;
}
}
| '(' BasicPred AND Conj ')'
| '(' BasicPred AND Conj ')'
{
{
$$ =
NULL
;
$$ =
create_cons_cell($2, $4)
;
}
}
BasicPred
BasicPred
: Term '=' Term
: Term '=' Term
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("EQUAL", create_cons_cell($1, create_cons_cell($3,
NULL
)))
;
}
}
| Term '<' Term
| Term '<' Term
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("LT", create_cons_cell($1, create_cons_cell($3,
NULL
)))
;
}
}
| Term LE Term
| Term LE Term
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("LE", create_cons_cell($1, create_cons_cell($3,
NULL
)))
;
}
}
| EXISTS Body
| EXISTS Body
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("EXISTS", create_cons_cell($2,
NULL
))
;
}
}
| NOT Pred
| NOT Pred
{
{
$$ = NULL;
$$ =
create_cons_cell_w_atom("NOT", create_cons_cell($2,
NULL
))
;
};
};
Term
Term
: INTEGER
: INTEGER
{
{
$$ =
NULL
;
$$ =
create_constant("INTEGER", constant)
;
}
}
| REAL
| REAL
{
{
$$ =
NULL
;
$$ =
create_constant("REAL", constant)
;
}
}
| STRING
| STRING
{
{
$$ =
NULL
;
$$ =
create_constant("STRING", constant)
;
}
}
| Col
| Col
{
{
$$ = $1;
$$ = $1;
};
};
AttributePath
: AttrIdentifier
{
$$ = create_cons_cell($1, NULL);
};
| AttrIdentifier '.' AttributePath
{
$$ = create_cons_cell($1, $3);
};
VarIdentifier
: IDENTIFIER
{
$$ = create_identifier("VAR", identifier);
};
TableIdentifier
: IDENTIFIER
{
$$ = create_identifier("TABLE", identifier);
};
AttrIdentifier
: IDENTIFIER
{
$$ = create_identifier("ATTR", identifier);
};
Integer
: INTEGER
{
$$ = create_constant("INTEGER", constant);
};
This diff is collapsed.
Click to expand it.
util.c
+
6
−
0
View file @
b2bb5ec4
...
@@ -47,6 +47,12 @@ cons_cell* create_identifier(char *type, char *identifier) {
...
@@ -47,6 +47,12 @@ cons_cell* create_identifier(char *type, char *identifier) {
return
create_cons_cell_w_atom
(
str
,
cc
);
return
create_cons_cell_w_atom
(
str
,
cc
);
}
}
cons_cell
*
create_constant
(
char
*
type
,
char
*
val
)
{
printf
(
"create_constant: %s, %s
\n
"
,
type
,
val
);
cons_cell
*
cc
=
create_cons_cell_w_atom
(
val
,
NULL
);
return
create_cons_cell_w_atom
(
type
,
cc
);
}
cons_cell
*
create_list
(
char
*
type
,
cons_cell
*
list
)
{
cons_cell
*
create_list
(
char
*
type
,
cons_cell
*
list
)
{
printf
(
"create_list: %s
\n
"
,
type
);
printf
(
"create_list: %s
\n
"
,
type
);
char
str
[
100
];
char
str
[
100
];
...
...
This diff is collapsed.
Click to expand it.
util.h
+
2
−
0
View file @
b2bb5ec4
...
@@ -35,6 +35,8 @@ cons_cell * cdr(cons_cell * cc);
...
@@ -35,6 +35,8 @@ cons_cell * cdr(cons_cell * cc);
cons_cell
*
create_identifier
(
char
*
type
,
char
*
identifier
);
cons_cell
*
create_identifier
(
char
*
type
,
char
*
identifier
);
cons_cell
*
create_constant
(
char
*
type
,
char
*
val
);
cons_cell
*
create_list
(
char
*
type
,
cons_cell
*
list
);
cons_cell
*
create_list
(
char
*
type
,
cons_cell
*
list
);
void
print_cons_tree
(
cons_cell
*
cc
);
void
print_cons_tree
(
cons_cell
*
cc
);
...
...
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