Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ehfeng/LDI
  • w328li/LDI
  • gweddell/LDI
3 results
Show changes
Commits on Source (30)
Showing
with 320 additions and 2393 deletions
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
.PHONY: all clean
#CFLAGS = `pkg-config --cflags glib-2.0`
#LDLIBS = `pkg-config --libs glib-2.0`
all: SQLPParser_new
all: SQLPSchema SQLPParser SQLPRefExp
SQLPParser: SQLPParser.c SQLPGrammar.y SQLPScanner.l util.o
bison --verbose -d SQLPGrammar.y
flex SQLPScanner.l
flex -D SQLPGrammar SQLPScanner.l
gcc -w SQLPParser.c util.o -o SQLPParser
rm -f lex.yy.c SQLPGrammar.tab.c SQLPGrammar.tab.h
SQLPParser_new: SQLPParser_new.c SQLPGrammar_new.y SQLPScanner_new.l util_new.o
bison --verbose -d SQLPGrammar_new.y
flex SQLPScanner_new.l
gcc -w SQLPParser_new.c util_new.o -o SQLPParser_new
rm -f lex.yy.c SQLPGrammar.tab.c SQLPGrammar.tab.h
SQLPSchema: SQLPSchema_main.c SQLPSchema.y SQLPScanner.l util.o
bison -d SQLPSchema.y
flex -D SQLPSchema SQLPScanner.l
gcc -g -w SQLPSchema_main.c util.o -o SQLPSchema
rm -f lex.yy.c SQLPSchema.tab.c SQLPSchema.tab.h
util.o: util.c util.h
gcc -c util.c
SQLPRefExp: SQLPRefExp_main.c SQLPRefExp.y SQLPScanner.l util.o
bison -d SQLPRefExp.y
flex -D SQLPRefExp SQLPScanner.l
gcc -g -w SQLPRefExp_main.c util.o -o SQLPRefExp
rm -f lex.yy.c SQLPRefExp.tab.c SQLPRefExp.tab.h
util_new.o: util_new.c util_new.h
gcc -c util_new.c
util.o: util.c util.h
gcc -g -c util.c
Parser: parser.c util.o
gcc -w parser.c util.o -o Parser
gcc -g -w parser.c util.o -o Parser
clean:
rm -f lex.yy.c *.tab.c *.tab.h *.fasl Parser util.o util_new.o
rm -f lex.yy.c *.tab.c *.tab.h *.fasl Parser util.o
......@@ -44,6 +44,9 @@ test input is
`select s.name from student s where s.name = "John" and s.num = 10;`.
The files added in Spring 2019 are appended with `_new`. To run the new
executable, the command is `./SQLPParser_new`.
Currently a syntax error will be reported when the semi-colon is read, but the
parse tree that is output is correct.
......@@ -80,45 +83,47 @@ Maybe this should be changed in the future to be separate but we'll leave that
discussion for the future.
Added in Spring 2019:
Entity descriptions for algebra in lisp form. There are two sorts of operators:
(1) operators producing normal tables with an ordered finite sequence of attribute
names, and (2) operators producing “column tables”, where tuples are a possibly
infinite set of “SQLP column name”/“constant” pairs.
<query> (1)
`<query> (1)
( select <set-or-bag> <limit> (as-list <as> … ) <body> )
( union <set-or-bag> <limit> (query-list <query> … ) )
( union <set-or-bag> <limit> (query-list <query> … ) )`
<set-or-bag>
`<set-or-bag>
distinct
all
all`
<limit>
`<limit>
( limit <integer-constant> )
( no-limit )
( no-limit )`
<as>
( as <column> <attribute-name> )
`<as>
( as <column> <attribute-name> )`
<body> (2)
`<body> (2)
<pred>
( atom <table-name> <var> )
( natural-join-list <body> … )
( sub-query <query> <var> )
( sub-query <query> <var> )`
<pred>
`<pred>
( equal <term> <term> )
( less-than <term> <term> )
( less-than-or-equal <term> <term> )
( exists <body> )
( not <pred> )
( and-list <pred> … )
( or-list <pred> … )
( or-list <pred> … )`
<term>
`<term>
<column>
( integer <integer-constant> )
( string <string-constant> )
( string <string-constant> )`
<column>
( column <var> ( attribute-name-list <attribute-name> … ) )
\ No newline at end of file
`<column>
( column <var> ( attribute-name-list <attribute-name> … ) )`
\ No newline at end of file
Terminals unused in grammar
IMPLIES
OR
HAS
MAX
MIN
AS
ASC
DESC
MOD
ASSIGN
COMMA
DOT
SIZE
SELECTIVITY
OVERLAP
FREQUENCY
UNIT
TIME
SPACE
CONSTANT
STRING_LITERAL
SIZEOF
STORE
STORING
DYNAMIC
STATIC
OF
TYPE
ORDERED
BY
INDEX
LIST
ARRAY
BINARY
TREE
DISTRIBUTED
POINTER
SCHEMA
CLASS
ISA
PROPERTIES
CONSTRAINTS
PROPERTY
ON
DETERMINED
COVER
QUERY
GIVEN
ORDER
PRECOMPUTED
ONE
FOR
ALL
TRANSACTION
INTCLASS
STRCLASS
DOUBLEREAL
MAXLEN
RANGE
TO
INSERT
END
CHANGE
DELETE
DECLARE
RETURN
Grammar
0 $accept: SQLPProgram $end
1 SQLPProgram: Query
2 Query: Union_Query
3 Select_Query: SELECT Select_List Body
4 Body: FROM TablePath
5 | FROM TablePath WHERE Bool
6 | FROM TablePath WHERE Pred
7 TablePath: TableIdentifier VarIdentifier
8 | TableIdentifier VarIdentifier ',' TablePath
9 Union_Query: Select_Query
10 | Union_Query UNION Select_Query
11 Select_List: STAR
12 | Col
13 | Col ',' Select_List
14 Col: VarIdentifier '.' AttrPath
15 AttrPath: AttrIdentifier
16 | AttrIdentifier '.' AttrPath
17 VarIdentifier: IDENTIFIER
18 TableIdentifier: IDENTIFIER
19 AttrIdentifier: IDENTIFIER
20 Operator: EQ
21 | NE
22 | LE
23 | GE
24 | LT
25 | GT
26 Bool: Col Operator Col
27 | Col Operator Constant
28 Pred: Bool AND Pred
29 | NOT Pred
30 | EXIST '(' Query ')'
31 Constant: INTEGER
32 | REAL
33 | STRING
Terminals, with rules where they appear
$end (0) 0
'(' (40) 30
')' (41) 30
',' (44) 8 13
'.' (46) 14 16
error (256)
IMPLIES (258)
OR (259)
AND (260) 28
NOT (261) 29
LE (262) 22
GE (263) 23
LT (264) 24
GT (265) 25
NE (266) 21
HAS (267)
MAX (268)
MIN (269)
AS (270)
ASC (271)
DESC (272)
MOD (273)
ASSIGN (274)
EQ (275) 20
STAR (276) 11
COMMA (277)
DOT (278)
SIZE (279)
SELECTIVITY (280)
OVERLAP (281)
FREQUENCY (282)
UNIT (283)
TIME (284)
SPACE (285)
IDENTIFIER (286) 17 18 19
CONSTANT (287)
STRING_LITERAL (288)
SIZEOF (289)
STORE (290)
STORING (291)
DYNAMIC (292)
STATIC (293)
OF (294)
TYPE (295)
ORDERED (296)
BY (297)
INDEX (298)
LIST (299)
ARRAY (300)
BINARY (301)
TREE (302)
DISTRIBUTED (303)
POINTER (304)
SCHEMA (305)
CLASS (306)
ISA (307)
PROPERTIES (308)
CONSTRAINTS (309)
PROPERTY (310)
ON (311)
DETERMINED (312)
COVER (313)
QUERY (314)
GIVEN (315)
FROM (316) 4 5 6
SELECT (317) 3
WHERE (318) 5 6
ORDER (319)
PRECOMPUTED (320)
ONE (321)
EXIST (322) 30
FOR (323)
ALL (324)
TRANSACTION (325)
INTCLASS (326)
STRCLASS (327)
INTEGER (328) 31
REAL (329) 32
DOUBLEREAL (330)
STRING (331) 33
MAXLEN (332)
RANGE (333)
TO (334)
INSERT (335)
END (336)
CHANGE (337)
DELETE (338)
DECLARE (339)
RETURN (340)
UNION (341) 10
Nonterminals, with rules where they appear
$accept (91)
on left: 0
SQLPProgram (92)
on left: 1, on right: 0
Query (93)
on left: 2, on right: 1 30
Select_Query (94)
on left: 3, on right: 9 10
Body (95)
on left: 4 5 6, on right: 3
TablePath (96)
on left: 7 8, on right: 4 5 6 8
Union_Query (97)
on left: 9 10, on right: 2 10
Select_List (98)
on left: 11 12 13, on right: 3 13
Col (99)
on left: 14, on right: 12 13 26 27
AttrPath (100)
on left: 15 16, on right: 14 16
VarIdentifier (101)
on left: 17, on right: 7 8 14
TableIdentifier (102)
on left: 18, on right: 7 8
AttrIdentifier (103)
on left: 19, on right: 15 16
Operator (104)
on left: 20 21 22 23 24 25, on right: 26 27
Bool (105)
on left: 26 27, on right: 5 28
Pred (106)
on left: 28 29 30, on right: 6 28 29
Constant (107)
on left: 31 32 33, on right: 27
State 0
0 $accept: . SQLPProgram $end
SELECT shift, and go to state 1
SQLPProgram go to state 2
Query go to state 3
Select_Query go to state 4
Union_Query go to state 5
State 1
3 Select_Query: SELECT . Select_List Body
STAR shift, and go to state 6
IDENTIFIER shift, and go to state 7
Select_List go to state 8
Col go to state 9
VarIdentifier go to state 10
State 2
0 $accept: SQLPProgram . $end
$end shift, and go to state 11
State 3
1 SQLPProgram: Query .
$default reduce using rule 1 (SQLPProgram)
State 4
9 Union_Query: Select_Query .
$default reduce using rule 9 (Union_Query)
State 5
2 Query: Union_Query .
10 Union_Query: Union_Query . UNION Select_Query
UNION shift, and go to state 12
$default reduce using rule 2 (Query)
State 6
11 Select_List: STAR .
$default reduce using rule 11 (Select_List)
State 7
17 VarIdentifier: IDENTIFIER .
$default reduce using rule 17 (VarIdentifier)
State 8
3 Select_Query: SELECT Select_List . Body
FROM shift, and go to state 13
Body go to state 14
State 9
12 Select_List: Col .
13 | Col . ',' Select_List
',' shift, and go to state 15
$default reduce using rule 12 (Select_List)
State 10
14 Col: VarIdentifier . '.' AttrPath
'.' shift, and go to state 16
State 11
0 $accept: SQLPProgram $end .
$default accept
State 12
10 Union_Query: Union_Query UNION . Select_Query
SELECT shift, and go to state 1
Select_Query go to state 17
State 13
4 Body: FROM . TablePath
5 | FROM . TablePath WHERE Bool
6 | FROM . TablePath WHERE Pred
IDENTIFIER shift, and go to state 18
TablePath go to state 19
TableIdentifier go to state 20
State 14
3 Select_Query: SELECT Select_List Body .
$default reduce using rule 3 (Select_Query)
State 15
13 Select_List: Col ',' . Select_List
STAR shift, and go to state 6
IDENTIFIER shift, and go to state 7
Select_List go to state 21
Col go to state 9
VarIdentifier go to state 10
State 16
14 Col: VarIdentifier '.' . AttrPath
IDENTIFIER shift, and go to state 22
AttrPath go to state 23
AttrIdentifier go to state 24
State 17
10 Union_Query: Union_Query UNION Select_Query .
$default reduce using rule 10 (Union_Query)
State 18
18 TableIdentifier: IDENTIFIER .
$default reduce using rule 18 (TableIdentifier)
State 19
4 Body: FROM TablePath .
5 | FROM TablePath . WHERE Bool
6 | FROM TablePath . WHERE Pred
WHERE shift, and go to state 25
$default reduce using rule 4 (Body)
State 20
7 TablePath: TableIdentifier . VarIdentifier
8 | TableIdentifier . VarIdentifier ',' TablePath
IDENTIFIER shift, and go to state 7
VarIdentifier go to state 26
State 21
13 Select_List: Col ',' Select_List .
$default reduce using rule 13 (Select_List)
State 22
19 AttrIdentifier: IDENTIFIER .
$default reduce using rule 19 (AttrIdentifier)
State 23
14 Col: VarIdentifier '.' AttrPath .
$default reduce using rule 14 (Col)
State 24
15 AttrPath: AttrIdentifier .
16 | AttrIdentifier . '.' AttrPath
'.' shift, and go to state 27
$default reduce using rule 15 (AttrPath)
State 25
5 Body: FROM TablePath WHERE . Bool
6 | FROM TablePath WHERE . Pred
NOT shift, and go to state 28
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 29
Col go to state 30
VarIdentifier go to state 10
Bool go to state 31
Pred go to state 32
State 26
7 TablePath: TableIdentifier VarIdentifier .
8 | TableIdentifier VarIdentifier . ',' TablePath
',' shift, and go to state 33
$default reduce using rule 7 (TablePath)
State 27
16 AttrPath: AttrIdentifier '.' . AttrPath
IDENTIFIER shift, and go to state 22
AttrPath go to state 34
AttrIdentifier go to state 24
State 28
29 Pred: NOT . Pred
NOT shift, and go to state 28
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 29
Col go to state 30
VarIdentifier go to state 10
Bool go to state 35
Pred go to state 36
State 29
30 Pred: EXIST . '(' Query ')'
'(' shift, and go to state 37
State 30
26 Bool: Col . Operator Col
27 | Col . Operator Constant
LE shift, and go to state 38
GE shift, and go to state 39
LT shift, and go to state 40
GT shift, and go to state 41
NE shift, and go to state 42
EQ shift, and go to state 43
Operator go to state 44
State 31
5 Body: FROM TablePath WHERE Bool .
28 Pred: Bool . AND Pred
AND shift, and go to state 45
$default reduce using rule 5 (Body)
State 32
6 Body: FROM TablePath WHERE Pred .
$default reduce using rule 6 (Body)
State 33
8 TablePath: TableIdentifier VarIdentifier ',' . TablePath
IDENTIFIER shift, and go to state 18
TablePath go to state 46
TableIdentifier go to state 20
State 34
16 AttrPath: AttrIdentifier '.' AttrPath .
$default reduce using rule 16 (AttrPath)
State 35
28 Pred: Bool . AND Pred
AND shift, and go to state 45
State 36
29 Pred: NOT Pred .
$default reduce using rule 29 (Pred)
State 37
30 Pred: EXIST '(' . Query ')'
SELECT shift, and go to state 1
Query go to state 47
Select_Query go to state 4
Union_Query go to state 5
State 38
22 Operator: LE .
$default reduce using rule 22 (Operator)
State 39
23 Operator: GE .
$default reduce using rule 23 (Operator)
State 40
24 Operator: LT .
$default reduce using rule 24 (Operator)
State 41
25 Operator: GT .
$default reduce using rule 25 (Operator)
State 42
21 Operator: NE .
$default reduce using rule 21 (Operator)
State 43
20 Operator: EQ .
$default reduce using rule 20 (Operator)
State 44
26 Bool: Col Operator . Col
27 | Col Operator . Constant
IDENTIFIER shift, and go to state 7
INTEGER shift, and go to state 48
REAL shift, and go to state 49
STRING shift, and go to state 50
Col go to state 51
VarIdentifier go to state 10
Constant go to state 52
State 45
28 Pred: Bool AND . Pred
NOT shift, and go to state 28
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 29
Col go to state 30
VarIdentifier go to state 10
Bool go to state 35
Pred go to state 53
State 46
8 TablePath: TableIdentifier VarIdentifier ',' TablePath .
$default reduce using rule 8 (TablePath)
State 47
30 Pred: EXIST '(' Query . ')'
')' shift, and go to state 54
State 48
31 Constant: INTEGER .
$default reduce using rule 31 (Constant)
State 49
32 Constant: REAL .
$default reduce using rule 32 (Constant)
State 50
33 Constant: STRING .
$default reduce using rule 33 (Constant)
State 51
26 Bool: Col Operator Col .
$default reduce using rule 26 (Bool)
State 52
27 Bool: Col Operator Constant .
$default reduce using rule 27 (Bool)
State 53
28 Pred: Bool AND Pred .
$default reduce using rule 28 (Pred)
State 54
30 Pred: EXIST '(' Query ')' .
$default reduce using rule 30 (Pred)
......@@ -13,199 +13,330 @@
%token STORE STORING DYNAMIC STATIC OF TYPE ORDERED BY
%token INDEX LIST ARRAY BINARY TREE DISTRIBUTED POINTER
%token SCHEMA CLASS ISA PROPERTIES CONSTRAINTS PROPERTY
%token SCHEMA CLASS ISA PROPERTIES CONSTRAINTS PROPERTY DISJOINT
%token FOREIGN KEY REFERENCES WITH
%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 PRECOMPUTED ONE EXIST FOR ALL TRANSACTION INTCLASS STRCLASS OID
%token INTEGER REAL DOUBLEREAL STRING MAXLEN RANGE TO SELF
%token INSERT END CHANGE DELETE DECLARE RETURN UNION UNIONALL
%token LIMIT DISTINCT REF
%start SQLPProgram
%%
SQLPProgram
: Query
{ printf("Input Query\n");
cons_cell *n = $1;
printf("Printing Tree\n");
print_cons_tree(n);
}
{
printf("Input Query\n");
cons_cell *n = $1;
printf("Printing Tree\n");
print_cons_tree(n);
}
;
Query
: Union_Query
{ printf("Union Query\n");
$$ = $1;
}
: UnionQuery
{
printf("Query 1\n");
$$ = $1;
}
| SelectQuery
{
printf("Query 3\n");
$$ = $1;
}
| SelectQuery LIMIT Integer
{
printf("Query 4\n");
$$ = create_limit_operator($1, $3);
}
;
Select_Query
: SELECT Select_List Body
{ printf("SQLP Query\n");
$$ = create_proj_operator($2, $3);
}
SelectQuery
: SELECT
{
printf("SelectQuery 1 \n");
}
| SELECT SelectList
{
printf("SelectQuery 2 \n");
$$ = create_rename_operator($2, NULL);
}
| SELECT Body
{
printf("SelectQuery 3 \n");
$$ = create_rename_operator($2, NULL);
}
| SELECT SelectList Body
{
printf("SelectQuery 4 \n");
$$ = create_proj_operator($2, $3);
}
| SELECT DISTINCT Body
{
printf("SelectList 5 \n");
$$ = create_rename_operator($3, NULL);
}
| SELECT DISTINCT SelectList Body
{
printf("SelectList 6 \n");
$$ = create_proj_operator($2, $3);
}
;
Body
: FROM TablePath
{ printf("Body 1\n");
$$ = $2;
}
| FROM TablePath WHERE Bool
{ printf("Body 2\n");
$$ = create_eval_operator($4, $2);
}
| FROM TablePath WHERE Pred
{ printf("Body 3\n");
$$ = create_eval_operator($4, $2);
}
: FROM TableList
{
printf("Body 1 \n");
$$ = create_rename_operator($2, NULL);
}
| FROM WHERE Pred
{
printf("Body 2 \n");
$$ = create_rename_operator($3, NULL);
}
| FROM TableList WHERE Pred
{
printf("Body 3 \n");
$$ = create_eval_operator($4, $2);
}
;
TablePath
: TableIdentifier VarIdentifier
{ printf("last table path\n");
$$ = create_rename_operator($1, $2);
}
| TableIdentifier VarIdentifier ',' TablePath
{ printf("table path2\n");
$$ = create_cross_operator(create_rename_operator($1, $2), $4);
}
;
TableList
: TableIdentifier VarIdentifier
{
printf("TableList 1\n");
$$ = create_rename_operator($1, $2);
}
| TableIdentifier VarIdentifier ',' TableList
{
printf("TableList 2\n");
$$ = create_cross_operator(create_rename_operator($1, $2), $4);
}
;
Union_Query
: Select_Query
{ printf("union query 1\n");
$$ = $1;
}
| Union_Query UNION Select_Query
{ printf("union query 2\n");
$$ = create_union_all_operator($1, $3);
}
;
Select_List
: STAR
{ printf("star\n");
//$$ = new_node(1, Select_List);
//$$->children[0] = new_node(0, STAR);
}
| Col
{ printf("select list attr path\n");
$$ = create_rename_operator($1, NULL);
}
| Col ',' Select_List
{ printf("Select list\n");
$$ = create_rename_operator($1, $2);
}
UnionQuery
: '(' SelectQuery ')' UNION UnionQuery
{
printf("UnionQuery 1\n");
$$ = create_union_all_operator($2, $5);
}
| '(' SelectQuery ')' UNIONALL UnionQuery
{
printf("UnionQuery 2\n");
$$ = create_union_all_operator($2, $5);
}
| '(' SelectQuery ')'
{
printf("UnionQuery 3\n");
$$ = create_rename_operator($1, NULL);
}
;
SelectList
: Col
{
printf("SelectList 1\n");
$$ = create_rename_operator($1, NULL);
}
| Col AS AttrIdentifier
{
printf("SelectList 2\n");
$$ = create_as_operator($1, $3);
}
| Col ',' SelectList
{
printf("SelectList 3\n");
$$ = create_rename_operator($1, $2);
}
| Col AS AttrIdentifier ',' SelectList
{
printf("SelectList 4\n");
$$ = create_rename_operator($1, create_as_operator($3, $5));
}
| AttrIdentifier
{
printf("SelectList 1\n");
$$ = create_rename_operator($1, NULL);
}
| AttrIdentifier AS AttrIdentifier
{
printf("SelectList 2\n");
$$ = create_as_operator($1, $3);
}
| AttrIdentifier ',' SelectList
{
printf("SelectList 3\n");
$$ = create_rename_operator($1, $2);
}
| AttrIdentifier AS AttrIdentifier ',' SelectList
{
printf("SelectList 4\n");
$$ = create_rename_operator($1, create_as_operator($3, $5));
}
;
Col
: VarIdentifier '.' AttrPath
{
printf("col\n");
$$ = create_spcol($1, $3);
}
: VarIdentifier '.' AttrPath
{
printf("col\n");
$$ = create_spcol($1, $3);
}
;
AttrPath
: AttrIdentifier
{ printf("path id\n");
$$ = create_pf($1, NULL);
}
{
printf("AttrPath 1\n");
$$ = create_pf($1, NULL);
}
| AttrIdentifier '.' AttrPath
{ printf("Path Function\n");
$$ = create_pf($1, $3);
}
;
{
printf("AttrPath 2\n");
$$ = create_pf($1, $3);
}
VarIdentifier
: IDENTIFIER
{
printf("|%s| ", yytext);
$$ = create_var(yytext);
}
: IDENTIFIER
{
printf("VarIdentifier is |%s| ", yytext);
$$ = create_var(yytext);
}
TableIdentifier
: IDENTIFIER
{
printf("|%s| ", yytext);
$$ = create_table(yytext);
}
: IDENTIFIER
{
printf("TableIdentifier is |%s| ", yytext);
$$ = create_var(yytext);
}
AttrIdentifier
: IDENTIFIER
{
printf("|%s| ", yytext);
$$ = create_attr(yytext);
}
: IDENTIFIER
{
printf("AttrIdentifier is |%s| ", yytext);
$$ = create_var(yytext);
}
Operator
CompOperator
: EQ
{
$$ = create_op(yytext);
}
{
printf("CompOperator EQ\n");
$$ = create_op(yytext);
}
| NE
{
$$ = create_op(yytext);
}
{
printf("CompOperator NE\n");
$$ = create_op(yytext);
}
| LE
{
$$ = create_op(yytext);
}
{
printf("CompOperator LE\n");
$$ = create_op(yytext);
}
| GE
{
$$ = create_op(yytext);
}
{
printf("CompOperator GE\n");
$$ = create_op(yytext);
}
| LT
{
$$ = create_op(yytext);
}
{
printf("CompOperator LT\n");
$$ = create_op(yytext);
}
| GT
{
$$ = create_op(yytext);
}
;
Bool
: Col Operator Col
{ printf("Col op Col\n");
cons_cell* first_term = create_term($1);
cons_cell* second_term = create_term($3);
$$ = create_comp_operator($2, first_term, second_term, NULL);
}
| Col Operator Constant
{ printf("Col op Constant\n");
cons_cell* first_term = create_term($1);
$$ = create_comp_operator($2, first_term, $3, NULL);
}
{
printf("CompOperator GT\n");
$$ = create_op(yytext);
}
;
Pred
: Bool AND Pred
{ printf("pred and pred\n");
$$ = $1;
$$->cdr->cdr->cdr->cdr->car = $3;
}
| NOT Pred
{ printf("Not Pred\n");
$$ = create_not_operator($1, NULL);
}
| EXIST '(' Query ')'
{ printf("Exist query\n");
$$ = create_atom("INPROG");
//$$->children[0] = new_node(0, EXIST);
//$$->children[1] = $3;
}
;
: Conj
{
printf("Pred 1\n");
$$ = $1;
}
| Conj OR Pred
{
printf("Pred 2 \n");
$$ = create_or_operator($1, $3);
}
Conj
: BasicPred
{
printf("Conj 1 \n");
$$ = $1;
}
| BasicPred AND Conj
{
printf("Conj 2 \n");
$$ = create_and_operator($1, $3);
}
BasicPred
: Term CompOperator Term
{
printf("BasicPred 1\n");
cons_cell* first_term = create_term($1);
cons_cell* second_term = create_term($3);
$$ = create_comp_operator($2, first_term, second_term);
}
| EXIST '(' Body ')'
{
printf("BasicPred 2\n");
$$ = create_exist_operator($2);
}
| NOT BasicPred
{
printf("BasicPred 3 \n");
$$ = create_not_operator($2);
}
| '(' Pred ')'
{
printf("BasicPred 4\n");
$$ = $1;
}
Term
: Constant
{
printf("Term 1\n");
$$ = $1;
}
| Col
{
printf("Term 2\n");
$$ = $1;
}
Integer
: INTEGER
{
printf("INTEGER is |%s|", yytext);
$$ = create_constant(yytext);
}
Constant
: INTEGER
{ printf("|%s|", yytext);
$$ = create_constant(yytext);
}
{
printf("INTEGER is |%s|", yytext);
$$ = create_constant(yytext);
}
| REAL
{ printf("|%s|", yytext);
$$ = create_constant(yytext);
}
{
printf("REAL is |%s|", yytext);
$$ = create_constant(yytext);
}
| STRING
{ printf("|%s|", yytext);
$$ = create_constant(yytext);
}
{
printf("STRING is |%s|", yytext);
$$ = create_constant(yytext);
}
;
Terminals unused in grammar
IMPLIES
HAS
MAX
MIN
ASC
DESC
MOD
ASSIGN
STAR
COMMA
DOT
SIZE
SELECTIVITY
OVERLAP
FREQUENCY
UNIT
TIME
SPACE
CONSTANT
STRING_LITERAL
SIZEOF
STORE
STORING
DYNAMIC
STATIC
OF
TYPE
ORDERED
BY
INDEX
LIST
ARRAY
BINARY
TREE
DISTRIBUTED
POINTER
SCHEMA
CLASS
ISA
PROPERTIES
CONSTRAINTS
PROPERTY
ON
DETERMINED
COVER
QUERY
GIVEN
ORDER
PRECOMPUTED
ONE
FOR
ALL
TRANSACTION
INTCLASS
STRCLASS
DOUBLEREAL
MAXLEN
RANGE
TO
INSERT
END
CHANGE
DELETE
DECLARE
RETURN
Grammar
0 $accept: SQLPProgram $end
1 SQLPProgram: Query
2 Query: UnionQuery
3 | UnionQuery LIMIT INTEGER
4 | SelectQuery
5 | SelectQuery LIMIT INTEGER
6 SelectQuery: SELECT Body
7 | SELECT SelectList Body
8 | SELECT DISTINCT Body
9 | SELECT DISTINCT SelectList Body
10 Body: FROM TableList
11 | FROM WHERE Pred
12 | FROM TableList WHERE Pred
13 TableList: TableIdentifier VarIdentifier
14 | TableIdentifier VarIdentifier ',' TableList
15 UnionQuery: '(' SelectQuery ')' UNION UnionQuery
16 | '(' SelectQuery ')' UNIONALL UnionQuery
17 | '(' SelectQuery ')'
18 SelectList: Col
19 | Col AS AttrIdentifier
20 | Col ',' SelectList
21 | Col AS AttrIdentifier ',' SelectList
22 Col: VarIdentifier '.' AttrPath
23 AttrPath: AttrIdentifier
24 | AttrIdentifier '.' AttrPath
25 VarIdentifier: IDENTIFIER
26 TableIdentifier: IDENTIFIER
27 AttrIdentifier: IDENTIFIER
28 CompOperator: EQ
29 | NE
30 | LE
31 | GE
32 | LT
33 | GT
34 Pred: Conj
35 | Conj OR Pred
36 Conj: BasicPred
37 | BasicPred AND Conj
38 BasicPred: Term CompOperator Term
39 | EXIST '(' Body ')'
40 | NOT BasicPred
41 | '(' Pred ')'
42 Term: Constant
43 | Col
44 Constant: INTEGER
45 | REAL
46 | STRING
Terminals, with rules where they appear
$end (0) 0
'(' (40) 15 16 17 39 41
')' (41) 15 16 17 39 41
',' (44) 14 20 21
'.' (46) 22 24
error (256)
IMPLIES (258)
OR (259) 35
AND (260) 37
NOT (261) 40
LE (262) 30
GE (263) 31
LT (264) 32
GT (265) 33
NE (266) 29
HAS (267)
MAX (268)
MIN (269)
AS (270) 19 21
ASC (271)
DESC (272)
MOD (273)
ASSIGN (274)
EQ (275) 28
STAR (276)
COMMA (277)
DOT (278)
SIZE (279)
SELECTIVITY (280)
OVERLAP (281)
FREQUENCY (282)
UNIT (283)
TIME (284)
SPACE (285)
IDENTIFIER (286) 25 26 27
CONSTANT (287)
STRING_LITERAL (288)
SIZEOF (289)
STORE (290)
STORING (291)
DYNAMIC (292)
STATIC (293)
OF (294)
TYPE (295)
ORDERED (296)
BY (297)
INDEX (298)
LIST (299)
ARRAY (300)
BINARY (301)
TREE (302)
DISTRIBUTED (303)
POINTER (304)
SCHEMA (305)
CLASS (306)
ISA (307)
PROPERTIES (308)
CONSTRAINTS (309)
PROPERTY (310)
ON (311)
DETERMINED (312)
COVER (313)
QUERY (314)
GIVEN (315)
FROM (316) 10 11 12
SELECT (317) 6 7 8 9
WHERE (318) 11 12
ORDER (319)
PRECOMPUTED (320)
ONE (321)
EXIST (322) 39
FOR (323)
ALL (324)
TRANSACTION (325)
INTCLASS (326)
STRCLASS (327)
INTEGER (328) 3 5 44
REAL (329) 45
DOUBLEREAL (330)
STRING (331) 46
MAXLEN (332)
RANGE (333)
TO (334)
INSERT (335)
END (336)
CHANGE (337)
DELETE (338)
DECLARE (339)
RETURN (340)
UNION (341) 15
UNIONALL (342) 16
LIMIT (343) 3 5
DISTINCT (344) 8 9
Nonterminals, with rules where they appear
$accept (94)
on left: 0
SQLPProgram (95)
on left: 1, on right: 0
Query (96)
on left: 2 3 4 5, on right: 1
SelectQuery (97)
on left: 6 7 8 9, on right: 4 5 15 16 17
Body (98)
on left: 10 11 12, on right: 6 7 8 9 39
TableList (99)
on left: 13 14, on right: 10 12 14
UnionQuery (100)
on left: 15 16 17, on right: 2 3 15 16
SelectList (101)
on left: 18 19 20 21, on right: 7 9 20 21
Col (102)
on left: 22, on right: 18 19 20 21 43
AttrPath (103)
on left: 23 24, on right: 22 24
VarIdentifier (104)
on left: 25, on right: 13 14 22
TableIdentifier (105)
on left: 26, on right: 13 14
AttrIdentifier (106)
on left: 27, on right: 19 21 23 24
CompOperator (107)
on left: 28 29 30 31 32 33, on right: 38
Pred (108)
on left: 34 35, on right: 11 12 35 41
Conj (109)
on left: 36 37, on right: 34 35 37
BasicPred (110)
on left: 38 39 40 41, on right: 36 37 40
Term (111)
on left: 42 43, on right: 38
Constant (112)
on left: 44 45 46, on right: 42
State 0
0 $accept: . SQLPProgram $end
SELECT shift, and go to state 1
'(' shift, and go to state 2
SQLPProgram go to state 3
Query go to state 4
SelectQuery go to state 5
UnionQuery go to state 6
State 1
6 SelectQuery: SELECT . Body
7 | SELECT . SelectList Body
8 | SELECT . DISTINCT Body
9 | SELECT . DISTINCT SelectList Body
IDENTIFIER shift, and go to state 7
FROM shift, and go to state 8
DISTINCT shift, and go to state 9
Body go to state 10
SelectList go to state 11
Col go to state 12
VarIdentifier go to state 13
State 2
15 UnionQuery: '(' . SelectQuery ')' UNION UnionQuery
16 | '(' . SelectQuery ')' UNIONALL UnionQuery
17 | '(' . SelectQuery ')'
SELECT shift, and go to state 1
SelectQuery go to state 14
State 3
0 $accept: SQLPProgram . $end
$end shift, and go to state 15
State 4
1 SQLPProgram: Query .
$default reduce using rule 1 (SQLPProgram)
State 5
4 Query: SelectQuery .
5 | SelectQuery . LIMIT INTEGER
LIMIT shift, and go to state 16
$default reduce using rule 4 (Query)
State 6
2 Query: UnionQuery .
3 | UnionQuery . LIMIT INTEGER
LIMIT shift, and go to state 17
$default reduce using rule 2 (Query)
State 7
25 VarIdentifier: IDENTIFIER .
$default reduce using rule 25 (VarIdentifier)
State 8
10 Body: FROM . TableList
11 | FROM . WHERE Pred
12 | FROM . TableList WHERE Pred
IDENTIFIER shift, and go to state 18
WHERE shift, and go to state 19
TableList go to state 20
TableIdentifier go to state 21
State 9
8 SelectQuery: SELECT DISTINCT . Body
9 | SELECT DISTINCT . SelectList Body
IDENTIFIER shift, and go to state 7
FROM shift, and go to state 8
Body go to state 22
SelectList go to state 23
Col go to state 12
VarIdentifier go to state 13
State 10
6 SelectQuery: SELECT Body .
$default reduce using rule 6 (SelectQuery)
State 11
7 SelectQuery: SELECT SelectList . Body
FROM shift, and go to state 8
Body go to state 24
State 12
18 SelectList: Col .
19 | Col . AS AttrIdentifier
20 | Col . ',' SelectList
21 | Col . AS AttrIdentifier ',' SelectList
AS shift, and go to state 25
',' shift, and go to state 26
$default reduce using rule 18 (SelectList)
State 13
22 Col: VarIdentifier . '.' AttrPath
'.' shift, and go to state 27
State 14
15 UnionQuery: '(' SelectQuery . ')' UNION UnionQuery
16 | '(' SelectQuery . ')' UNIONALL UnionQuery
17 | '(' SelectQuery . ')'
')' shift, and go to state 28
State 15
0 $accept: SQLPProgram $end .
$default accept
State 16
5 Query: SelectQuery LIMIT . INTEGER
INTEGER shift, and go to state 29
State 17
3 Query: UnionQuery LIMIT . INTEGER
INTEGER shift, and go to state 30
State 18
26 TableIdentifier: IDENTIFIER .
$default reduce using rule 26 (TableIdentifier)
State 19
11 Body: FROM WHERE . Pred
NOT shift, and go to state 31
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 32
INTEGER shift, and go to state 33
REAL shift, and go to state 34
STRING shift, and go to state 35
'(' shift, and go to state 36
Col go to state 37
VarIdentifier go to state 13
Pred go to state 38
Conj go to state 39
BasicPred go to state 40
Term go to state 41
Constant go to state 42
State 20
10 Body: FROM TableList .
12 | FROM TableList . WHERE Pred
WHERE shift, and go to state 43
$default reduce using rule 10 (Body)
State 21
13 TableList: TableIdentifier . VarIdentifier
14 | TableIdentifier . VarIdentifier ',' TableList
IDENTIFIER shift, and go to state 7
VarIdentifier go to state 44
State 22
8 SelectQuery: SELECT DISTINCT Body .
$default reduce using rule 8 (SelectQuery)
State 23
9 SelectQuery: SELECT DISTINCT SelectList . Body
FROM shift, and go to state 8
Body go to state 45
State 24
7 SelectQuery: SELECT SelectList Body .
$default reduce using rule 7 (SelectQuery)
State 25
19 SelectList: Col AS . AttrIdentifier
21 | Col AS . AttrIdentifier ',' SelectList
IDENTIFIER shift, and go to state 46
AttrIdentifier go to state 47
State 26
20 SelectList: Col ',' . SelectList
IDENTIFIER shift, and go to state 7
SelectList go to state 48
Col go to state 12
VarIdentifier go to state 13
State 27
22 Col: VarIdentifier '.' . AttrPath
IDENTIFIER shift, and go to state 46
AttrPath go to state 49
AttrIdentifier go to state 50
State 28
15 UnionQuery: '(' SelectQuery ')' . UNION UnionQuery
16 | '(' SelectQuery ')' . UNIONALL UnionQuery
17 | '(' SelectQuery ')' .
UNION shift, and go to state 51
UNIONALL shift, and go to state 52
$default reduce using rule 17 (UnionQuery)
State 29
5 Query: SelectQuery LIMIT INTEGER .
$default reduce using rule 5 (Query)
State 30
3 Query: UnionQuery LIMIT INTEGER .
$default reduce using rule 3 (Query)
State 31
40 BasicPred: NOT . BasicPred
NOT shift, and go to state 31
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 32
INTEGER shift, and go to state 33
REAL shift, and go to state 34
STRING shift, and go to state 35
'(' shift, and go to state 36
Col go to state 37
VarIdentifier go to state 13
BasicPred go to state 53
Term go to state 41
Constant go to state 42
State 32
39 BasicPred: EXIST . '(' Body ')'
'(' shift, and go to state 54
State 33
44 Constant: INTEGER .
$default reduce using rule 44 (Constant)
State 34
45 Constant: REAL .
$default reduce using rule 45 (Constant)
State 35
46 Constant: STRING .
$default reduce using rule 46 (Constant)
State 36
41 BasicPred: '(' . Pred ')'
NOT shift, and go to state 31
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 32
INTEGER shift, and go to state 33
REAL shift, and go to state 34
STRING shift, and go to state 35
'(' shift, and go to state 36
Col go to state 37
VarIdentifier go to state 13
Pred go to state 55
Conj go to state 39
BasicPred go to state 40
Term go to state 41
Constant go to state 42
State 37
43 Term: Col .
$default reduce using rule 43 (Term)
State 38
11 Body: FROM WHERE Pred .
$default reduce using rule 11 (Body)
State 39
34 Pred: Conj .
35 | Conj . OR Pred
OR shift, and go to state 56
$default reduce using rule 34 (Pred)
State 40
36 Conj: BasicPred .
37 | BasicPred . AND Conj
AND shift, and go to state 57
$default reduce using rule 36 (Conj)
State 41
38 BasicPred: Term . CompOperator Term
LE shift, and go to state 58
GE shift, and go to state 59
LT shift, and go to state 60
GT shift, and go to state 61
NE shift, and go to state 62
EQ shift, and go to state 63
CompOperator go to state 64
State 42
42 Term: Constant .
$default reduce using rule 42 (Term)
State 43
12 Body: FROM TableList WHERE . Pred
NOT shift, and go to state 31
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 32
INTEGER shift, and go to state 33
REAL shift, and go to state 34
STRING shift, and go to state 35
'(' shift, and go to state 36
Col go to state 37
VarIdentifier go to state 13
Pred go to state 65
Conj go to state 39
BasicPred go to state 40
Term go to state 41
Constant go to state 42
State 44
13 TableList: TableIdentifier VarIdentifier .
14 | TableIdentifier VarIdentifier . ',' TableList
',' shift, and go to state 66
$default reduce using rule 13 (TableList)
State 45
9 SelectQuery: SELECT DISTINCT SelectList Body .
$default reduce using rule 9 (SelectQuery)
State 46
27 AttrIdentifier: IDENTIFIER .
$default reduce using rule 27 (AttrIdentifier)
State 47
19 SelectList: Col AS AttrIdentifier .
21 | Col AS AttrIdentifier . ',' SelectList
',' shift, and go to state 67
$default reduce using rule 19 (SelectList)
State 48
20 SelectList: Col ',' SelectList .
$default reduce using rule 20 (SelectList)
State 49
22 Col: VarIdentifier '.' AttrPath .
$default reduce using rule 22 (Col)
State 50
23 AttrPath: AttrIdentifier .
24 | AttrIdentifier . '.' AttrPath
'.' shift, and go to state 68
$default reduce using rule 23 (AttrPath)
State 51
15 UnionQuery: '(' SelectQuery ')' UNION . UnionQuery
'(' shift, and go to state 2
UnionQuery go to state 69
State 52
16 UnionQuery: '(' SelectQuery ')' UNIONALL . UnionQuery
'(' shift, and go to state 2
UnionQuery go to state 70
State 53
40 BasicPred: NOT BasicPred .
$default reduce using rule 40 (BasicPred)
State 54
39 BasicPred: EXIST '(' . Body ')'
FROM shift, and go to state 8
Body go to state 71
State 55
41 BasicPred: '(' Pred . ')'
')' shift, and go to state 72
State 56
35 Pred: Conj OR . Pred
NOT shift, and go to state 31
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 32
INTEGER shift, and go to state 33
REAL shift, and go to state 34
STRING shift, and go to state 35
'(' shift, and go to state 36
Col go to state 37
VarIdentifier go to state 13
Pred go to state 73
Conj go to state 39
BasicPred go to state 40
Term go to state 41
Constant go to state 42
State 57
37 Conj: BasicPred AND . Conj
NOT shift, and go to state 31
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 32
INTEGER shift, and go to state 33
REAL shift, and go to state 34
STRING shift, and go to state 35
'(' shift, and go to state 36
Col go to state 37
VarIdentifier go to state 13
Conj go to state 74
BasicPred go to state 40
Term go to state 41
Constant go to state 42
State 58
30 CompOperator: LE .
$default reduce using rule 30 (CompOperator)
State 59
31 CompOperator: GE .
$default reduce using rule 31 (CompOperator)
State 60
32 CompOperator: LT .
$default reduce using rule 32 (CompOperator)
State 61
33 CompOperator: GT .
$default reduce using rule 33 (CompOperator)
State 62
29 CompOperator: NE .
$default reduce using rule 29 (CompOperator)
State 63
28 CompOperator: EQ .
$default reduce using rule 28 (CompOperator)
State 64
38 BasicPred: Term CompOperator . Term
IDENTIFIER shift, and go to state 7
INTEGER shift, and go to state 33
REAL shift, and go to state 34
STRING shift, and go to state 35
Col go to state 37
VarIdentifier go to state 13
Term go to state 75
Constant go to state 42
State 65
12 Body: FROM TableList WHERE Pred .
$default reduce using rule 12 (Body)
State 66
14 TableList: TableIdentifier VarIdentifier ',' . TableList
IDENTIFIER shift, and go to state 18
TableList go to state 76
TableIdentifier go to state 21
State 67
21 SelectList: Col AS AttrIdentifier ',' . SelectList
IDENTIFIER shift, and go to state 7
SelectList go to state 77
Col go to state 12
VarIdentifier go to state 13
State 68
24 AttrPath: AttrIdentifier '.' . AttrPath
IDENTIFIER shift, and go to state 46
AttrPath go to state 78
AttrIdentifier go to state 50
State 69
15 UnionQuery: '(' SelectQuery ')' UNION UnionQuery .
$default reduce using rule 15 (UnionQuery)
State 70
16 UnionQuery: '(' SelectQuery ')' UNIONALL UnionQuery .
$default reduce using rule 16 (UnionQuery)
State 71
39 BasicPred: EXIST '(' Body . ')'
')' shift, and go to state 79
State 72
41 BasicPred: '(' Pred ')' .
$default reduce using rule 41 (BasicPred)
State 73
35 Pred: Conj OR Pred .
$default reduce using rule 35 (Pred)
State 74
37 Conj: BasicPred AND Conj .
$default reduce using rule 37 (Conj)
State 75
38 BasicPred: Term CompOperator Term .
$default reduce using rule 38 (BasicPred)
State 76
14 TableList: TableIdentifier VarIdentifier ',' TableList .
$default reduce using rule 14 (TableList)
State 77
21 SelectList: Col AS AttrIdentifier ',' SelectList .
$default reduce using rule 21 (SelectList)
State 78
24 AttrPath: AttrIdentifier '.' AttrPath .
$default reduce using rule 24 (AttrPath)
State 79
39 BasicPred: EXIST '(' Body ')' .
$default reduce using rule 39 (BasicPred)
/* A Bison parser, made by GNU Bison 3.0.4. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_YY_SQLPGRAMMAR_NEW_TAB_H_INCLUDED
# define YY_YY_SQLPGRAMMAR_NEW_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
IMPLIES = 258,
OR = 259,
AND = 260,
NOT = 261,
LE = 262,
GE = 263,
LT = 264,
GT = 265,
NE = 266,
HAS = 267,
MAX = 268,
MIN = 269,
AS = 270,
ASC = 271,
DESC = 272,
MOD = 273,
ASSIGN = 274,
EQ = 275,
STAR = 276,
COMMA = 277,
DOT = 278,
SIZE = 279,
SELECTIVITY = 280,
OVERLAP = 281,
FREQUENCY = 282,
UNIT = 283,
TIME = 284,
SPACE = 285,
IDENTIFIER = 286,
CONSTANT = 287,
STRING_LITERAL = 288,
SIZEOF = 289,
STORE = 290,
STORING = 291,
DYNAMIC = 292,
STATIC = 293,
OF = 294,
TYPE = 295,
ORDERED = 296,
BY = 297,
INDEX = 298,
LIST = 299,
ARRAY = 300,
BINARY = 301,
TREE = 302,
DISTRIBUTED = 303,
POINTER = 304,
SCHEMA = 305,
CLASS = 306,
ISA = 307,
PROPERTIES = 308,
CONSTRAINTS = 309,
PROPERTY = 310,
ON = 311,
DETERMINED = 312,
COVER = 313,
QUERY = 314,
GIVEN = 315,
FROM = 316,
SELECT = 317,
WHERE = 318,
ORDER = 319,
PRECOMPUTED = 320,
ONE = 321,
EXIST = 322,
FOR = 323,
ALL = 324,
TRANSACTION = 325,
INTCLASS = 326,
STRCLASS = 327,
INTEGER = 328,
REAL = 329,
DOUBLEREAL = 330,
STRING = 331,
MAXLEN = 332,
RANGE = 333,
TO = 334,
INSERT = 335,
END = 336,
CHANGE = 337,
DELETE = 338,
DECLARE = 339,
RETURN = 340,
UNION = 341,
UNIONALL = 342,
LIMIT = 343,
DISTINCT = 344
};
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef cons_cell * YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_SQLPGRAMMAR_NEW_TAB_H_INCLUDED */
%{
#include "util_new.h"
%}
%define api.value.type {cons_cell *}
%token IMPLIES OR AND NOT LE GE LT GT NE HAS MAX MIN AS ASC DESC MOD ASSIGN EQ STAR COMMA DOT
%token SIZE SELECTIVITY OVERLAP
%token FREQUENCY UNIT TIME SPACE
%token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF
%token STORE STORING DYNAMIC STATIC OF TYPE ORDERED BY
%token INDEX LIST ARRAY BINARY TREE DISTRIBUTED POINTER
%token SCHEMA CLASS ISA PROPERTIES CONSTRAINTS PROPERTY
%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 UNIONALL
%token LIMIT DISTINCT
%start SQLPProgram
%%
SQLPProgram
: Query
{
printf("Input Query\n");
cons_cell *n = $1;
printf("Printing Tree\n");
print_cons_tree(n);
}
;
Query
: UnionQuery
{
printf("Query 1\n");
$$ = $1;
}
| UnionQuery LIMIT INTEGER
{
printf("Query 2\n");
$$ = create_limit_operator($1, $3);
}
| SelectQuery
{
printf("Query 3\n");
$$ = $1;
}
| SelectQuery LIMIT INTEGER
{
printf("Query 4\n");
$$ = create_limit_operator($1, $3);
}
;
SelectQuery
: SELECT Body
| SELECT SelectList Body
| SELECT DISTINCT Body
| SELECT DISTINCT SelectList Body
;
Body
: FROM TableList
| FROM WHERE Pred
| FROM TableList WHERE Pred
;
TableList
: TableIdentifier VarIdentifier
{
printf("TableList 1\n");
$$ = create_rename_operator($1, $2);
}
| TableIdentifier VarIdentifier ',' TableList // keep right-recursive
{
printf("TableList 2\n");
$$ = create_cross_operator(create_rename_operator($1, $2), $4);
}
;
UnionQuery
: '(' SelectQuery ')' UNION UnionQuery
{
printf("UnionQuery 1\n");
$$ = create_union_all_operator($2, $5);
}
| '(' SelectQuery ')' UNIONALL UnionQuery
{
printf("UnionQuery 2\n");
$$ = create_union_all_operator($2, $5);
}
| '(' SelectQuery ')'
{
printf("UnionQuery 3\n");
$$ = $1;
}
;
SelectList
: Col
{
printf("SelectList 2\n");
$$ = create_rename_operator($1, NULL);
}
| Col AS AttrIdentifier // todo: create_as_operator
| Col ',' SelectList
{
printf("SelectList 4\n");
$$ = create_rename_operator($1, $2);
}
| Col AS AttrIdentifier ',' SelectList
;
Col
: VarIdentifier '.' AttrPath
{
printf("col\n");
$$ = create_spcol($1, $3);
}
AttrPath
: AttrIdentifier
{
printf("AttrPath 1\n");
$$ = create_pf($1, NULL);
}
| AttrIdentifier '.' AttrPath
{
printf("AttrPath 2\n");
$$ = create_pf($1, $3);
}
VarIdentifier
: IDENTIFIER
{
printf("VarIdentifier is |%s| ", yytext);
$$ = create_var(yytext);
}
TableIdentifier
: IDENTIFIER
{
printf("TableIdentifier is |%s| ", yytext);
$$ = create_var(yytext);
}
AttrIdentifier
: IDENTIFIER
{
printf("AttrIdentifier is |%s| ", yytext);
$$ = create_var(yytext);
}
CompOperator
: EQ
{
printf("CompOperator EQ\n");
$$ = create_op(yytext);
}
| NE
{
printf("CompOperator NE\n");
$$ = create_op(yytext);
}
| LE
{
printf("CompOperator LE\n");
$$ = create_op(yytext);
}
| GE
{
printf("CompOperator GE\n");
$$ = create_op(yytext);
}
| LT
{
printf("CompOperator LT\n");
$$ = create_op(yytext);
}
| GT
{
printf("CompOperator GT\n");
$$ = create_op(yytext);
}
;
Pred
: Conj
{
printf("Pred 1\n");
$$ = $1;
}
| Conj OR Pred
{
printf("Pred 2 \n");
$$ = create_or_operator($1, $3);
}
Conj
: BasicPred
{
printf("Conj 1 \n");
$$ = $1;
}
| BasicPred AND Conj
{
printf("Conj 2 \n");
$$ = create_and_operator($1, $3);
}
BasicPred
: Term CompOperator Term
{
printf("BasicPred 1\n");
cons_cell* first_term = create_term($1);
cons_cell* second_term = create_term($3);
$$ = create_comp_operator($2, first_term, second_term, NULL);
}
| EXIST '(' Body ')'
{
printf("BasicPred 2\n");
$$ = create_exist_operator($2);
}
| NOT BasicPred
{
printf("BasicPred 3 \n");
$$ = create_not_operator($2);
}
| '(' Pred ')'
{
printf("BasicPred 4\n");
$$ = $1;
}
Term
: Constant
{
printf("Term 1\n");
$$ = $1;
}
| Col
{
printf("Term 2\n");
$$ = $1;
}
Constant
: INTEGER
{
printf("INTEGER is |%s|", yytext);
$$ = create_constant(yytext);
}
| REAL
{
printf("REAL is |%s|", yytext);
$$ = create_constant(yytext);
}
| STRING
{
printf("STRING is |%s|", yytext);
$$ = create_constant(yytext);
}
;
File deleted
......@@ -24,7 +24,7 @@
int main()
{
int Result;
int Result;
strcpy(LineBuffer, "");
printf("(\n");
Result = yyparse();
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.SQLPParser</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
File deleted
select x.ssn_num from Person x where x.std_info.name = "A"
\ No newline at end of file
File deleted
File added