Skip to content
Snippets Groups Projects
Commit 31f67726 authored by expan's avatar expan
Browse files

small fix

parent f8b4b938
No related branches found
No related tags found
1 merge request!1SQLP parser with cons cells
......@@ -93,44 +93,46 @@ Grammar
11 | Union_Query UNION Select_Query
12 Select_List: STAR
13 | AttrPath
14 | AttrPath ',' Select_List
13 | Col
14 | Col ',' Select_List
15 AttrPath: Identifier
16 | Identifier '.' AttrPath
15 Col: Identifier '.' AttrPath
17 Operator: EQ
18 | NE
19 | LE
20 | GE
21 | LT
22 | GT
16 AttrPath: Identifier
17 | Identifier '.' AttrPath
23 Bool: AttrPath Operator AttrPath
24 | AttrPath Operator CONSTANT
18 Operator: EQ
19 | NE
20 | LE
21 | GE
22 | LT
23 | GT
25 Pred: Bool AND Pred
26 | NOT Pred
27 | EXIST '(' Query ')'
24 Bool: Col Operator Col
25 | Col Operator CONSTANT
26 Pred: Bool AND Pred
27 | NOT Pred
28 | EXIST '(' Query ')'
Terminals, with rules where they appear
$end (0) 0
'(' (40) 27
')' (41) 27
'(' (40) 28
')' (41) 28
',' (44) 9 14
'.' (46) 16
'.' (46) 15 17
error (256)
IMPLIES (258)
OR (259)
AND (260) 25
NOT (261) 26
LE (262) 19
GE (263) 20
LT (264) 21
GT (265) 22
NE (266) 18
AND (260) 26
NOT (261) 27
LE (262) 20
GE (263) 21
LT (264) 22
GT (265) 23
NE (266) 19
HAS (267)
MAX (268)
MIN (269)
......@@ -139,7 +141,7 @@ ASC (271)
DESC (272)
MOD (273)
ASSIGN (274)
EQ (275) 17
EQ (275) 18
STAR (276) 12
COMMA (277)
DOT (278)
......@@ -151,7 +153,7 @@ UNIT (283)
TIME (284)
SPACE (285)
IDENTIFIER (286) 2
CONSTANT (287) 24
CONSTANT (287) 25
STRING_LITERAL (288)
SIZEOF (289)
STORE (290)
......@@ -186,7 +188,7 @@ WHERE (318) 6 7
ORDER (319)
PRECOMPUTED (320)
ONE (321)
EXIST (322) 27
EXIST (322) 28
FOR (323)
ALL (324)
TRANSACTION (325)
......@@ -215,9 +217,9 @@ $accept (91)
SQLPProgram (92)
on left: 1, on right: 0
Identifier (93)
on left: 2, on right: 8 9 15 16
on left: 2, on right: 8 9 15 16 17
Query (94)
on left: 3, on right: 1 27
on left: 3, on right: 1 28
Select_Query (95)
on left: 4, on right: 10 11
Body (96)
......@@ -228,14 +230,16 @@ Union_Query (98)
on left: 10 11, on right: 3 11
Select_List (99)
on left: 12 13 14, on right: 4 14
AttrPath (100)
on left: 15 16, on right: 13 14 16 23 24
Operator (101)
on left: 17 18 19 20 21 22, on right: 23 24
Bool (102)
on left: 23 24, on right: 6 25
Pred (103)
on left: 25 26 27, on right: 7 25 26
Col (100)
on left: 15, on right: 13 14 24 25
AttrPath (101)
on left: 16 17, on right: 15 17
Operator (102)
on left: 18 19 20 21 22 23, on right: 24 25
Bool (103)
on left: 24 25, on right: 6 26
Pred (104)
on left: 26 27 28, on right: 7 26 27
State 0
......@@ -259,7 +263,7 @@ State 1
Identifier go to state 8
Select_List go to state 9
AttrPath go to state 10
Col go to state 10
State 2
......@@ -309,13 +313,10 @@ State 7
State 8
15 AttrPath: Identifier .
16 | Identifier . '.' AttrPath
15 Col: Identifier . '.' AttrPath
'.' shift, and go to state 13
$default reduce using rule 15 (AttrPath)
State 9
......@@ -328,8 +329,8 @@ State 9
State 10
13 Select_List: AttrPath .
14 | AttrPath . ',' Select_List
13 Select_List: Col .
14 | Col . ',' Select_List
',' shift, and go to state 16
......@@ -354,12 +355,12 @@ State 12
State 13
16 AttrPath: Identifier '.' . AttrPath
15 Col: Identifier '.' . AttrPath
IDENTIFIER shift, and go to state 7
Identifier go to state 8
AttrPath go to state 18
Identifier go to state 18
AttrPath go to state 19
State 14
......@@ -370,8 +371,8 @@ State 14
IDENTIFIER shift, and go to state 7
Identifier go to state 19
TablePath go to state 20
Identifier go to state 20
TablePath go to state 21
State 15
......@@ -383,14 +384,14 @@ State 15
State 16
14 Select_List: AttrPath ',' . Select_List
14 Select_List: Col ',' . Select_List
STAR shift, and go to state 6
IDENTIFIER shift, and go to state 7
Identifier go to state 8
Select_List go to state 21
AttrPath go to state 10
Select_List go to state 22
Col go to state 10
State 17
......@@ -402,257 +403,284 @@ State 17
State 18
16 AttrPath: Identifier '.' AttrPath .
16 AttrPath: Identifier .
17 | Identifier . '.' AttrPath
'.' shift, and go to state 23
$default reduce using rule 16 (AttrPath)
State 19
15 Col: Identifier '.' AttrPath .
$default reduce using rule 15 (Col)
State 20
8 TablePath: Identifier . Identifier
9 | Identifier . Identifier ',' TablePath
IDENTIFIER shift, and go to state 7
Identifier go to state 22
Identifier go to state 24
State 20
State 21
5 Body: FROM TablePath .
6 | FROM TablePath . WHERE Bool
7 | FROM TablePath . WHERE Pred
WHERE shift, and go to state 23
WHERE shift, and go to state 25
$default reduce using rule 5 (Body)
State 21
State 22
14 Select_List: AttrPath ',' Select_List .
14 Select_List: Col ',' Select_List .
$default reduce using rule 14 (Select_List)
State 22
State 23
17 AttrPath: Identifier '.' . AttrPath
IDENTIFIER shift, and go to state 7
Identifier go to state 18
AttrPath go to state 26
State 24
8 TablePath: Identifier Identifier .
9 | Identifier Identifier . ',' TablePath
',' shift, and go to state 24
',' shift, and go to state 27
$default reduce using rule 8 (TablePath)
State 23
State 25
6 Body: FROM TablePath WHERE . Bool
7 | FROM TablePath WHERE . Pred
NOT shift, and go to state 25
NOT shift, and go to state 28
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 26
EXIST shift, and go to state 29
Identifier go to state 8
AttrPath go to state 27
Bool go to state 28
Pred go to state 29
Col go to state 30
Bool go to state 31
Pred go to state 32
State 24
State 26
17 AttrPath: Identifier '.' AttrPath .
$default reduce using rule 17 (AttrPath)
State 27
9 TablePath: Identifier Identifier ',' . TablePath
IDENTIFIER shift, and go to state 7
Identifier go to state 19
TablePath go to state 30
Identifier go to state 20
TablePath go to state 33
State 25
State 28
26 Pred: NOT . Pred
27 Pred: NOT . Pred
NOT shift, and go to state 25
NOT shift, and go to state 28
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 26
EXIST shift, and go to state 29
Identifier go to state 8
AttrPath go to state 27
Bool go to state 31
Pred go to state 32
Col go to state 30
Bool go to state 34
Pred go to state 35
State 26
State 29
27 Pred: EXIST . '(' Query ')'
28 Pred: EXIST . '(' Query ')'
'(' shift, and go to state 33
'(' shift, and go to state 36
State 27
State 30
23 Bool: AttrPath . Operator AttrPath
24 | AttrPath . Operator CONSTANT
24 Bool: Col . Operator Col
25 | Col . Operator CONSTANT
LE shift, and go to state 34
GE shift, and go to state 35
LT shift, and go to state 36
GT shift, and go to state 37
NE shift, and go to state 38
EQ shift, and go to state 39
LE shift, and go to state 37
GE shift, and go to state 38
LT shift, and go to state 39
GT shift, and go to state 40
NE shift, and go to state 41
EQ shift, and go to state 42
Operator go to state 40
Operator go to state 43
State 28
State 31
6 Body: FROM TablePath WHERE Bool .
25 Pred: Bool . AND Pred
26 Pred: Bool . AND Pred
AND shift, and go to state 41
AND shift, and go to state 44
$default reduce using rule 6 (Body)
State 29
State 32
7 Body: FROM TablePath WHERE Pred .
$default reduce using rule 7 (Body)
State 30
State 33
9 TablePath: Identifier Identifier ',' TablePath .
$default reduce using rule 9 (TablePath)
State 31
State 34
25 Pred: Bool . AND Pred
26 Pred: Bool . AND Pred
AND shift, and go to state 41
AND shift, and go to state 44
State 32
State 35
26 Pred: NOT Pred .
27 Pred: NOT Pred .
$default reduce using rule 26 (Pred)
$default reduce using rule 27 (Pred)
State 33
State 36
27 Pred: EXIST '(' . Query ')'
28 Pred: EXIST '(' . Query ')'
SELECT shift, and go to state 1
Query go to state 42
Query go to state 45
Select_Query go to state 4
Union_Query go to state 5
State 34
State 37
19 Operator: LE .
20 Operator: LE .
$default reduce using rule 19 (Operator)
$default reduce using rule 20 (Operator)
State 35
State 38
20 Operator: GE .
21 Operator: GE .
$default reduce using rule 20 (Operator)
$default reduce using rule 21 (Operator)
State 36
State 39
21 Operator: LT .
22 Operator: LT .
$default reduce using rule 21 (Operator)
$default reduce using rule 22 (Operator)
State 37
State 40
22 Operator: GT .
23 Operator: GT .
$default reduce using rule 22 (Operator)
$default reduce using rule 23 (Operator)
State 38
State 41
18 Operator: NE .
19 Operator: NE .
$default reduce using rule 18 (Operator)
$default reduce using rule 19 (Operator)
State 39
State 42
17 Operator: EQ .
18 Operator: EQ .
$default reduce using rule 17 (Operator)
$default reduce using rule 18 (Operator)
State 40
State 43
23 Bool: AttrPath Operator . AttrPath
24 | AttrPath Operator . CONSTANT
24 Bool: Col Operator . Col
25 | Col Operator . CONSTANT
IDENTIFIER shift, and go to state 7
CONSTANT shift, and go to state 43
CONSTANT shift, and go to state 46
Identifier go to state 8
AttrPath go to state 44
Col go to state 47
State 41
State 44
25 Pred: Bool AND . Pred
26 Pred: Bool AND . Pred
NOT shift, and go to state 25
NOT shift, and go to state 28
IDENTIFIER shift, and go to state 7
EXIST shift, and go to state 26
EXIST shift, and go to state 29
Identifier go to state 8
AttrPath go to state 27
Bool go to state 31
Pred go to state 45
Col go to state 30
Bool go to state 34
Pred go to state 48
State 42
State 45
27 Pred: EXIST '(' Query . ')'
28 Pred: EXIST '(' Query . ')'
')' shift, and go to state 46
')' shift, and go to state 49
State 43
State 46
24 Bool: AttrPath Operator CONSTANT .
25 Bool: Col Operator CONSTANT .
$default reduce using rule 24 (Bool)
$default reduce using rule 25 (Bool)
State 44
State 47
23 Bool: AttrPath Operator AttrPath .
24 Bool: Col Operator Col .
$default reduce using rule 23 (Bool)
$default reduce using rule 24 (Bool)
State 45
State 48
25 Pred: Bool AND Pred .
26 Pred: Bool AND Pred .
$default reduce using rule 25 (Pred)
$default reduce using rule 26 (Pred)
State 46
State 49
27 Pred: EXIST '(' Query ')' .
28 Pred: EXIST '(' Query ')' .
$default reduce using rule 27 (Pred)
$default reduce using rule 28 (Pred)
......@@ -28,95 +28,68 @@
SQLPProgram
: Query
{ printf("Input Query\n");
struct node *n = new_node(1, SQLPProgram);
n->children[0] = $1;
cons_cell *n = $1;
printf("Printing Tree\n");
print_tree(n, 0);
struct linked_node *linked_tree = malloc(sizeof(struct linked_node));
translate(linked_tree, n);
print_linked_tree(linked_tree, 0);
print_cons_tree(n, 0);
}
;
Identifier
: IDENTIFIER
{ printf("|%s| ", yytext);
$$ = new_node(1, Identifier);
$$->children[0] = new_node(0, IDENTIFIER);
$$ = yytext;
}
;
Query
: Union_Query
{ printf("Union Query\n");
$$ = new_node(1, Query);
$$->children[0] = $1;
$$ = $1;
}
;
Select_Query
: SELECT Select_List Body
{ printf("SQLP Query\n");
$$ = new_node(3, Select_Query);
$$->children[0] = new_node(0, SELECT);
$$->children[1] = $2;
$$->children[2] = $3;
$$ = create_proj_operator($1, $2);
}
;
Body
: FROM TablePath
{ printf("Body 1\n");
$$ = new_node(2, Body);
$$->children[0] = new_node(0, FROM);
$$->children[1] = $2;}
$$ = $2;
}
| FROM TablePath WHERE Bool
{ printf("Body 2\n");
$$ = new_node(4, Body);
$$->children[0] = new_node(0, FROM);
$$->children[1] = $2;
$$->children[2] = new_node(0, WHERE);
$$->children[3] = $4;
$$ = create_eval_operator($4, $2);
}
| FROM TablePath WHERE Pred
{ printf("Body 3\n");
$$ = new_node(4, Body);
$$->children[0] = new_node(0, FROM);
$$->children[1] = $2;
$$->children[2] = new_node(0, WHERE);
$$->children[3] = $4;
$$ = create_eval_operator($4, $2);
}
;
TablePath
: Identifier Identifier
{ printf("table path1\n");
$$ = new_node(2, TablePath);
$$->children[0] = $1;
$$->children[1] = $2;
}
{ printf("last table path\n");
$$ = create_atom_operator($1, $2);
}
| Identifier Identifier ',' TablePath
{ printf("table path2\n");
$$ = new_node(4, TablePath);
$$->children[0] = $1;
$$->children[1] = $2;
$$->children[2] = new_node(0, COMMA);
$$->children[3] = $4;
$$ = create_cross_operator(create_atom_operator($1, $2), $4);
}
;
Union_Query
: Select_Query
{ printf("union query 1\n");
$$ = new_node(1, Union_Query);
$$->children[0] = $1;
$$ = $1;
}
| Union_Query UNION Select_Query
{ printf("union query 2\n");
$$ = new_node(3, Union_Query);
$$->children[0] = $1;
$$->children[1] = new_node(0, UNION);
$$->children[2] = $3;
$$ = create_union_all_operator($1, $3);
}
;
......@@ -126,34 +99,34 @@ Select_List
$$ = new_node(1, Select_List);
$$->children[0] = new_node(0, STAR);
}
| AttrPath
| Col
{ printf("select list attr path\n");
$$ = new_node(1, Select_List);
$$->children[0] = $1;
$$ = create_assign_operator($1, $1, NULL);
}
| AttrPath ',' Select_List
| Col ',' Select_List
{ printf("Select list\n");
$$ = new_node(3, Select_List);
$$->children[0] = $1;
$$->children[1] = new_node(0, COMMA);
$$->children[2] = $3;
$$ = create_assign_operator($1, $1, $2);
}
;
Col
: Identifier '.' AttrPath
{
printf("col\n");
$$ = create_spcol($1, $3);
}
AttrPath
: Identifier
{ printf("path id\n");
$$ = new_node(1, AttrPath);
$$->children[0] = $1;
$$ = create_pf(create_attr($1), NULL);
}
| Identifier '.' AttrPath
{ printf("Path Function\n");
$$ = new_node(3, AttrPath);
$$->children[0] = $1;
$$->children[1] = new_node(0, DOT);
$$->children[2] = $3;
$$ = create_pf(create_attr($1), $3);
}
;
Operator
: EQ
| NE
......@@ -164,42 +137,31 @@ Operator
;
Bool
: AttrPath Operator AttrPath
{ printf("AttrPath op AttrPath\n");
$$ = new_node(3, Bool);
$$->children[0] = $1;
$$->children[1] = $2;
$$->children[2] = $3;
: Col Operator Col
{ printf("Col op Col\n");
$$ = create_comp_operator($2, $1, $3, NULL);
}
| AttrPath Operator CONSTANT
{ printf("AttrPath op Constant\n");
$$ = new_node(3, Bool);
$$->children[0] = $1;
$$->children[1] = $2;
$$->children[2] = new_node(0, CONSTANT);
| Col Operator CONSTANT
{ printf("Col op Constant\n");
cons_cell* a = create_cons_cell_w_atom(CONSTANT, NULL);
$$ = create_comp_operator($2, $1, a, NULL);
}
;
Pred
: Bool AND Pred
{ printf("pred and pred\n");
$$ = new_node(3, Pred);
$$->children[0] = $1;
$$->children[1] = new_node(0, AND);
$$->children[2] = $3;
$$ = $1;
$$->cdr->cdr->cdr->cdr->car = $3;
}
| NOT Pred
{ printf("Not Pred\n");
$$ = new_node(2, Pred);
$$->children[0] = new_node(0, NOT);
$$->children[1] = $2;
$$ = create_not_operator($1, NULL);
}
| EXIST '(' Query ')'
{ printf("Exist query\n");
$$ = new_node(2, Pred);
$$->children[0] = new_node(0, EXIST);
$$->children[1] = $3;
$$ = create_atom("INPROG");
//$$->children[0] = new_node(0, EXIST);
//$$->children[1] = $3;
}
;
\ No newline at end of file
;
File deleted
......@@ -18,7 +18,7 @@
*/
#include <stdio.h>
#include <util.h>
#include "util.h"
#include "lex.yy.c"
#include "SQLPGrammar.tab.c"
......@@ -34,4 +34,4 @@ int main()
fprintf(stderr, "checking semantics.\n");
printf(")\n");
return (Result);
}
\ No newline at end of file
}
......@@ -28,67 +28,95 @@
SQLPProgram
: Query
{ printf("Input Query\n");
cons_cell *n = $1;
struct node *n = new_node(1, SQLPProgram);
n->children[0] = $1;
printf("Printing Tree\n");
print_cons_tree(n, 0);
print_tree(n, 0);
struct linked_node *linked_tree = malloc(sizeof(struct linked_node));
translate(linked_tree, n);
print_linked_tree(linked_tree, 0);
}
;
Identifier
: IDENTIFIER
{ printf("|%s| ", yytext);
$$ = yytext;
$$ = new_node(1, Identifier);
$$->children[0] = new_node(0, IDENTIFIER);
}
;
Query
: Union_Query
{ printf("Union Query\n");
$$ = $1;
$$ = new_node(1, Query);
$$->children[0] = $1;
}
;
Select_Query
: SELECT Select_List Body
{ printf("SQLP Query\n");
$$ = create_proj_operator($1, $2);
$$ = new_node(3, Select_Query);
$$->children[0] = new_node(0, SELECT);
$$->children[1] = $2;
$$->children[2] = $3;
}
;
Body
: FROM TablePath
{ printf("Body 1\n");
$$ = create_cons_cell($2,NULL);
$$ = new_node(2, Body);
$$->children[0] = new_node(0, FROM);
$$->children[1] = $2;}
| FROM TablePath WHERE Bool
{ printf("Body 2\n");
$$ = create_eval_operator($4, $2);
$$ = new_node(4, Body);
$$->children[0] = new_node(0, FROM);
$$->children[1] = $2;
$$->children[2] = new_node(0, WHERE);
$$->children[3] = $4;
}
| FROM TablePath WHERE Pred
{ printf("Body 3\n");
$$ = create_eval_operator($4, $2);
$$ = new_node(4, Body);
$$->children[0] = new_node(0, FROM);
$$->children[1] = $2;
$$->children[2] = new_node(0, WHERE);
$$->children[3] = $4;
}
;
TablePath
: Identifier Identifier
{ printf("last table path\n");
$$ = create_atom_operator($1, $2);
}
{ printf("table path1\n");
$$ = new_node(2, TablePath);
$$->children[0] = $1;
$$->children[1] = $2;
}
| Identifier Identifier ',' TablePath
{ printf("table path2\n");
$$ = create_cross_operator(create_atom_operator($1, $2), $4);
$$ = new_node(4, TablePath);
$$->children[0] = $1;
$$->children[1] = $2;
$$->children[2] = new_node(0, COMMA);
$$->children[3] = $4;
}
;
Union_Query
: Select_Query
{ printf("union query 1\n");
$$ = $1;
$$ = new_node(1, Union_Query);
$$->children[0] = $1;
}
| Union_Query UNION Select_Query
{ printf("union query 2\n");
$$ = create_union_all_operator($1, $3);
$$ = new_node(3, Union_Query);
$$->children[0] = $1;
$$->children[1] = new_node(0, UNION);
$$->children[2] = $3;
}
;
......@@ -98,34 +126,34 @@ Select_List
$$ = new_node(1, Select_List);
$$->children[0] = new_node(0, STAR);
}
| Col
| AttrPath
{ printf("select list attr path\n");
$$ = create_assign_operator($1, $1, NULL);
$$ = new_node(1, Select_List);
$$->children[0] = $1;
}
| Col ',' Select_List
| AttrPath ',' Select_List
{ printf("Select list\n");
$$ = create_assign_operator($1, $1, $2);
$$ = new_node(3, Select_List);
$$->children[0] = $1;
$$->children[1] = new_node(0, COMMA);
$$->children[2] = $3;
}
;
Col
: Identifier '.' AttrPath
{
printf("col\n");
$$ = create_spcol($1, $3);
}
AttrPath
: Identifier
{ printf("path id\n");
$$ = create_pf(create_attr($1), NULL);
$$ = new_node(1, AttrPath);
$$->children[0] = $1;
}
| Identifier '.' AttrPath
{ printf("Path Function\n");
$$ = create_pf(create_attr($1), $3);
$$ = new_node(3, AttrPath);
$$->children[0] = $1;
$$->children[1] = new_node(0, DOT);
$$->children[2] = $3;
}
;
Operator
: EQ
| NE
......@@ -136,26 +164,37 @@ Operator
;
Bool
: Col Operator Col
{ printf("Col op Col\n");
$$ = create_comp_operator($2, $1, $3, NULL);
: AttrPath Operator AttrPath
{ printf("AttrPath op AttrPath\n");
$$ = new_node(3, Bool);
$$->children[0] = $1;
$$->children[1] = $2;
$$->children[2] = $3;
}
| Col Operator CONSTANT
{ printf("Col op Constant\n");
cons_cell* a = create_cons_cell_w_atom(CONSTANT, NULL);
$$ = create_comp_operator($2, $1, a, NULL);
| AttrPath Operator CONSTANT
{ printf("AttrPath op Constant\n");
$$ = new_node(3, Bool);
$$->children[0] = $1;
$$->children[1] = $2;
$$->children[2] = new_node(0, CONSTANT);
}
;
Pred
: Bool AND Pred
{ printf("pred and pred\n");
$$ = $1;
$$->cdr->cdr->cdr->cdr->car = $3;
$$ = new_node(3, Pred);
$$->children[0] = $1;
$$->children[1] = new_node(0, AND);
$$->children[2] = $3;
}
| NOT Pred
{ printf("Not Pred\n");
$$ = create_not_operator($1, NULL);
$$ = new_node(2, Pred);
$$->children[0] = new_node(0, NOT);
$$->children[1] = $2;
}
| EXIST '(' Query ')'
{ printf("Exist query\n");
......@@ -163,4 +202,4 @@ Pred
$$->children[0] = new_node(0, EXIST);
$$->children[1] = $3;
}
;
;
\ No newline at end of file
No preview for this file type
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