blob: 1049150f6df3b253e713fdbc2934b8a1dba6f014 [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**
drhdaffd0e2001-04-11 14:28:42 +000029** @(#) $Id: parse.y,v 1.28 2001/04/11 14:28:42 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
drh348784e2000-05-29 20:41:49 +000044// These are extra tokens used by the lexer but never seen by the
45// parser. We put them in a rule so that the parser generator will
drh6206d502000-06-19 19:09:08 +000046// add them to the parse.h output file.
drh348784e2000-05-29 20:41:49 +000047//
drhc4a3c772001-04-04 11:48:57 +000048%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
49 COLUMN AGG_FUNCTION.
50
51// Input is zero or more commands.
52input ::= cmdlist.
drh348784e2000-05-29 20:41:49 +000053
54// A list of commands is zero or more commands
55//
56cmdlist ::= ecmd.
57cmdlist ::= cmdlist SEMI ecmd.
58ecmd ::= explain cmd. {sqliteExec(pParse);}
59ecmd ::= cmd. {sqliteExec(pParse);}
60ecmd ::= .
61explain ::= EXPLAIN. {pParse->explain = 1;}
62
drhc4a3c772001-04-04 11:48:57 +000063// Begin and end transactions. Transaction support is sparse.
64// Some backends support only COMMIT and not ROLLBACK. There can
65// be only a single active transaction at a time.
66//
67cmd ::= BEGIN trans_opt. {sqliteBeginTransaction(pParse);}
68trans_opt ::= .
69trans_opt ::= TRANSACTION.
70trans_opt ::= TRANSACTION ids.
71cmd ::= COMMIT trans_opt. {sqliteCommitTransaction(pParse);}
72cmd ::= END trans_opt. {sqliteCommitTransaction(pParse);}
73cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);}
74
drh348784e2000-05-29 20:41:49 +000075// The first form of a command is a CREATE TABLE statement.
76//
77cmd ::= create_table create_table_args.
drhc4a3c772001-04-04 11:48:57 +000078create_table ::= CREATE(X) TABLE ids(Y). {sqliteStartTable(pParse,&X,&Y);}
drh348784e2000-05-29 20:41:49 +000079create_table_args ::= LP columnlist conslist_opt RP(X).
80 {sqliteEndTable(pParse,&X);}
81columnlist ::= columnlist COMMA column.
82columnlist ::= column.
83
84// About the only information used for a column is the name of the
85// column. The type is always just "text". But the code will accept
86// an elaborate typename. Perhaps someday we'll do something with it.
87//
88column ::= columnid type carglist.
drhc4a3c772001-04-04 11:48:57 +000089columnid ::= ids(X). {sqliteAddColumn(pParse,&X);}
90
91// An IDENTIFIER can be a generic identifier, or one of several
92// keywords. Any non-standard keyword can also be an identifier.
93// We also make DESC and identifier since it comes up so often.
94//
drh982cef72000-05-30 16:27:03 +000095%type id {Token}
drhc4a3c772001-04-04 11:48:57 +000096id(A) ::= DESC(X). {A = X;}
97id(A) ::= ASC(X). {A = X;}
98id(A) ::= DELIMITERS(X). {A = X;}
99id(A) ::= EXPLAIN(X). {A = X;}
100id(A) ::= VACUUM(X). {A = X;}
101id(A) ::= BEGIN(X). {A = X;}
102id(A) ::= END(X). {A = X;}
103id(A) ::= ID(X). {A = X;}
104
105// And "ids" is an identifer-or-string.
106//
107%type ids {Token}
108ids(A) ::= id(X). {A = X;}
109ids(A) ::= STRING(X). {A = X;}
110
drh348784e2000-05-29 20:41:49 +0000111type ::= typename.
112type ::= typename LP signed RP.
113type ::= typename LP signed COMMA signed RP.
drhc4a3c772001-04-04 11:48:57 +0000114typename ::= ids.
115typename ::= typename ids.
drh348784e2000-05-29 20:41:49 +0000116signed ::= INTEGER.
117signed ::= PLUS INTEGER.
118signed ::= MINUS INTEGER.
119carglist ::= carglist carg.
120carglist ::= .
drhc4a3c772001-04-04 11:48:57 +0000121carg ::= CONSTRAINT ids ccons.
drh348784e2000-05-29 20:41:49 +0000122carg ::= ccons.
drh7020f652000-06-03 18:06:52 +0000123carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
124carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
125carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
126carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
127carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
128carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
129carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
130carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
131carg ::= DEFAULT NULL.
drh348784e2000-05-29 20:41:49 +0000132
133// In addition to the type name, we also care about the primary key.
134//
135ccons ::= NOT NULL.
drh6206d502000-06-19 19:09:08 +0000136ccons ::= PRIMARY KEY sortorder. {sqliteCreateIndex(pParse,0,0,0,0,0);}
drh348784e2000-05-29 20:41:49 +0000137ccons ::= UNIQUE.
drh4794b982000-06-06 13:54:14 +0000138ccons ::= CHECK LP expr RP.
drh348784e2000-05-29 20:41:49 +0000139
140// For the time being, the only constraint we care about is the primary
141// key.
142//
143conslist_opt ::= .
144conslist_opt ::= COMMA conslist.
145conslist ::= conslist COMMA tcons.
drha2e1bb52001-01-04 14:20:18 +0000146conslist ::= conslist tcons.
drh348784e2000-05-29 20:41:49 +0000147conslist ::= tcons.
drhc4a3c772001-04-04 11:48:57 +0000148tcons ::= CONSTRAINT ids.
drha2e1bb52001-01-04 14:20:18 +0000149tcons ::= PRIMARY KEY LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,0,0);}
150tcons ::= UNIQUE LP idlist RP.
151tcons ::= CHECK expr.
drhc4a3c772001-04-04 11:48:57 +0000152idlist ::= idlist COMMA ids.
153idlist ::= ids.
drh348784e2000-05-29 20:41:49 +0000154
155// The next command format is dropping tables.
156//
drhc4a3c772001-04-04 11:48:57 +0000157cmd ::= DROP TABLE ids(X). {sqliteDropTable(pParse,&X);}
drh348784e2000-05-29 20:41:49 +0000158
159// The select statement
160//
drh9bb61fe2000-06-05 16:01:39 +0000161cmd ::= select(X). {
drhfef52082000-06-06 01:50:43 +0000162 sqliteSelect(pParse, X, SRT_Callback, 0);
drh9bb61fe2000-06-05 16:01:39 +0000163 sqliteSelectDelete(X);
164}
drhefb72512000-05-31 20:00:52 +0000165
drh9bb61fe2000-06-05 16:01:39 +0000166%type select {Select*}
167%destructor select {sqliteSelectDelete($$);}
drh82c3d632000-06-06 21:56:07 +0000168%type oneselect {Select*}
169%destructor oneselect {sqliteSelectDelete($$);}
drh9bb61fe2000-06-05 16:01:39 +0000170
drh82c3d632000-06-06 21:56:07 +0000171select(A) ::= oneselect(X). {A = X;}
172select(A) ::= select(X) joinop(Y) oneselect(Z). {
drhdaffd0e2001-04-11 14:28:42 +0000173 if( Z ){
drh82c3d632000-06-06 21:56:07 +0000174 Z->op = Y;
175 Z->pPrior = X;
drhdaffd0e2001-04-11 14:28:42 +0000176 }
177 A = Z;
drh82c3d632000-06-06 21:56:07 +0000178}
179%type joinop {int}
180joinop(A) ::= UNION. {A = TK_UNION;}
181joinop(A) ::= UNION ALL. {A = TK_ALL;}
182joinop(A) ::= INTERSECT. {A = TK_INTERSECT;}
183joinop(A) ::= EXCEPT. {A = TK_EXCEPT;}
184oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
185 groupby_opt(P) having_opt(Q) orderby_opt(Z). {
drh22827922000-06-06 17:27:05 +0000186 A = sqliteSelectNew(W,X,Y,P,Q,Z,D);
drh9bb61fe2000-06-05 16:01:39 +0000187}
188
189// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
190// present and false (0) if it is not.
191//
drhefb72512000-05-31 20:00:52 +0000192%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000193distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000194distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000195distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000196
drh9bb61fe2000-06-05 16:01:39 +0000197// selcollist is a list of expressions that are to become the return
198// values of the SELECT statement. In the case of "SELECT * FROM ..."
199// the selcollist value is NULL.
200//
drh348784e2000-05-29 20:41:49 +0000201%type selcollist {ExprList*}
202%destructor selcollist {sqliteExprListDelete($$);}
203%type sclp {ExprList*}
204%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000205sclp(A) ::= selcollist(X) COMMA. {A = X;}
206sclp(A) ::= . {A = 0;}
drh9bb61fe2000-06-05 16:01:39 +0000207selcollist(A) ::= STAR. {A = 0;}
drh348784e2000-05-29 20:41:49 +0000208selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);}
drhc4a3c772001-04-04 11:48:57 +0000209selcollist(A) ::= sclp(P) expr(X) as ids(Y). {A = sqliteExprListAppend(P,X,&Y);}
drh9bb61fe2000-06-05 16:01:39 +0000210as ::= .
211as ::= AS.
212
drh348784e2000-05-29 20:41:49 +0000213
214%type seltablist {IdList*}
215%destructor seltablist {sqliteIdListDelete($$);}
216%type stl_prefix {IdList*}
217%destructor stl_prefix {sqliteIdListDelete($$);}
218%type from {IdList*}
219%destructor from {sqliteIdListDelete($$);}
220
221from(A) ::= FROM seltablist(X). {A = X;}
222stl_prefix(A) ::= seltablist(X) COMMA. {A = X;}
223stl_prefix(A) ::= . {A = 0;}
drhc4a3c772001-04-04 11:48:57 +0000224seltablist(A) ::= stl_prefix(X) ids(Y). {A = sqliteIdListAppend(X,&Y);}
225seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). {
226 A = sqliteIdListAppend(X,&Y);
227 sqliteIdListAddAlias(A,&Z);
228}
drh348784e2000-05-29 20:41:49 +0000229
230%type orderby_opt {ExprList*}
231%destructor orderby_opt {sqliteExprListDelete($$);}
232%type sortlist {ExprList*}
233%destructor sortlist {sqliteExprListDelete($$);}
234%type sortitem {Expr*}
235%destructor sortitem {sqliteExprDelete($$);}
236
237orderby_opt(A) ::= . {A = 0;}
238orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh9bb61fe2000-06-05 16:01:39 +0000239sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
240 A = sqliteExprListAppend(X,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000241 if( A ) A->a[A->nExpr-1].sortOrder = Z; /* 0=ascending, 1=decending */
drh9bb61fe2000-06-05 16:01:39 +0000242}
243sortlist(A) ::= sortitem(Y) sortorder(Z). {
244 A = sqliteExprListAppend(0,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000245 if( A ) A->a[0].sortOrder = Z;
drh9bb61fe2000-06-05 16:01:39 +0000246}
drhda9d6c42000-05-31 18:20:14 +0000247sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000248
249%type sortorder {int}
250
251sortorder(A) ::= ASC. {A = 0;}
252sortorder(A) ::= DESC. {A = 1;}
253sortorder(A) ::= . {A = 0;}
254
drh22827922000-06-06 17:27:05 +0000255%type groupby_opt {ExprList*}
256%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000257groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000258groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
259
260%type having_opt {Expr*}
261%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000262having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000263having_opt(A) ::= HAVING expr(X). {A = X;}
264
drh82c3d632000-06-06 21:56:07 +0000265
drhc4a3c772001-04-04 11:48:57 +0000266cmd ::= DELETE FROM ids(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000267 {sqliteDeleteFrom(pParse, &X, Y);}
268
269%type where_opt {Expr*}
270%destructor where_opt {sqliteExprDelete($$);}
271
272where_opt(A) ::= . {A = 0;}
273where_opt(A) ::= WHERE expr(X). {A = X;}
274
275%type setlist {ExprList*}
276%destructor setlist {sqliteExprListDelete($$);}
277
drhc4a3c772001-04-04 11:48:57 +0000278cmd ::= UPDATE ids(X) SET setlist(Y) where_opt(Z).
drh348784e2000-05-29 20:41:49 +0000279 {sqliteUpdate(pParse,&X,Y,Z);}
280
drhc4a3c772001-04-04 11:48:57 +0000281setlist(A) ::= setlist(Z) COMMA ids(X) EQ expr(Y).
drh348784e2000-05-29 20:41:49 +0000282 {A = sqliteExprListAppend(Z,Y,&X);}
drhc4a3c772001-04-04 11:48:57 +0000283setlist(A) ::= ids(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000284
drhc4a3c772001-04-04 11:48:57 +0000285cmd ::= INSERT INTO ids(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
drh5974a302000-06-07 14:42:26 +0000286 {sqliteInsert(pParse, &X, Y, 0, F);}
drhc4a3c772001-04-04 11:48:57 +0000287cmd ::= INSERT INTO ids(X) inscollist_opt(F) select(S).
drh5974a302000-06-07 14:42:26 +0000288 {sqliteInsert(pParse, &X, 0, S, F);}
drh348784e2000-05-29 20:41:49 +0000289
290
291%type itemlist {ExprList*}
292%destructor itemlist {sqliteExprListDelete($$);}
293%type item {Expr*}
294%destructor item {sqliteExprDelete($$);}
295
296itemlist(A) ::= itemlist(X) COMMA item(Y). {A = sqliteExprListAppend(X,Y,0);}
297itemlist(A) ::= item(X). {A = sqliteExprListAppend(0,X,0);}
298item(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000299item(A) ::= PLUS INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
300item(A) ::= MINUS INTEGER(X). {
drh6e142f52000-06-08 13:36:40 +0000301 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000302 if( A ) A->pLeft = sqliteExpr(TK_INTEGER, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000303}
drh348784e2000-05-29 20:41:49 +0000304item(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000305item(A) ::= PLUS FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
306item(A) ::= MINUS FLOAT(X). {
drh6e142f52000-06-08 13:36:40 +0000307 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000308 if( A ) A->pLeft = sqliteExpr(TK_FLOAT, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000309}
drh348784e2000-05-29 20:41:49 +0000310item(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drh8be51132000-06-03 19:19:41 +0000311item(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);}
drh348784e2000-05-29 20:41:49 +0000312
drh967e8b72000-06-21 13:59:10 +0000313%type inscollist_opt {IdList*}
314%destructor inscollist_opt {sqliteIdListDelete($$);}
315%type inscollist {IdList*}
316%destructor inscollist {sqliteIdListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000317
drhc4a3c772001-04-04 11:48:57 +0000318inscollist_opt(A) ::= . {A = 0;}
319inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
320inscollist(A) ::= inscollist(X) COMMA ids(Y). {A = sqliteIdListAppend(X,&Y);}
321inscollist(A) ::= ids(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000322
323%left OR.
324%left AND.
drh8be51132000-06-03 19:19:41 +0000325%right NOT.
drhfef52082000-06-06 01:50:43 +0000326%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000327%left GT GE LT LE.
328%left PLUS MINUS.
drh31884b02000-06-09 14:14:32 +0000329%left STAR SLASH.
drh00400772000-06-16 20:51:26 +0000330%left CONCAT.
drh8be51132000-06-03 19:19:41 +0000331%right UMINUS.
drh348784e2000-05-29 20:41:49 +0000332
333%type expr {Expr*}
334%destructor expr {sqliteExprDelete($$);}
335
drhe1b6a5b2000-07-29 13:06:59 +0000336expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
drhe1b6a5b2000-07-29 13:06:59 +0000337expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
drhc4a3c772001-04-04 11:48:57 +0000338expr(A) ::= id(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
339expr(A) ::= ids(X) DOT ids(Y). {
drhe1b6a5b2000-07-29 13:06:59 +0000340 Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
341 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
342 A = sqliteExpr(TK_DOT, temp1, temp2, 0);
343}
drh348784e2000-05-29 20:41:49 +0000344expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
345expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
346expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhe1b6a5b2000-07-29 13:06:59 +0000347expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
348 A = sqliteExprFunction(Y, &X);
349 sqliteExprSpan(A,&X,&E);
350}
351expr(A) ::= ID(X) LP STAR RP(E). {
352 A = sqliteExprFunction(0, &X);
353 sqliteExprSpan(A,&X,&E);
354}
drh348784e2000-05-29 20:41:49 +0000355expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
356expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
357expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
358expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
359expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
360expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
361expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
362expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drhdce2cbe2000-05-31 02:27:49 +0000363expr(A) ::= expr(X) LIKE expr(Y). {A = sqliteExpr(TK_LIKE, X, Y, 0);}
drh4794b982000-06-06 13:54:14 +0000364expr(A) ::= expr(X) NOT LIKE expr(Y). {
365 A = sqliteExpr(TK_LIKE, X, Y, 0);
366 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000367 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000368}
drhfef52082000-06-06 01:50:43 +0000369expr(A) ::= expr(X) GLOB expr(Y). {A = sqliteExpr(TK_GLOB,X,Y,0);}
drh4794b982000-06-06 13:54:14 +0000370expr(A) ::= expr(X) NOT GLOB expr(Y). {
371 A = sqliteExpr(TK_GLOB, X, Y, 0);
372 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000373 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000374}
drh348784e2000-05-29 20:41:49 +0000375expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
376expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
377expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
378expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000379expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drhe1b6a5b2000-07-29 13:06:59 +0000380expr(A) ::= expr(X) ISNULL(E). {
381 A = sqliteExpr(TK_ISNULL, X, 0, 0);
382 sqliteExprSpan(A,&X->span,&E);
383}
384expr(A) ::= expr(X) NOTNULL(E). {
385 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
386 sqliteExprSpan(A,&X->span,&E);
387}
388expr(A) ::= NOT(B) expr(X). {
389 A = sqliteExpr(TK_NOT, X, 0, 0);
390 sqliteExprSpan(A,&B,&X->span);
391}
392expr(A) ::= MINUS(B) expr(X). [UMINUS] {
393 A = sqliteExpr(TK_UMINUS, X, 0, 0);
394 sqliteExprSpan(A,&B,&X->span);
395}
396expr(A) ::= PLUS(B) expr(X). [UMINUS] {
397 A = X;
398 sqliteExprSpan(A,&B,&X->span);
399}
400expr(A) ::= LP(B) select(X) RP(E). {
drh19a775c2000-06-05 18:54:46 +0000401 A = sqliteExpr(TK_SELECT, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000402 if( A ) A->pSelect = X;
drhe1b6a5b2000-07-29 13:06:59 +0000403 sqliteExprSpan(A,&B,&E);
drh19a775c2000-06-05 18:54:46 +0000404}
drhfef52082000-06-06 01:50:43 +0000405expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
406 ExprList *pList = sqliteExprListAppend(0, X, 0);
407 pList = sqliteExprListAppend(pList, Y, 0);
408 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000409 if( A ) A->pList = pList;
drhe1b6a5b2000-07-29 13:06:59 +0000410 sqliteExprSpan(A,&W->span,&Y->span);
drhfef52082000-06-06 01:50:43 +0000411}
drh4794b982000-06-06 13:54:14 +0000412expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
413 ExprList *pList = sqliteExprListAppend(0, X, 0);
414 pList = sqliteExprListAppend(pList, Y, 0);
415 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000416 if( A ) A->pList = pList;
drh4794b982000-06-06 13:54:14 +0000417 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000418 sqliteExprSpan(A,&W->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000419}
drhe1b6a5b2000-07-29 13:06:59 +0000420expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000421 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000422 if( A ) A->pList = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000423 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000424}
drhe1b6a5b2000-07-29 13:06:59 +0000425expr(A) ::= expr(X) IN LP select(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000426 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000427 if( A ) A->pSelect = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000428 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000429}
drhe1b6a5b2000-07-29 13:06:59 +0000430expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000431 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000432 if( A ) A->pList = Y;
drh4794b982000-06-06 13:54:14 +0000433 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000434 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000435}
drhe1b6a5b2000-07-29 13:06:59 +0000436expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000437 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000438 if( A ) A->pSelect = Y;
drh4794b982000-06-06 13:54:14 +0000439 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000440 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000441}
drhfef52082000-06-06 01:50:43 +0000442
443
drh348784e2000-05-29 20:41:49 +0000444
445%type exprlist {ExprList*}
446%destructor exprlist {sqliteExprListDelete($$);}
447%type expritem {Expr*}
448%destructor expritem {sqliteExprDelete($$);}
449
drh348784e2000-05-29 20:41:49 +0000450exprlist(A) ::= exprlist(X) COMMA expritem(Y).
451 {A = sqliteExprListAppend(X,Y,0);}
452exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
453expritem(A) ::= expr(X). {A = X;}
454expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000455
drh348784e2000-05-29 20:41:49 +0000456
drhc4a3c772001-04-04 11:48:57 +0000457cmd ::= CREATE(S) uniqueflag INDEX ids(X) ON ids(Y) LP idxlist(Z) RP(E).
drh348784e2000-05-29 20:41:49 +0000458 {sqliteCreateIndex(pParse, &X, &Y, Z, &S, &E);}
459uniqueflag ::= UNIQUE.
460uniqueflag ::= .
461
462%type idxlist {IdList*}
463%destructor idxlist {sqliteIdListDelete($$);}
464%type idxitem {Token}
465
466idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
467 {A = sqliteIdListAppend(X,&Y);}
468idxlist(A) ::= idxitem(Y).
469 {A = sqliteIdListAppend(0,&Y);}
drhc4a3c772001-04-04 11:48:57 +0000470idxitem(A) ::= ids(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000471
drhc4a3c772001-04-04 11:48:57 +0000472cmd ::= DROP INDEX ids(X). {sqliteDropIndex(pParse, &X);}
drh982cef72000-05-30 16:27:03 +0000473
drhc4a3c772001-04-04 11:48:57 +0000474cmd ::= COPY ids(X) FROM ids(Y) USING DELIMITERS STRING(Z).
drh982cef72000-05-30 16:27:03 +0000475 {sqliteCopy(pParse,&X,&Y,&Z);}
drhc4a3c772001-04-04 11:48:57 +0000476cmd ::= COPY ids(X) FROM ids(Y).
drh982cef72000-05-30 16:27:03 +0000477 {sqliteCopy(pParse,&X,&Y,0);}
drhdce2cbe2000-05-31 02:27:49 +0000478
479cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
drhc4a3c772001-04-04 11:48:57 +0000480cmd ::= VACUUM ids(X). {sqliteVacuum(pParse,&X);}