Skip to content
Snippets Groups Projects
Commit b2bb5ec4 authored by Tony Zhang's avatar Tony Zhang
Browse files

Fix Query Parser

parent cfbb3e6e
No related branches found
No related tags found
1 merge request!6Rewrite Parsers for SQLP Query, Schema, and Referring Type Expression
...@@ -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 INTEGER : LIMIT Integer
{ {
$$ = 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);
} }
| AsList ',' As | As ',' AsList
{ {
$$ = 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
: QueryList ',' '(' Query ')' : '(' Query ')' ',' QueryList
{ {
$$ = 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);
};
...@@ -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];
......
...@@ -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);
......
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