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

added new file SQLPGrammar_new.y with new grammar rules

parent a2e6de25
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 SQLPParser_new Parser
SQLPParser: SQLPParser.c SQLPGrammar.y SQLPScanner.l util.o
bison --verbose -d SQLPGrammar.y
flex SQLPScanner.l
gcc -w SQLPParser.c util.o -o SQLPParser
rm -f lex.yy.c SQLPGrammar.tab.c SQLPGrammar.tab.h
# rm -f lex.yy.c SQLPGrammar.tab.c SQLPGrammar.tab.h
SQLPParser_new: SQLPParser.c SQLPGrammar_new.y SQLPScanner.l util.o
bison --verbose -d SQLPGrammar_new.y
flex SQLPScanner.l
gcc -w SQLPParser.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
......
File deleted
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
State 31 conflicts: 3 reduce/reduce
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 | Bool
32 Constant: INTEGER
33 | REAL
34 | 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) 32
REAL (329) 33
DOUBLEREAL (330)
STRING (331) 34
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 31
Pred (106)
on left: 28 29 30 31, on right: 6 28 29
Constant (107)
on left: 32 33 34, 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
31 | Bool .
AND shift, and go to state 45
$end reduce using rule 5 (Body)
$end [reduce using rule 31 (Pred)]
UNION reduce using rule 5 (Body)
UNION [reduce using rule 31 (Pred)]
')' reduce using rule 5 (Body)
')' [reduce using rule 31 (Pred)]
$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
31 | Bool .
AND shift, and go to state 45
$default reduce using rule 31 (Pred)
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
32 Constant: INTEGER .
$default reduce using rule 32 (Constant)
State 49
33 Constant: REAL .
$default reduce using rule 33 (Constant)
State 50
34 Constant: STRING .
$default reduce using rule 34 (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)
%{
#include "util.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
%start SQLPProgram
%%
/*
todo: add ELIM, LIMIT
todo: check recursive token is on the left
*/
SQLPProgram
: Query
;
Query
: Union_Query
| Select_Query
;
Select_Query
: SELECT Select_List Body
;
Elim
: ELIM
| NO_ELM
;
Limit
: LIMIT
| NO_LIMIT
;
Body
: FROM TablePath
| FROM TablePath WHERE Pred
;
TablePath
: TableIdentifier VarIdentifier
| TableIdentifier VarIdentifier ',' TablePath
;
Union_Query
: Union_Query UNION Select_Query
;
Select_List
: STAR
| Col
| Col as Attr
| Col ',' Select_List
| Col as Attr ',' Select_List
;
Col
: VarIdentifier '.' AttrPath
Attr
: AttrIdentifier
AttrPath
: AttrIdentifier
| AttrIdentifier '.' AttrPath
VarIdentifier
: IDENTIFIER
TableIdentifier
: IDENTIFIER
AttrIdentifier
: IDENTIFIER
Operator
: EQ
| NE
| LE
| GE
| LT
| GT
;
Pred
: Col Operator Col
| Col Operator Constant
| Pred AND Col Operator Col
| Pred AND Col Operator Constant
| Pred OR Col Operator Col
| Pred OR Col Operator Constant
| NOT Pred
| EXIST '(' SELECT START Body ')'
;
Constant
: INTEGER
| REAL
| STRING
File added
File deleted
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