Commit d542f9af authored by Eva Feng's avatar Eva Feng
Browse files

Merge branch 'dev' into 'master'

Dev Merge into Master

See merge request !5
parents 32e1c17b f1a4f375
.PHONY: all clean
#CFLAGS = `pkg-config --cflags glib-2.0`
#CFLAGS = `pkg-config --cflags glib-2.0`
#LDLIBS = `pkg-config --libs glib-2.0`
all: SQLPParser Parser
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
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
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.o: util.c util.h
gcc -c util.c
# gcc `pkg-config --cflags --libs glib-2.0` util.c
#gcc -c util.c
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
......
File deleted
......@@ -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.
......@@ -77,4 +80,50 @@ valid.
Also the Makefile only has two commands, `make` and `make clean`. `make` will
create both the SQLPParser and Parser programs to do what was described above.
Maybe this should be changed in the future to be separate but we'll leave that
discussion for the future.
\ No newline at end of file
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)
( select <set-or-bag> <limit> (as-list <as> … ) <body> )
( union <set-or-bag> <limit> (query-list <query> … ) )`
`<set-or-bag>
distinct
all`
`<limit>
( limit <integer-constant> )
( no-limit )`
`<as>
( as <column> <attribute-name> )`
`<body> (2)
<pred>
( atom <table-name> <var> )
( natural-join-list <body> … )
( sub-query <query> <var> )`
`<pred>
( equal <term> <term> )
( less-than <term> <term> )
( less-than-or-equal <term> <term> )
( exists <body> )
( not <pred> )
( and-list <pred> … )
( or-list <pred> … )`
`<term>
<column>
( integer <integer-constant> )
( string <string-constant> )`
`<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