blob: 68c30214e60277cdcc9f8f4bac385042d64a1c45 [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**
drhc4a3c772001-04-04 11:48:57 +000029** @(#) $Id: parse.y,v 1.27 2001/04/04 11:48:58 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). {
173 Z->op = Y;
174 Z->pPrior = X;
175 A = Z;
176}
177%type joinop {int}
178joinop(A) ::= UNION. {A = TK_UNION;}
179joinop(A) ::= UNION ALL. {A = TK_ALL;}
180joinop(A) ::= INTERSECT. {A = TK_INTERSECT;}
181joinop(A) ::= EXCEPT. {A = TK_EXCEPT;}
182oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
183 groupby_opt(P) having_opt(Q) orderby_opt(Z). {
drh22827922000-06-06 17:27:05 +0000184 A = sqliteSelectNew(W,X,Y,P,Q,Z,D);
drh9bb61fe2000-06-05 16:01:39 +0000185}
186
187// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
188// present and false (0) if it is not.
189//
drhefb72512000-05-31 20:00:52 +0000190%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000191distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000192distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000193distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000194
drh9bb61fe2000-06-05 16:01:39 +0000195// selcollist is a list of expressions that are to become the return
196// values of the SELECT statement. In the case of "SELECT * FROM ..."
197// the selcollist value is NULL.
198//
drh348784e2000-05-29 20:41:49 +0000199%type selcollist {ExprList*}
200%destructor selcollist {sqliteExprListDelete($$);}
201%type sclp {ExprList*}
202%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000203sclp(A) ::= selcollist(X) COMMA. {A = X;}
204sclp(A) ::= . {A = 0;}
drh9bb61fe2000-06-05 16:01:39 +0000205selcollist(A) ::= STAR. {A = 0;}
drh348784e2000-05-29 20:41:49 +0000206selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);}
drhc4a3c772001-04-04 11:48:57 +0000207selcollist(A) ::= sclp(P) expr(X) as ids(Y). {A = sqliteExprListAppend(P,X,&Y);}
drh9bb61fe2000-06-05 16:01:39 +0000208as ::= .
209as ::= AS.
210
drh348784e2000-05-29 20:41:49 +0000211
212%type seltablist {IdList*}
213%destructor seltablist {sqliteIdListDelete($$);}
214%type stl_prefix {IdList*}
215%destructor stl_prefix {sqliteIdListDelete($$);}
216%type from {IdList*}
217%destructor from {sqliteIdListDelete($$);}
218
219from(A) ::= FROM seltablist(X). {A = X;}
220stl_prefix(A) ::= seltablist(X) COMMA. {A = X;}
221stl_prefix(A) ::= . {A = 0;}
drhc4a3c772001-04-04 11:48:57 +0000222seltablist(A) ::= stl_prefix(X) ids(Y). {A = sqliteIdListAppend(X,&Y);}
223seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). {
224 A = sqliteIdListAppend(X,&Y);
225 sqliteIdListAddAlias(A,&Z);
226}
drh348784e2000-05-29 20:41:49 +0000227
228%type orderby_opt {ExprList*}
229%destructor orderby_opt {sqliteExprListDelete($$);}
230%type sortlist {ExprList*}
231%destructor sortlist {sqliteExprListDelete($$);}
232%type sortitem {Expr*}
233%destructor sortitem {sqliteExprDelete($$);}
234
235orderby_opt(A) ::= . {A = 0;}
236orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh9bb61fe2000-06-05 16:01:39 +0000237sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
238 A = sqliteExprListAppend(X,Y,0);
drhd8bc7082000-06-07 23:51:50 +0000239 A->a[A->nExpr-1].sortOrder = Z; /* 0 for ascending order, 1 for decending */
drh9bb61fe2000-06-05 16:01:39 +0000240}
241sortlist(A) ::= sortitem(Y) sortorder(Z). {
242 A = sqliteExprListAppend(0,Y,0);
drhd8bc7082000-06-07 23:51:50 +0000243 A->a[0].sortOrder = Z;
drh9bb61fe2000-06-05 16:01:39 +0000244}
drhda9d6c42000-05-31 18:20:14 +0000245sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000246
247%type sortorder {int}
248
249sortorder(A) ::= ASC. {A = 0;}
250sortorder(A) ::= DESC. {A = 1;}
251sortorder(A) ::= . {A = 0;}
252
drh22827922000-06-06 17:27:05 +0000253%type groupby_opt {ExprList*}
254%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000255groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000256groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
257
258%type having_opt {Expr*}
259%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000260having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000261having_opt(A) ::= HAVING expr(X). {A = X;}
262
drh82c3d632000-06-06 21:56:07 +0000263
drhc4a3c772001-04-04 11:48:57 +0000264cmd ::= DELETE FROM ids(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000265 {sqliteDeleteFrom(pParse, &X, Y);}
266
267%type where_opt {Expr*}
268%destructor where_opt {sqliteExprDelete($$);}
269
270where_opt(A) ::= . {A = 0;}
271where_opt(A) ::= WHERE expr(X). {A = X;}
272
273%type setlist {ExprList*}
274%destructor setlist {sqliteExprListDelete($$);}
275
drhc4a3c772001-04-04 11:48:57 +0000276cmd ::= UPDATE ids(X) SET setlist(Y) where_opt(Z).
drh348784e2000-05-29 20:41:49 +0000277 {sqliteUpdate(pParse,&X,Y,Z);}
278
drhc4a3c772001-04-04 11:48:57 +0000279setlist(A) ::= setlist(Z) COMMA ids(X) EQ expr(Y).
drh348784e2000-05-29 20:41:49 +0000280 {A = sqliteExprListAppend(Z,Y,&X);}
drhc4a3c772001-04-04 11:48:57 +0000281setlist(A) ::= ids(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000282
drhc4a3c772001-04-04 11:48:57 +0000283cmd ::= INSERT INTO ids(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
drh5974a302000-06-07 14:42:26 +0000284 {sqliteInsert(pParse, &X, Y, 0, F);}
drhc4a3c772001-04-04 11:48:57 +0000285cmd ::= INSERT INTO ids(X) inscollist_opt(F) select(S).
drh5974a302000-06-07 14:42:26 +0000286 {sqliteInsert(pParse, &X, 0, S, F);}
drh348784e2000-05-29 20:41:49 +0000287
288
289%type itemlist {ExprList*}
290%destructor itemlist {sqliteExprListDelete($$);}
291%type item {Expr*}
292%destructor item {sqliteExprDelete($$);}
293
294itemlist(A) ::= itemlist(X) COMMA item(Y). {A = sqliteExprListAppend(X,Y,0);}
295itemlist(A) ::= item(X). {A = sqliteExprListAppend(0,X,0);}
296item(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000297item(A) ::= PLUS INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
298item(A) ::= MINUS INTEGER(X). {
drh6e142f52000-06-08 13:36:40 +0000299 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
300 A->pLeft = sqliteExpr(TK_INTEGER, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000301}
drh348784e2000-05-29 20:41:49 +0000302item(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000303item(A) ::= PLUS FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
304item(A) ::= MINUS FLOAT(X). {
drh6e142f52000-06-08 13:36:40 +0000305 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
306 A->pLeft = sqliteExpr(TK_FLOAT, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000307}
drh348784e2000-05-29 20:41:49 +0000308item(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drh8be51132000-06-03 19:19:41 +0000309item(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);}
drh348784e2000-05-29 20:41:49 +0000310
drh967e8b72000-06-21 13:59:10 +0000311%type inscollist_opt {IdList*}
312%destructor inscollist_opt {sqliteIdListDelete($$);}
313%type inscollist {IdList*}
314%destructor inscollist {sqliteIdListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000315
drhc4a3c772001-04-04 11:48:57 +0000316inscollist_opt(A) ::= . {A = 0;}
317inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
318inscollist(A) ::= inscollist(X) COMMA ids(Y). {A = sqliteIdListAppend(X,&Y);}
319inscollist(A) ::= ids(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000320
321%left OR.
322%left AND.
drh8be51132000-06-03 19:19:41 +0000323%right NOT.
drhfef52082000-06-06 01:50:43 +0000324%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000325%left GT GE LT LE.
326%left PLUS MINUS.
drh31884b02000-06-09 14:14:32 +0000327%left STAR SLASH.
drh00400772000-06-16 20:51:26 +0000328%left CONCAT.
drh8be51132000-06-03 19:19:41 +0000329%right UMINUS.
drh348784e2000-05-29 20:41:49 +0000330
331%type expr {Expr*}
332%destructor expr {sqliteExprDelete($$);}
333
drhe1b6a5b2000-07-29 13:06:59 +0000334expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
drhe1b6a5b2000-07-29 13:06:59 +0000335expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
drhc4a3c772001-04-04 11:48:57 +0000336expr(A) ::= id(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
337expr(A) ::= ids(X) DOT ids(Y). {
drhe1b6a5b2000-07-29 13:06:59 +0000338 Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
339 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
340 A = sqliteExpr(TK_DOT, temp1, temp2, 0);
341}
drh348784e2000-05-29 20:41:49 +0000342expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
343expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
344expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhe1b6a5b2000-07-29 13:06:59 +0000345expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
346 A = sqliteExprFunction(Y, &X);
347 sqliteExprSpan(A,&X,&E);
348}
349expr(A) ::= ID(X) LP STAR RP(E). {
350 A = sqliteExprFunction(0, &X);
351 sqliteExprSpan(A,&X,&E);
352}
drh348784e2000-05-29 20:41:49 +0000353expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
354expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
355expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
356expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
357expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
358expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
359expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
360expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drhdce2cbe2000-05-31 02:27:49 +0000361expr(A) ::= expr(X) LIKE expr(Y). {A = sqliteExpr(TK_LIKE, X, Y, 0);}
drh4794b982000-06-06 13:54:14 +0000362expr(A) ::= expr(X) NOT LIKE expr(Y). {
363 A = sqliteExpr(TK_LIKE, X, Y, 0);
364 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000365 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000366}
drhfef52082000-06-06 01:50:43 +0000367expr(A) ::= expr(X) GLOB expr(Y). {A = sqliteExpr(TK_GLOB,X,Y,0);}
drh4794b982000-06-06 13:54:14 +0000368expr(A) ::= expr(X) NOT GLOB expr(Y). {
369 A = sqliteExpr(TK_GLOB, X, Y, 0);
370 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000371 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000372}
drh348784e2000-05-29 20:41:49 +0000373expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
374expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
375expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
376expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000377expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drhe1b6a5b2000-07-29 13:06:59 +0000378expr(A) ::= expr(X) ISNULL(E). {
379 A = sqliteExpr(TK_ISNULL, X, 0, 0);
380 sqliteExprSpan(A,&X->span,&E);
381}
382expr(A) ::= expr(X) NOTNULL(E). {
383 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
384 sqliteExprSpan(A,&X->span,&E);
385}
386expr(A) ::= NOT(B) expr(X). {
387 A = sqliteExpr(TK_NOT, X, 0, 0);
388 sqliteExprSpan(A,&B,&X->span);
389}
390expr(A) ::= MINUS(B) expr(X). [UMINUS] {
391 A = sqliteExpr(TK_UMINUS, X, 0, 0);
392 sqliteExprSpan(A,&B,&X->span);
393}
394expr(A) ::= PLUS(B) expr(X). [UMINUS] {
395 A = X;
396 sqliteExprSpan(A,&B,&X->span);
397}
398expr(A) ::= LP(B) select(X) RP(E). {
drh19a775c2000-06-05 18:54:46 +0000399 A = sqliteExpr(TK_SELECT, 0, 0, 0);
400 A->pSelect = X;
drhe1b6a5b2000-07-29 13:06:59 +0000401 sqliteExprSpan(A,&B,&E);
drh19a775c2000-06-05 18:54:46 +0000402}
drhfef52082000-06-06 01:50:43 +0000403expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
404 ExprList *pList = sqliteExprListAppend(0, X, 0);
405 pList = sqliteExprListAppend(pList, Y, 0);
406 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
407 A->pList = pList;
drhe1b6a5b2000-07-29 13:06:59 +0000408 sqliteExprSpan(A,&W->span,&Y->span);
drhfef52082000-06-06 01:50:43 +0000409}
drh4794b982000-06-06 13:54:14 +0000410expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
411 ExprList *pList = sqliteExprListAppend(0, X, 0);
412 pList = sqliteExprListAppend(pList, Y, 0);
413 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
414 A->pList = pList;
415 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000416 sqliteExprSpan(A,&W->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000417}
drhe1b6a5b2000-07-29 13:06:59 +0000418expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000419 A = sqliteExpr(TK_IN, X, 0, 0);
420 A->pList = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000421 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000422}
drhe1b6a5b2000-07-29 13:06:59 +0000423expr(A) ::= expr(X) IN LP select(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000424 A = sqliteExpr(TK_IN, X, 0, 0);
425 A->pSelect = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000426 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000427}
drhe1b6a5b2000-07-29 13:06:59 +0000428expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000429 A = sqliteExpr(TK_IN, X, 0, 0);
430 A->pList = Y;
431 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000432 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000433}
drhe1b6a5b2000-07-29 13:06:59 +0000434expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000435 A = sqliteExpr(TK_IN, X, 0, 0);
436 A->pSelect = Y;
437 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000438 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000439}
drhfef52082000-06-06 01:50:43 +0000440
441
drh348784e2000-05-29 20:41:49 +0000442
443%type exprlist {ExprList*}
444%destructor exprlist {sqliteExprListDelete($$);}
445%type expritem {Expr*}
446%destructor expritem {sqliteExprDelete($$);}
447
drh348784e2000-05-29 20:41:49 +0000448exprlist(A) ::= exprlist(X) COMMA expritem(Y).
449 {A = sqliteExprListAppend(X,Y,0);}
450exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
451expritem(A) ::= expr(X). {A = X;}
452expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000453
drh348784e2000-05-29 20:41:49 +0000454
drhc4a3c772001-04-04 11:48:57 +0000455cmd ::= CREATE(S) uniqueflag INDEX ids(X) ON ids(Y) LP idxlist(Z) RP(E).
drh348784e2000-05-29 20:41:49 +0000456 {sqliteCreateIndex(pParse, &X, &Y, Z, &S, &E);}
457uniqueflag ::= UNIQUE.
458uniqueflag ::= .
459
460%type idxlist {IdList*}
461%destructor idxlist {sqliteIdListDelete($$);}
462%type idxitem {Token}
463
464idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
465 {A = sqliteIdListAppend(X,&Y);}
466idxlist(A) ::= idxitem(Y).
467 {A = sqliteIdListAppend(0,&Y);}
drhc4a3c772001-04-04 11:48:57 +0000468idxitem(A) ::= ids(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000469
drhc4a3c772001-04-04 11:48:57 +0000470cmd ::= DROP INDEX ids(X). {sqliteDropIndex(pParse, &X);}
drh982cef72000-05-30 16:27:03 +0000471
drhc4a3c772001-04-04 11:48:57 +0000472cmd ::= COPY ids(X) FROM ids(Y) USING DELIMITERS STRING(Z).
drh982cef72000-05-30 16:27:03 +0000473 {sqliteCopy(pParse,&X,&Y,&Z);}
drhc4a3c772001-04-04 11:48:57 +0000474cmd ::= COPY ids(X) FROM ids(Y).
drh982cef72000-05-30 16:27:03 +0000475 {sqliteCopy(pParse,&X,&Y,0);}
drhdce2cbe2000-05-31 02:27:49 +0000476
477cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
drhc4a3c772001-04-04 11:48:57 +0000478cmd ::= VACUUM ids(X). {sqliteVacuum(pParse,&X);}