blob: 8e413b7dd72df2b714354a7caa88c2119095385c [file] [log] [blame]
drh348784e2000-05-29 20:41:49 +00001/*
2** Copyright (c) 1999, 2000 D. Richard Hipp
3**
4** This program is free software; you can redistribute it and/or
5** modify it under the terms of the GNU General Public
6** License as published by the Free Software Foundation; either
7** version 2 of the License, or (at your option) any later version.
8**
9** This program is distributed in the hope that it will be useful,
10** but WITHOUT ANY WARRANTY; without even the implied warranty of
11** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12** General Public License for more details.
13**
14** You should have received a copy of the GNU General Public
15** License along with this library; if not, write to the
16** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17** Boston, MA 02111-1307, USA.
18**
19** Author contact information:
20** drh@hwaci.com
21** http://www.hwaci.com/drh/
22**
23*************************************************************************
24** This file contains SQLite's grammar for SQL. Process this file
25** using the lemon parser generator to generate C code that runs
26** the parser. Lemon will also generate a header file containing
27** numeric codes for all of the tokens.
28**
drha2e1bb52001-01-04 14:20:18 +000029** @(#) $Id: parse.y,v 1.26 2001/01/04 14:20:18 drh Exp $
drh348784e2000-05-29 20:41:49 +000030*/
31%token_prefix TK_
32%token_type {Token}
33%extra_argument {Parse *pParse}
34%syntax_error {
drhc837e702000-06-08 16:26:24 +000035 sqliteSetString(&pParse->zErrMsg,"syntax error",0);
drh348784e2000-05-29 20:41:49 +000036 pParse->sErrToken = TOKEN;
37}
38%name sqliteParser
39%include {
40#include "sqliteInt.h"
41#include "parse.h"
42}
43
44
45// Input is zero or more commands.
46input ::= cmdlist.
47
48// These are extra tokens used by the lexer but never seen by the
49// parser. We put them in a rule so that the parser generator will
drh6206d502000-06-19 19:09:08 +000050// add them to the parse.h output file.
drh348784e2000-05-29 20:41:49 +000051//
52input ::= END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
drh967e8b72000-06-21 13:59:10 +000053 UMINUS COLUMN AGG_FUNCTION.
drh348784e2000-05-29 20:41:49 +000054
55// A list of commands is zero or more commands
56//
57cmdlist ::= ecmd.
58cmdlist ::= cmdlist SEMI ecmd.
59ecmd ::= explain cmd. {sqliteExec(pParse);}
60ecmd ::= cmd. {sqliteExec(pParse);}
61ecmd ::= .
62explain ::= EXPLAIN. {pParse->explain = 1;}
63
64// The first form of a command is a CREATE TABLE statement.
65//
66cmd ::= create_table create_table_args.
drh982cef72000-05-30 16:27:03 +000067create_table ::= CREATE(X) TABLE id(Y). {sqliteStartTable(pParse,&X,&Y);}
drh348784e2000-05-29 20:41:49 +000068create_table_args ::= LP columnlist conslist_opt RP(X).
69 {sqliteEndTable(pParse,&X);}
70columnlist ::= columnlist COMMA column.
71columnlist ::= column.
72
73// About the only information used for a column is the name of the
74// column. The type is always just "text". But the code will accept
75// an elaborate typename. Perhaps someday we'll do something with it.
76//
77column ::= columnid type carglist.
drh982cef72000-05-30 16:27:03 +000078columnid ::= id(X). {sqliteAddColumn(pParse,&X);}
79%type id {Token}
80id(A) ::= ID(X). {A = X;}
81id(A) ::= STRING(X). {A = X;}
drh348784e2000-05-29 20:41:49 +000082type ::= typename.
83type ::= typename LP signed RP.
84type ::= typename LP signed COMMA signed RP.
drh4cfa7932000-06-08 15:10:46 +000085typename ::= id.
86typename ::= typename id.
drh348784e2000-05-29 20:41:49 +000087signed ::= INTEGER.
88signed ::= PLUS INTEGER.
89signed ::= MINUS INTEGER.
90carglist ::= carglist carg.
91carglist ::= .
drh4cfa7932000-06-08 15:10:46 +000092carg ::= CONSTRAINT id ccons.
drh348784e2000-05-29 20:41:49 +000093carg ::= ccons.
drh7020f652000-06-03 18:06:52 +000094carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
95carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
96carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
97carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
98carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
99carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
100carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
101carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
102carg ::= DEFAULT NULL.
drh348784e2000-05-29 20:41:49 +0000103
104// In addition to the type name, we also care about the primary key.
105//
106ccons ::= NOT NULL.
drh6206d502000-06-19 19:09:08 +0000107ccons ::= PRIMARY KEY sortorder. {sqliteCreateIndex(pParse,0,0,0,0,0);}
drh348784e2000-05-29 20:41:49 +0000108ccons ::= UNIQUE.
drh4794b982000-06-06 13:54:14 +0000109ccons ::= CHECK LP expr RP.
drh348784e2000-05-29 20:41:49 +0000110
111// For the time being, the only constraint we care about is the primary
112// key.
113//
114conslist_opt ::= .
115conslist_opt ::= COMMA conslist.
116conslist ::= conslist COMMA tcons.
drha2e1bb52001-01-04 14:20:18 +0000117conslist ::= conslist tcons.
drh348784e2000-05-29 20:41:49 +0000118conslist ::= tcons.
drha2e1bb52001-01-04 14:20:18 +0000119tcons ::= CONSTRAINT id.
120tcons ::= PRIMARY KEY LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,0,0);}
121tcons ::= UNIQUE LP idlist RP.
122tcons ::= CHECK expr.
drh982cef72000-05-30 16:27:03 +0000123idlist ::= idlist COMMA id.
124idlist ::= id.
drh348784e2000-05-29 20:41:49 +0000125
126// The next command format is dropping tables.
127//
drh982cef72000-05-30 16:27:03 +0000128cmd ::= DROP TABLE id(X). {sqliteDropTable(pParse,&X);}
drh348784e2000-05-29 20:41:49 +0000129
130// The select statement
131//
drh9bb61fe2000-06-05 16:01:39 +0000132cmd ::= select(X). {
drhfef52082000-06-06 01:50:43 +0000133 sqliteSelect(pParse, X, SRT_Callback, 0);
drh9bb61fe2000-06-05 16:01:39 +0000134 sqliteSelectDelete(X);
135}
drhefb72512000-05-31 20:00:52 +0000136
drh9bb61fe2000-06-05 16:01:39 +0000137%type select {Select*}
138%destructor select {sqliteSelectDelete($$);}
drh82c3d632000-06-06 21:56:07 +0000139%type oneselect {Select*}
140%destructor oneselect {sqliteSelectDelete($$);}
drh9bb61fe2000-06-05 16:01:39 +0000141
drh82c3d632000-06-06 21:56:07 +0000142select(A) ::= oneselect(X). {A = X;}
143select(A) ::= select(X) joinop(Y) oneselect(Z). {
144 Z->op = Y;
145 Z->pPrior = X;
146 A = Z;
147}
148%type joinop {int}
149joinop(A) ::= UNION. {A = TK_UNION;}
150joinop(A) ::= UNION ALL. {A = TK_ALL;}
151joinop(A) ::= INTERSECT. {A = TK_INTERSECT;}
152joinop(A) ::= EXCEPT. {A = TK_EXCEPT;}
153oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
154 groupby_opt(P) having_opt(Q) orderby_opt(Z). {
drh22827922000-06-06 17:27:05 +0000155 A = sqliteSelectNew(W,X,Y,P,Q,Z,D);
drh9bb61fe2000-06-05 16:01:39 +0000156}
157
158// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
159// present and false (0) if it is not.
160//
drhefb72512000-05-31 20:00:52 +0000161%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000162distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000163distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000164distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000165
drh9bb61fe2000-06-05 16:01:39 +0000166// selcollist is a list of expressions that are to become the return
167// values of the SELECT statement. In the case of "SELECT * FROM ..."
168// the selcollist value is NULL.
169//
drh348784e2000-05-29 20:41:49 +0000170%type selcollist {ExprList*}
171%destructor selcollist {sqliteExprListDelete($$);}
172%type sclp {ExprList*}
173%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000174sclp(A) ::= selcollist(X) COMMA. {A = X;}
175sclp(A) ::= . {A = 0;}
drh9bb61fe2000-06-05 16:01:39 +0000176selcollist(A) ::= STAR. {A = 0;}
drh348784e2000-05-29 20:41:49 +0000177selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);}
drh4cfa7932000-06-08 15:10:46 +0000178selcollist(A) ::= sclp(P) expr(X) as id(Y). {A = sqliteExprListAppend(P,X,&Y);}
drh9bb61fe2000-06-05 16:01:39 +0000179as ::= .
180as ::= AS.
181
drh348784e2000-05-29 20:41:49 +0000182
183%type seltablist {IdList*}
184%destructor seltablist {sqliteIdListDelete($$);}
185%type stl_prefix {IdList*}
186%destructor stl_prefix {sqliteIdListDelete($$);}
187%type from {IdList*}
188%destructor from {sqliteIdListDelete($$);}
189
190from(A) ::= FROM seltablist(X). {A = X;}
191stl_prefix(A) ::= seltablist(X) COMMA. {A = X;}
192stl_prefix(A) ::= . {A = 0;}
drh982cef72000-05-30 16:27:03 +0000193seltablist(A) ::= stl_prefix(X) id(Y). {A = sqliteIdListAppend(X,&Y);}
drh6206d502000-06-19 19:09:08 +0000194seltablist(A) ::= stl_prefix(X) id(Y) as id(Z).
drh348784e2000-05-29 20:41:49 +0000195 {A = sqliteIdListAppend(X,&Y);
196 sqliteIdListAddAlias(A,&Z);}
197
198%type orderby_opt {ExprList*}
199%destructor orderby_opt {sqliteExprListDelete($$);}
200%type sortlist {ExprList*}
201%destructor sortlist {sqliteExprListDelete($$);}
202%type sortitem {Expr*}
203%destructor sortitem {sqliteExprDelete($$);}
204
205orderby_opt(A) ::= . {A = 0;}
206orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh9bb61fe2000-06-05 16:01:39 +0000207sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
208 A = sqliteExprListAppend(X,Y,0);
drhd8bc7082000-06-07 23:51:50 +0000209 A->a[A->nExpr-1].sortOrder = Z; /* 0 for ascending order, 1 for decending */
drh9bb61fe2000-06-05 16:01:39 +0000210}
211sortlist(A) ::= sortitem(Y) sortorder(Z). {
212 A = sqliteExprListAppend(0,Y,0);
drhd8bc7082000-06-07 23:51:50 +0000213 A->a[0].sortOrder = Z;
drh9bb61fe2000-06-05 16:01:39 +0000214}
drhda9d6c42000-05-31 18:20:14 +0000215sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000216
217%type sortorder {int}
218
219sortorder(A) ::= ASC. {A = 0;}
220sortorder(A) ::= DESC. {A = 1;}
221sortorder(A) ::= . {A = 0;}
222
drh22827922000-06-06 17:27:05 +0000223%type groupby_opt {ExprList*}
224%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000225groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000226groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
227
228%type having_opt {Expr*}
229%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000230having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000231having_opt(A) ::= HAVING expr(X). {A = X;}
232
drh82c3d632000-06-06 21:56:07 +0000233
drh4cfa7932000-06-08 15:10:46 +0000234cmd ::= DELETE FROM id(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000235 {sqliteDeleteFrom(pParse, &X, Y);}
236
237%type where_opt {Expr*}
238%destructor where_opt {sqliteExprDelete($$);}
239
240where_opt(A) ::= . {A = 0;}
241where_opt(A) ::= WHERE expr(X). {A = X;}
242
243%type setlist {ExprList*}
244%destructor setlist {sqliteExprListDelete($$);}
245
drh4cfa7932000-06-08 15:10:46 +0000246cmd ::= UPDATE id(X) SET setlist(Y) where_opt(Z).
drh348784e2000-05-29 20:41:49 +0000247 {sqliteUpdate(pParse,&X,Y,Z);}
248
drhed380d82000-08-01 09:56:27 +0000249setlist(A) ::= setlist(Z) COMMA id(X) EQ expr(Y).
drh348784e2000-05-29 20:41:49 +0000250 {A = sqliteExprListAppend(Z,Y,&X);}
drh4cfa7932000-06-08 15:10:46 +0000251setlist(A) ::= id(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000252
drh967e8b72000-06-21 13:59:10 +0000253cmd ::= INSERT INTO id(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
drh5974a302000-06-07 14:42:26 +0000254 {sqliteInsert(pParse, &X, Y, 0, F);}
drh967e8b72000-06-21 13:59:10 +0000255cmd ::= INSERT INTO id(X) inscollist_opt(F) select(S).
drh5974a302000-06-07 14:42:26 +0000256 {sqliteInsert(pParse, &X, 0, S, F);}
drh348784e2000-05-29 20:41:49 +0000257
258
259%type itemlist {ExprList*}
260%destructor itemlist {sqliteExprListDelete($$);}
261%type item {Expr*}
262%destructor item {sqliteExprDelete($$);}
263
264itemlist(A) ::= itemlist(X) COMMA item(Y). {A = sqliteExprListAppend(X,Y,0);}
265itemlist(A) ::= item(X). {A = sqliteExprListAppend(0,X,0);}
266item(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000267item(A) ::= PLUS INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
268item(A) ::= MINUS INTEGER(X). {
drh6e142f52000-06-08 13:36:40 +0000269 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
270 A->pLeft = sqliteExpr(TK_INTEGER, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000271}
drh348784e2000-05-29 20:41:49 +0000272item(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000273item(A) ::= PLUS FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
274item(A) ::= MINUS FLOAT(X). {
drh6e142f52000-06-08 13:36:40 +0000275 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
276 A->pLeft = sqliteExpr(TK_FLOAT, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000277}
drh348784e2000-05-29 20:41:49 +0000278item(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drh8be51132000-06-03 19:19:41 +0000279item(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);}
drh348784e2000-05-29 20:41:49 +0000280
drh967e8b72000-06-21 13:59:10 +0000281%type inscollist_opt {IdList*}
282%destructor inscollist_opt {sqliteIdListDelete($$);}
283%type inscollist {IdList*}
284%destructor inscollist {sqliteIdListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000285
drh967e8b72000-06-21 13:59:10 +0000286inscollist_opt(A) ::= . {A = 0;}
287inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
288inscollist(A) ::= inscollist(X) COMMA id(Y). {A = sqliteIdListAppend(X,&Y);}
289inscollist(A) ::= id(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000290
291%left OR.
292%left AND.
drh8be51132000-06-03 19:19:41 +0000293%right NOT.
drhfef52082000-06-06 01:50:43 +0000294%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000295%left GT GE LT LE.
296%left PLUS MINUS.
drh31884b02000-06-09 14:14:32 +0000297%left STAR SLASH.
drh00400772000-06-16 20:51:26 +0000298%left CONCAT.
drh8be51132000-06-03 19:19:41 +0000299%right UMINUS.
drh348784e2000-05-29 20:41:49 +0000300
301%type expr {Expr*}
302%destructor expr {sqliteExprDelete($$);}
303
drhe1b6a5b2000-07-29 13:06:59 +0000304expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
305expr(A) ::= ID(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
306expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
307expr(A) ::= id(X) DOT id(Y). {
308 Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
309 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
310 A = sqliteExpr(TK_DOT, temp1, temp2, 0);
311}
drh348784e2000-05-29 20:41:49 +0000312expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
313expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
314expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhe1b6a5b2000-07-29 13:06:59 +0000315expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
316 A = sqliteExprFunction(Y, &X);
317 sqliteExprSpan(A,&X,&E);
318}
319expr(A) ::= ID(X) LP STAR RP(E). {
320 A = sqliteExprFunction(0, &X);
321 sqliteExprSpan(A,&X,&E);
322}
drh348784e2000-05-29 20:41:49 +0000323expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
324expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
325expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
326expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
327expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
328expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
329expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
330expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drhdce2cbe2000-05-31 02:27:49 +0000331expr(A) ::= expr(X) LIKE expr(Y). {A = sqliteExpr(TK_LIKE, X, Y, 0);}
drh4794b982000-06-06 13:54:14 +0000332expr(A) ::= expr(X) NOT LIKE expr(Y). {
333 A = sqliteExpr(TK_LIKE, X, Y, 0);
334 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000335 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000336}
drhfef52082000-06-06 01:50:43 +0000337expr(A) ::= expr(X) GLOB expr(Y). {A = sqliteExpr(TK_GLOB,X,Y,0);}
drh4794b982000-06-06 13:54:14 +0000338expr(A) ::= expr(X) NOT GLOB expr(Y). {
339 A = sqliteExpr(TK_GLOB, X, Y, 0);
340 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000341 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000342}
drh348784e2000-05-29 20:41:49 +0000343expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
344expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
345expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
346expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000347expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drhe1b6a5b2000-07-29 13:06:59 +0000348expr(A) ::= expr(X) ISNULL(E). {
349 A = sqliteExpr(TK_ISNULL, X, 0, 0);
350 sqliteExprSpan(A,&X->span,&E);
351}
352expr(A) ::= expr(X) NOTNULL(E). {
353 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
354 sqliteExprSpan(A,&X->span,&E);
355}
356expr(A) ::= NOT(B) expr(X). {
357 A = sqliteExpr(TK_NOT, X, 0, 0);
358 sqliteExprSpan(A,&B,&X->span);
359}
360expr(A) ::= MINUS(B) expr(X). [UMINUS] {
361 A = sqliteExpr(TK_UMINUS, X, 0, 0);
362 sqliteExprSpan(A,&B,&X->span);
363}
364expr(A) ::= PLUS(B) expr(X). [UMINUS] {
365 A = X;
366 sqliteExprSpan(A,&B,&X->span);
367}
368expr(A) ::= LP(B) select(X) RP(E). {
drh19a775c2000-06-05 18:54:46 +0000369 A = sqliteExpr(TK_SELECT, 0, 0, 0);
370 A->pSelect = X;
drhe1b6a5b2000-07-29 13:06:59 +0000371 sqliteExprSpan(A,&B,&E);
drh19a775c2000-06-05 18:54:46 +0000372}
drhfef52082000-06-06 01:50:43 +0000373expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
374 ExprList *pList = sqliteExprListAppend(0, X, 0);
375 pList = sqliteExprListAppend(pList, Y, 0);
376 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
377 A->pList = pList;
drhe1b6a5b2000-07-29 13:06:59 +0000378 sqliteExprSpan(A,&W->span,&Y->span);
drhfef52082000-06-06 01:50:43 +0000379}
drh4794b982000-06-06 13:54:14 +0000380expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
381 ExprList *pList = sqliteExprListAppend(0, X, 0);
382 pList = sqliteExprListAppend(pList, Y, 0);
383 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
384 A->pList = pList;
385 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000386 sqliteExprSpan(A,&W->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000387}
drhe1b6a5b2000-07-29 13:06:59 +0000388expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000389 A = sqliteExpr(TK_IN, X, 0, 0);
390 A->pList = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000391 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000392}
drhe1b6a5b2000-07-29 13:06:59 +0000393expr(A) ::= expr(X) IN LP select(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000394 A = sqliteExpr(TK_IN, X, 0, 0);
395 A->pSelect = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000396 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000397}
drhe1b6a5b2000-07-29 13:06:59 +0000398expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000399 A = sqliteExpr(TK_IN, X, 0, 0);
400 A->pList = Y;
401 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000402 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000403}
drhe1b6a5b2000-07-29 13:06:59 +0000404expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000405 A = sqliteExpr(TK_IN, X, 0, 0);
406 A->pSelect = Y;
407 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000408 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000409}
drhfef52082000-06-06 01:50:43 +0000410
411
drh348784e2000-05-29 20:41:49 +0000412
413%type exprlist {ExprList*}
414%destructor exprlist {sqliteExprListDelete($$);}
415%type expritem {Expr*}
416%destructor expritem {sqliteExprDelete($$);}
417
drh348784e2000-05-29 20:41:49 +0000418exprlist(A) ::= exprlist(X) COMMA expritem(Y).
419 {A = sqliteExprListAppend(X,Y,0);}
420exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
421expritem(A) ::= expr(X). {A = X;}
422expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000423
drh348784e2000-05-29 20:41:49 +0000424
drh4cfa7932000-06-08 15:10:46 +0000425cmd ::= CREATE(S) uniqueflag INDEX id(X) ON id(Y) LP idxlist(Z) RP(E).
drh348784e2000-05-29 20:41:49 +0000426 {sqliteCreateIndex(pParse, &X, &Y, Z, &S, &E);}
427uniqueflag ::= UNIQUE.
428uniqueflag ::= .
429
430%type idxlist {IdList*}
431%destructor idxlist {sqliteIdListDelete($$);}
432%type idxitem {Token}
433
434idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
435 {A = sqliteIdListAppend(X,&Y);}
436idxlist(A) ::= idxitem(Y).
437 {A = sqliteIdListAppend(0,&Y);}
drh4cfa7932000-06-08 15:10:46 +0000438idxitem(A) ::= id(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000439
drh982cef72000-05-30 16:27:03 +0000440cmd ::= DROP INDEX id(X). {sqliteDropIndex(pParse, &X);}
441
442cmd ::= COPY id(X) FROM id(Y) USING DELIMITERS STRING(Z).
443 {sqliteCopy(pParse,&X,&Y,&Z);}
444cmd ::= COPY id(X) FROM id(Y).
445 {sqliteCopy(pParse,&X,&Y,0);}
drhdce2cbe2000-05-31 02:27:49 +0000446
447cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
448cmd ::= VACUUM id(X). {sqliteVacuum(pParse,&X);}