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

fix compile error

todo: fix conflict rule
parent 224cdc37
No related branches found
No related tags found
No related merge requests found
.PHONY: all clean
#CFLAGS = `pkg-config --cflags glib-2.0`
#LDLIBS = `pkg-config --libs glib-2.0`
all: SQLPParser Parser
all: SQLPParser Parser SQLPParser_new
SQLPParser: SQLPParser.c SQLPGrammar.y SQLPScanner.l util.o
bison --verbose -d SQLPGrammar.y
......@@ -9,11 +9,11 @@ SQLPParser: SQLPParser.c SQLPGrammar.y SQLPScanner.l util.o
gcc -w SQLPParser.c util.o -o SQLPParser
rm -f lex.yy.c SQLPGrammar.tab.c SQLPGrammar.tab.h
SQLPParser_new: SQLPParser.c SQLPGrammar_new.y SQLPScanner.l util.o
SQLPParser_new: SQLPParser_new.c SQLPGrammar_new.y SQLPScanner_new.l util.o
bison --verbose -d SQLPGrammar_new.y
flex SQLPScanner_new.l
gcc -w SQLPParser.c util.o -o SQLPParser_new
# rm -f lex.yy.c SQLPGrammar.tab.c SQLPGrammar.tab.h
gcc -w SQLPParser_new.c util.o -o SQLPParser_new
rm -f lex.yy.c SQLPGrammar.tab.c SQLPGrammar.tab.h
util.o: util.c util.h
gcc -c util.c
......
No preview for this file type
This diff is collapsed.
This diff is collapsed.
......@@ -30,8 +30,8 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_YY_SQLPGRAMMAR_TAB_H_INCLUDED
# define YY_YY_SQLPGRAMMAR_TAB_H_INCLUDED
#ifndef YY_YY_SQLPGRAMMAR_NEW_TAB_H_INCLUDED
# define YY_YY_SQLPGRAMMAR_NEW_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
......@@ -128,7 +128,11 @@ extern int yydebug;
DELETE = 338,
DECLARE = 339,
RETURN = 340,
UNION = 341
UNION = 341,
UNIONALL = 342,
ELIM = 343,
LIMIT = 344,
NJOIN = 345
};
#endif
......@@ -144,4 +148,4 @@ extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_SQLPGRAMMAR_TAB_H_INCLUDED */
#endif /* !YY_YY_SQLPGRAMMAR_NEW_TAB_H_INCLUDED */
......@@ -17,7 +17,8 @@
%token ON DETERMINED COVER QUERY GIVEN FROM SELECT WHERE ORDER
%token PRECOMPUTED ONE EXIST FOR ALL TRANSACTION INTCLASS STRCLASS
%token INTEGER REAL DOUBLEREAL STRING MAXLEN RANGE TO
%token INSERT END CHANGE DELETE DECLARE RETURN UNION
%token INSERT END CHANGE DELETE DECLARE RETURN UNION UNIONALL
%token ELIM LIMIT NJOIN
%start SQLPProgram
%%
......@@ -34,34 +35,47 @@ SQLPProgram
Query
: UnionQuery
{
printf("Union Query\n");
printf("Query 1\n");
$$ = $1;
}
| UnionQuery LIMIT Constant // todo: how to represent Constant in parse tree
| UnionQuery LIMIT INTEGER
{
printf("Query 2\n");
$$ = create_limit_operator($1, $3);
}
| SelectQuery
{
printf("Select Query\n");
printf("Query 3\n");
$$ = $1;
}
| SelectQuery LIMIT Constant
| SelectQuery LIMIT INTEGER
{
printf("Query 4\n");
$$ = create_limit_operator($1, $3);
}
;
SelectQuery
: SELECT SelectList Body
{
printf("SQLP Query\n");
printf("SelectQuery 1\n");
$$ = create_proj_operator($2, $3);
}
| SELECT ELIM SelectList Body // todo: how to represent ELIM in parse tree
| SELECT ELIM SelectList Body
{
printf("SelectQuery 2\n");
// todo: add ELIM
$$ = create_proj_operator($3, $4);
}
;
BodyContent // todo: create BodyContent since njoin does not apply to FROM
BodyContent // create BodyContent since njoin does not apply to FROM
: TableList
{
printf("BodyContent 1\n");
$$ = $1
$$ = $1;
}
| TableList WHERE Pred
{
......@@ -71,20 +85,20 @@ BodyContent // todo: create BodyContent since njoin does not apply to FROM
| '(' TableList ')' NJOIN BodyContent
{
printf("BodyContent 3\n");
$$ = create_njoin_operator($1, $3)
$$ = create_njoin_operator($1, $3);
}
| '(' TableList WHERE Pred ')' NJOIN BodyContent
{
printf("BodyContent 3\n");
$$ = create_njoin_operator(create_eval_operator($4, $2), $6)
$$ = create_njoin_operator(create_eval_operator($4, $2), $6);
}
Body
: FROM BodyContent
{
printf("Body \n")
$$ = $2
printf("Body \n");
$$ = $2;
}
;
......@@ -92,7 +106,7 @@ TableList
: TableIdentifier VarIdentifier
{
printf("TableList 1\n");
$$ = create_rename_operator($1, $2);s
$$ = create_rename_operator($1, $2);
}
| TableIdentifier VarIdentifier ',' TableList // keep right-recursive
{
......@@ -113,10 +127,10 @@ UnionQuery
printf("UnionQuery 2\n");
$$ = create_union_all_operator($2, $5);
}
: SelectQuery
| SelectQuery
{
printf("UnionQuery 3\n");
$$ = $1
$$ = $1;
}
;
......@@ -126,13 +140,13 @@ SelectList
printf("SelectList 2\n");
$$ = create_rename_operator($1, NULL);
}
| Col as AttrIdentifier // todo: create_as_operator
| Col AS AttrIdentifier // todo: create_as_operator
| Col ',' SelectList
{
printf("SelectList 4\n");
$$ = create_rename_operator($1, $2);
}
| Col as AttrIdentifier ',' SelectList
| Col AS AttrIdentifier ',' SelectList
;
Col
......@@ -213,12 +227,12 @@ Pred
: Conj
{
printf("Pred 1\n");
$$ = $1
$$ = $1;
}
| Pred OR Conj
{
printf("Pred 2 \n");
$$ = create_or_operator($1, $3)
$$ = create_or_operator($1, $3);
}
......@@ -226,7 +240,7 @@ Conj
: BasicPred
{
printf("Conj 1 \n");
$$ = $1
$$ = $1;
}
| BasicPred AND Conj
{
......@@ -250,24 +264,24 @@ BasicPred
| NOT BasicPred
{
printf("BasicPred 3 \n");
$$ = create_not_operator($2);
$$ = create_not_operator($2, NULL);
}
| '(' Pred ')'
{
printf("BasicPred 4\n");
$$ = $1
$$ = $1;
}
Term
: Constant
{
printf("Term 1\n");
$$ = create_constant($1)
$$ = create_constant($1);
}
| Col
{
printf("Term 2\n");
$$ = create_col($1)
$$ = create_col($1);
}
......
No preview for this file type
No preview for this file type
/*
* Copyright (C) 1989, G. E. Weddell.
*
* This file is part of RDM.
*
* RDM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RDM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RDM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "util.h"
#include "lex.yy.c"
#include "SQLPGrammar_new.tab.c"
int main()
{
int Result;
strcpy(LineBuffer, "");
printf("(\n");
Result = yyparse();
if (Result)
printf("**error**");
else
fprintf(stderr, "checking semantics.\n");
printf(")\n");
return (Result);
}
......@@ -51,6 +51,7 @@ E [Ee][+-]?{D}+
"delete" { strcat(LineBuffer, yytext); return(DELETE); }
"desc" { strcat(LineBuffer, yytext); return(DESC); }
"union" { strcat(LineBuffer, yytext); return(UNION); }
"unionall" { strcat(LineBuffer, yytext); return(UNIONALL); }
"determined" { strcat(LineBuffer, yytext); return(DETERMINED); }
"distributed" { strcat(LineBuffer, yytext); return(DISTRIBUTED); }
"dynamic" { strcat(LineBuffer, yytext); return(DYNAMIC); }
......@@ -61,6 +62,7 @@ E [Ee][+-]?{D}+
"from" { strcat(LineBuffer, yytext); return(FROM); }
"given" { strcat(LineBuffer, yytext); return(GIVEN); }
"has" { strcat(LineBuffer, yytext); return(HAS); }
"njoin" { strcat(LineBuffer, yytext); return(NJOIN); }
"implies" { strcat(LineBuffer, yytext); return(IMPLIES); }
"index" { strcat(LineBuffer, yytext); return(INDEX); }
"insert" { strcat(LineBuffer, yytext); return(INSERT); }
......
This diff is collapsed.
......@@ -28,7 +28,6 @@ cons_cell* create_cons_cell_w_atom(char* val, cons_cell* cdr) {
}
cons_cell* create_spcol(cons_cell* var, cons_cell* pf) {
cons_cell* pf_cons = create_cons_cell(pf, NULL);
cons_cell* var_cons = create_cons_cell(var, pf);
char operator[6] = "SPCOL\0";
cons_cell* operator_cons = create_cons_cell_w_atom(operator, var_cons);
......@@ -84,6 +83,7 @@ cons_cell* create_op(char *op) {
return create_cons_cell_w_atom(operator, op_cons);
}
// todo: why need ra
cons_cell* create_comp_operator(cons_cell* op, cons_cell* term1, cons_cell* term2, cons_cell* ra) {
cons_cell* ra_cons = create_cons_cell(ra, NULL);
cons_cell* term2_cons = create_cons_cell(term2, ra_cons);
......@@ -103,7 +103,7 @@ cons_cell* create_atom_operator(cons_cell* table, cons_cell* var) {
return operator_cons;
}
// todo: why pass NULL
cons_cell* create_union_all_operator(cons_cell* ra1, cons_cell* ra2) {
cons_cell* ra2_cons = create_cons_cell(ra2, NULL);
cons_cell* ra1_cons = create_cons_cell(ra1, ra2_cons);
......@@ -168,11 +168,13 @@ cons_cell* create_proj_operator(cons_cell* assign, cons_cell* ra) {
return operator_cons;
}
cons_cell* create_not_operator(cons_cell* ra1) { // todo: why do we need the second param ra2?
cons_cell* ra1_cons = create_cons_cell(ra1, NULL);
// todo: ra2?
cons_cell* create_not_operator(cons_cell* ra1, cons_cell* ra2) {
cons_cell* ra2_cons = create_cons_cell(ra2, NULL);
cons_cell* ra1_cons = create_cons_cell(ra1, ra2_cons);
char operator[4] = "NOT\0";
cons_cell* operator_cons = create_cons_cell_w_atom(operator, ra1_cons);
return create_cons_cell_w_atom(operator, ra1_cons);
return operator_cons;
}
cons_cell* create_exist_operator(cons_cell* ra1) {
......@@ -191,7 +193,7 @@ cons_cell* create_limit_operator(cons_cell* ra1, cons_cell* ra2) {
return operator_cons;
}
cons_cell* create_elim_operator(cons_cell* ra1, cons_cell* ra2) {
cons_cell* create_elim_operator(cons_cell* ra1) {
cons_cell* ra1_cons = create_cons_cell(ra1, NULL);
char operator[5] = "ELIM\0";
cons_cell* operator_cons = create_cons_cell_w_atom(operator, ra1_cons);
......
......@@ -76,10 +76,10 @@ cons_cell* create_union_operator(cons_cell* ra1, cons_cell* ra2);
cons_cell* create_cross_operator(cons_cell* ra1, cons_cell* ra2);
cons_cell* create_rename_operator(cons_cell* table, cons_cell* var);
cons_cell* create_proj_operator(cons_cell* assign, cons_cell* ra);
cons_cell* create_not_operator(cons_cell* ra1);
cons_cell* create_not_operator(cons_cell* ra1, cons_cell* ra2);
cons_cell* create_exist_operator(cons_cell* ra1);
cons_cell* create_limit_operator(cons_cell* ra1, cons_cell* ra2);
cons_cell* create_elim_operator(cons_cell* ra1, cons_cell* ra2);
cons_cell* create_elim_operator(cons_cell* ra1);
cons_cell* create_eval_operator(cons_cell* logic, cons_cell* cross);
// Prints an in order traversal of the tree
......
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