blob: 373497d350ed0bf0fcbdaaea912d9741ad9e9466 [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**
drhf57b14a2001-09-14 18:54:08 +000029** @(#) $Id: parse.y,v 1.29 2001/09/14 18:54:09 drh Exp $
drh348784e2000-05-29 20:41:49 +000030*/
31%token_prefix TK_
32%token_type {Token}
drhf57b14a2001-09-14 18:54:08 +000033%default_type {Token}
drh348784e2000-05-29 20:41:49 +000034%extra_argument {Parse *pParse}
35%syntax_error {
drhc837e702000-06-08 16:26:24 +000036 sqliteSetString(&pParse->zErrMsg,"syntax error",0);
drh348784e2000-05-29 20:41:49 +000037 pParse->sErrToken = TOKEN;
38}
39%name sqliteParser
40%include {
41#include "sqliteInt.h"
42#include "parse.h"
43}
44
drh348784e2000-05-29 20:41:49 +000045// These are extra tokens used by the lexer but never seen by the
46// parser. We put them in a rule so that the parser generator will
drh6206d502000-06-19 19:09:08 +000047// add them to the parse.h output file.
drh348784e2000-05-29 20:41:49 +000048//
drhc4a3c772001-04-04 11:48:57 +000049%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
50 COLUMN AGG_FUNCTION.
51
52// Input is zero or more commands.
53input ::= cmdlist.
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
drhc4a3c772001-04-04 11:48:57 +000064// Begin and end transactions. Transaction support is sparse.
65// Some backends support only COMMIT and not ROLLBACK. There can
66// be only a single active transaction at a time.
67//
68cmd ::= BEGIN trans_opt. {sqliteBeginTransaction(pParse);}
69trans_opt ::= .
70trans_opt ::= TRANSACTION.
71trans_opt ::= TRANSACTION ids.
72cmd ::= COMMIT trans_opt. {sqliteCommitTransaction(pParse);}
73cmd ::= END trans_opt. {sqliteCommitTransaction(pParse);}
74cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);}
75
drh348784e2000-05-29 20:41:49 +000076// The first form of a command is a CREATE TABLE statement.
77//
78cmd ::= create_table create_table_args.
drhc4a3c772001-04-04 11:48:57 +000079create_table ::= CREATE(X) TABLE ids(Y). {sqliteStartTable(pParse,&X,&Y);}
drh348784e2000-05-29 20:41:49 +000080create_table_args ::= LP columnlist conslist_opt RP(X).
81 {sqliteEndTable(pParse,&X);}
82columnlist ::= columnlist COMMA column.
83columnlist ::= column.
84
85// About the only information used for a column is the name of the
86// column. The type is always just "text". But the code will accept
87// an elaborate typename. Perhaps someday we'll do something with it.
88//
89column ::= columnid type carglist.
drhc4a3c772001-04-04 11:48:57 +000090columnid ::= ids(X). {sqliteAddColumn(pParse,&X);}
91
92// An IDENTIFIER can be a generic identifier, or one of several
93// keywords. Any non-standard keyword can also be an identifier.
94// We also make DESC and identifier since it comes up so often.
95//
drh982cef72000-05-30 16:27:03 +000096%type id {Token}
drhc4a3c772001-04-04 11:48:57 +000097id(A) ::= DESC(X). {A = X;}
98id(A) ::= ASC(X). {A = X;}
99id(A) ::= DELIMITERS(X). {A = X;}
100id(A) ::= EXPLAIN(X). {A = X;}
101id(A) ::= VACUUM(X). {A = X;}
102id(A) ::= BEGIN(X). {A = X;}
103id(A) ::= END(X). {A = X;}
drhf57b14a2001-09-14 18:54:08 +0000104id(A) ::= PRAGMA(X). {A = X;}
105id(A) ::= CLUSTER(X). {A = X;}
drhc4a3c772001-04-04 11:48:57 +0000106id(A) ::= ID(X). {A = X;}
107
108// And "ids" is an identifer-or-string.
109//
110%type ids {Token}
111ids(A) ::= id(X). {A = X;}
112ids(A) ::= STRING(X). {A = X;}
113
drh348784e2000-05-29 20:41:49 +0000114type ::= typename.
115type ::= typename LP signed RP.
116type ::= typename LP signed COMMA signed RP.
drhc4a3c772001-04-04 11:48:57 +0000117typename ::= ids.
118typename ::= typename ids.
drh348784e2000-05-29 20:41:49 +0000119signed ::= INTEGER.
120signed ::= PLUS INTEGER.
121signed ::= MINUS INTEGER.
122carglist ::= carglist carg.
123carglist ::= .
drhc4a3c772001-04-04 11:48:57 +0000124carg ::= CONSTRAINT ids ccons.
drh348784e2000-05-29 20:41:49 +0000125carg ::= ccons.
drh7020f652000-06-03 18:06:52 +0000126carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
127carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
128carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
129carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
130carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
131carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
132carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
133carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
134carg ::= DEFAULT NULL.
drh348784e2000-05-29 20:41:49 +0000135
136// In addition to the type name, we also care about the primary key.
137//
138ccons ::= NOT NULL.
drh6206d502000-06-19 19:09:08 +0000139ccons ::= PRIMARY KEY sortorder. {sqliteCreateIndex(pParse,0,0,0,0,0);}
drh348784e2000-05-29 20:41:49 +0000140ccons ::= UNIQUE.
drh4794b982000-06-06 13:54:14 +0000141ccons ::= CHECK LP expr RP.
drh348784e2000-05-29 20:41:49 +0000142
143// For the time being, the only constraint we care about is the primary
144// key.
145//
146conslist_opt ::= .
147conslist_opt ::= COMMA conslist.
148conslist ::= conslist COMMA tcons.
drha2e1bb52001-01-04 14:20:18 +0000149conslist ::= conslist tcons.
drh348784e2000-05-29 20:41:49 +0000150conslist ::= tcons.
drhc4a3c772001-04-04 11:48:57 +0000151tcons ::= CONSTRAINT ids.
drha2e1bb52001-01-04 14:20:18 +0000152tcons ::= PRIMARY KEY LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,0,0);}
153tcons ::= UNIQUE LP idlist RP.
154tcons ::= CHECK expr.
drhc4a3c772001-04-04 11:48:57 +0000155idlist ::= idlist COMMA ids.
156idlist ::= ids.
drh348784e2000-05-29 20:41:49 +0000157
158// The next command format is dropping tables.
159//
drhc4a3c772001-04-04 11:48:57 +0000160cmd ::= DROP TABLE ids(X). {sqliteDropTable(pParse,&X);}
drh348784e2000-05-29 20:41:49 +0000161
162// The select statement
163//
drh9bb61fe2000-06-05 16:01:39 +0000164cmd ::= select(X). {
drhfef52082000-06-06 01:50:43 +0000165 sqliteSelect(pParse, X, SRT_Callback, 0);
drh9bb61fe2000-06-05 16:01:39 +0000166 sqliteSelectDelete(X);
167}
drhefb72512000-05-31 20:00:52 +0000168
drh9bb61fe2000-06-05 16:01:39 +0000169%type select {Select*}
170%destructor select {sqliteSelectDelete($$);}
drh82c3d632000-06-06 21:56:07 +0000171%type oneselect {Select*}
172%destructor oneselect {sqliteSelectDelete($$);}
drh9bb61fe2000-06-05 16:01:39 +0000173
drh82c3d632000-06-06 21:56:07 +0000174select(A) ::= oneselect(X). {A = X;}
175select(A) ::= select(X) joinop(Y) oneselect(Z). {
drhdaffd0e2001-04-11 14:28:42 +0000176 if( Z ){
drh82c3d632000-06-06 21:56:07 +0000177 Z->op = Y;
178 Z->pPrior = X;
drhdaffd0e2001-04-11 14:28:42 +0000179 }
180 A = Z;
drh82c3d632000-06-06 21:56:07 +0000181}
182%type joinop {int}
183joinop(A) ::= UNION. {A = TK_UNION;}
184joinop(A) ::= UNION ALL. {A = TK_ALL;}
185joinop(A) ::= INTERSECT. {A = TK_INTERSECT;}
186joinop(A) ::= EXCEPT. {A = TK_EXCEPT;}
187oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
188 groupby_opt(P) having_opt(Q) orderby_opt(Z). {
drh22827922000-06-06 17:27:05 +0000189 A = sqliteSelectNew(W,X,Y,P,Q,Z,D);
drh9bb61fe2000-06-05 16:01:39 +0000190}
191
192// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
193// present and false (0) if it is not.
194//
drhefb72512000-05-31 20:00:52 +0000195%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000196distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000197distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000198distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000199
drh9bb61fe2000-06-05 16:01:39 +0000200// selcollist is a list of expressions that are to become the return
201// values of the SELECT statement. In the case of "SELECT * FROM ..."
202// the selcollist value is NULL.
203//
drh348784e2000-05-29 20:41:49 +0000204%type selcollist {ExprList*}
205%destructor selcollist {sqliteExprListDelete($$);}
206%type sclp {ExprList*}
207%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000208sclp(A) ::= selcollist(X) COMMA. {A = X;}
209sclp(A) ::= . {A = 0;}
drh9bb61fe2000-06-05 16:01:39 +0000210selcollist(A) ::= STAR. {A = 0;}
drh348784e2000-05-29 20:41:49 +0000211selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);}
drhc4a3c772001-04-04 11:48:57 +0000212selcollist(A) ::= sclp(P) expr(X) as ids(Y). {A = sqliteExprListAppend(P,X,&Y);}
drh9bb61fe2000-06-05 16:01:39 +0000213as ::= .
214as ::= AS.
215
drh348784e2000-05-29 20:41:49 +0000216
217%type seltablist {IdList*}
218%destructor seltablist {sqliteIdListDelete($$);}
219%type stl_prefix {IdList*}
220%destructor stl_prefix {sqliteIdListDelete($$);}
221%type from {IdList*}
222%destructor from {sqliteIdListDelete($$);}
223
224from(A) ::= FROM seltablist(X). {A = X;}
225stl_prefix(A) ::= seltablist(X) COMMA. {A = X;}
226stl_prefix(A) ::= . {A = 0;}
drhc4a3c772001-04-04 11:48:57 +0000227seltablist(A) ::= stl_prefix(X) ids(Y). {A = sqliteIdListAppend(X,&Y);}
228seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). {
229 A = sqliteIdListAppend(X,&Y);
230 sqliteIdListAddAlias(A,&Z);
231}
drh348784e2000-05-29 20:41:49 +0000232
233%type orderby_opt {ExprList*}
234%destructor orderby_opt {sqliteExprListDelete($$);}
235%type sortlist {ExprList*}
236%destructor sortlist {sqliteExprListDelete($$);}
237%type sortitem {Expr*}
238%destructor sortitem {sqliteExprDelete($$);}
239
240orderby_opt(A) ::= . {A = 0;}
241orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh9bb61fe2000-06-05 16:01:39 +0000242sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
243 A = sqliteExprListAppend(X,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000244 if( A ) A->a[A->nExpr-1].sortOrder = Z; /* 0=ascending, 1=decending */
drh9bb61fe2000-06-05 16:01:39 +0000245}
246sortlist(A) ::= sortitem(Y) sortorder(Z). {
247 A = sqliteExprListAppend(0,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000248 if( A ) A->a[0].sortOrder = Z;
drh9bb61fe2000-06-05 16:01:39 +0000249}
drhda9d6c42000-05-31 18:20:14 +0000250sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000251
252%type sortorder {int}
253
254sortorder(A) ::= ASC. {A = 0;}
255sortorder(A) ::= DESC. {A = 1;}
256sortorder(A) ::= . {A = 0;}
257
drh22827922000-06-06 17:27:05 +0000258%type groupby_opt {ExprList*}
259%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000260groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000261groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
262
263%type having_opt {Expr*}
264%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000265having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000266having_opt(A) ::= HAVING expr(X). {A = X;}
267
drh82c3d632000-06-06 21:56:07 +0000268
drhc4a3c772001-04-04 11:48:57 +0000269cmd ::= DELETE FROM ids(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000270 {sqliteDeleteFrom(pParse, &X, Y);}
271
272%type where_opt {Expr*}
273%destructor where_opt {sqliteExprDelete($$);}
274
275where_opt(A) ::= . {A = 0;}
276where_opt(A) ::= WHERE expr(X). {A = X;}
277
278%type setlist {ExprList*}
279%destructor setlist {sqliteExprListDelete($$);}
280
drhc4a3c772001-04-04 11:48:57 +0000281cmd ::= UPDATE ids(X) SET setlist(Y) where_opt(Z).
drh348784e2000-05-29 20:41:49 +0000282 {sqliteUpdate(pParse,&X,Y,Z);}
283
drhc4a3c772001-04-04 11:48:57 +0000284setlist(A) ::= setlist(Z) COMMA ids(X) EQ expr(Y).
drh348784e2000-05-29 20:41:49 +0000285 {A = sqliteExprListAppend(Z,Y,&X);}
drhc4a3c772001-04-04 11:48:57 +0000286setlist(A) ::= ids(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000287
drhc4a3c772001-04-04 11:48:57 +0000288cmd ::= INSERT INTO ids(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
drh5974a302000-06-07 14:42:26 +0000289 {sqliteInsert(pParse, &X, Y, 0, F);}
drhc4a3c772001-04-04 11:48:57 +0000290cmd ::= INSERT INTO ids(X) inscollist_opt(F) select(S).
drh5974a302000-06-07 14:42:26 +0000291 {sqliteInsert(pParse, &X, 0, S, F);}
drh348784e2000-05-29 20:41:49 +0000292
293
294%type itemlist {ExprList*}
295%destructor itemlist {sqliteExprListDelete($$);}
296%type item {Expr*}
297%destructor item {sqliteExprDelete($$);}
298
299itemlist(A) ::= itemlist(X) COMMA item(Y). {A = sqliteExprListAppend(X,Y,0);}
300itemlist(A) ::= item(X). {A = sqliteExprListAppend(0,X,0);}
301item(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000302item(A) ::= PLUS INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
303item(A) ::= MINUS INTEGER(X). {
drh6e142f52000-06-08 13:36:40 +0000304 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000305 if( A ) A->pLeft = sqliteExpr(TK_INTEGER, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000306}
drh348784e2000-05-29 20:41:49 +0000307item(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000308item(A) ::= PLUS FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
309item(A) ::= MINUS FLOAT(X). {
drh6e142f52000-06-08 13:36:40 +0000310 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000311 if( A ) A->pLeft = sqliteExpr(TK_FLOAT, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000312}
drh348784e2000-05-29 20:41:49 +0000313item(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drh8be51132000-06-03 19:19:41 +0000314item(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);}
drh348784e2000-05-29 20:41:49 +0000315
drh967e8b72000-06-21 13:59:10 +0000316%type inscollist_opt {IdList*}
317%destructor inscollist_opt {sqliteIdListDelete($$);}
318%type inscollist {IdList*}
319%destructor inscollist {sqliteIdListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000320
drhc4a3c772001-04-04 11:48:57 +0000321inscollist_opt(A) ::= . {A = 0;}
322inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
323inscollist(A) ::= inscollist(X) COMMA ids(Y). {A = sqliteIdListAppend(X,&Y);}
324inscollist(A) ::= ids(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000325
326%left OR.
327%left AND.
drh8be51132000-06-03 19:19:41 +0000328%right NOT.
drhfef52082000-06-06 01:50:43 +0000329%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000330%left GT GE LT LE.
331%left PLUS MINUS.
drh31884b02000-06-09 14:14:32 +0000332%left STAR SLASH.
drh00400772000-06-16 20:51:26 +0000333%left CONCAT.
drh8be51132000-06-03 19:19:41 +0000334%right UMINUS.
drh348784e2000-05-29 20:41:49 +0000335
336%type expr {Expr*}
337%destructor expr {sqliteExprDelete($$);}
338
drhe1b6a5b2000-07-29 13:06:59 +0000339expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
drhe1b6a5b2000-07-29 13:06:59 +0000340expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
drhc4a3c772001-04-04 11:48:57 +0000341expr(A) ::= id(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
342expr(A) ::= ids(X) DOT ids(Y). {
drhe1b6a5b2000-07-29 13:06:59 +0000343 Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
344 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
345 A = sqliteExpr(TK_DOT, temp1, temp2, 0);
346}
drh348784e2000-05-29 20:41:49 +0000347expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
348expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
349expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhe1b6a5b2000-07-29 13:06:59 +0000350expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
351 A = sqliteExprFunction(Y, &X);
352 sqliteExprSpan(A,&X,&E);
353}
354expr(A) ::= ID(X) LP STAR RP(E). {
355 A = sqliteExprFunction(0, &X);
356 sqliteExprSpan(A,&X,&E);
357}
drh348784e2000-05-29 20:41:49 +0000358expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
359expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
360expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
361expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
362expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
363expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
364expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
365expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drhdce2cbe2000-05-31 02:27:49 +0000366expr(A) ::= expr(X) LIKE expr(Y). {A = sqliteExpr(TK_LIKE, X, Y, 0);}
drh4794b982000-06-06 13:54:14 +0000367expr(A) ::= expr(X) NOT LIKE expr(Y). {
368 A = sqliteExpr(TK_LIKE, X, Y, 0);
369 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000370 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000371}
drhfef52082000-06-06 01:50:43 +0000372expr(A) ::= expr(X) GLOB expr(Y). {A = sqliteExpr(TK_GLOB,X,Y,0);}
drh4794b982000-06-06 13:54:14 +0000373expr(A) ::= expr(X) NOT GLOB expr(Y). {
374 A = sqliteExpr(TK_GLOB, X, Y, 0);
375 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000376 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000377}
drh348784e2000-05-29 20:41:49 +0000378expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
379expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
380expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
381expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000382expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drhe1b6a5b2000-07-29 13:06:59 +0000383expr(A) ::= expr(X) ISNULL(E). {
384 A = sqliteExpr(TK_ISNULL, X, 0, 0);
385 sqliteExprSpan(A,&X->span,&E);
386}
387expr(A) ::= expr(X) NOTNULL(E). {
388 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
389 sqliteExprSpan(A,&X->span,&E);
390}
391expr(A) ::= NOT(B) expr(X). {
392 A = sqliteExpr(TK_NOT, X, 0, 0);
393 sqliteExprSpan(A,&B,&X->span);
394}
395expr(A) ::= MINUS(B) expr(X). [UMINUS] {
396 A = sqliteExpr(TK_UMINUS, X, 0, 0);
397 sqliteExprSpan(A,&B,&X->span);
398}
399expr(A) ::= PLUS(B) expr(X). [UMINUS] {
400 A = X;
401 sqliteExprSpan(A,&B,&X->span);
402}
403expr(A) ::= LP(B) select(X) RP(E). {
drh19a775c2000-06-05 18:54:46 +0000404 A = sqliteExpr(TK_SELECT, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000405 if( A ) A->pSelect = X;
drhe1b6a5b2000-07-29 13:06:59 +0000406 sqliteExprSpan(A,&B,&E);
drh19a775c2000-06-05 18:54:46 +0000407}
drhfef52082000-06-06 01:50:43 +0000408expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
409 ExprList *pList = sqliteExprListAppend(0, X, 0);
410 pList = sqliteExprListAppend(pList, Y, 0);
411 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000412 if( A ) A->pList = pList;
drhe1b6a5b2000-07-29 13:06:59 +0000413 sqliteExprSpan(A,&W->span,&Y->span);
drhfef52082000-06-06 01:50:43 +0000414}
drh4794b982000-06-06 13:54:14 +0000415expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
416 ExprList *pList = sqliteExprListAppend(0, X, 0);
417 pList = sqliteExprListAppend(pList, Y, 0);
418 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000419 if( A ) A->pList = pList;
drh4794b982000-06-06 13:54:14 +0000420 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000421 sqliteExprSpan(A,&W->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000422}
drhe1b6a5b2000-07-29 13:06:59 +0000423expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000424 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000425 if( A ) A->pList = 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) IN LP select(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000429 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000430 if( A ) A->pSelect = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000431 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000432}
drhe1b6a5b2000-07-29 13:06:59 +0000433expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000434 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000435 if( A ) A->pList = Y;
drh4794b982000-06-06 13:54:14 +0000436 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000437 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000438}
drhe1b6a5b2000-07-29 13:06:59 +0000439expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000440 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000441 if( A ) A->pSelect = Y;
drh4794b982000-06-06 13:54:14 +0000442 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000443 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000444}
drhfef52082000-06-06 01:50:43 +0000445
446
drh348784e2000-05-29 20:41:49 +0000447
448%type exprlist {ExprList*}
449%destructor exprlist {sqliteExprListDelete($$);}
450%type expritem {Expr*}
451%destructor expritem {sqliteExprDelete($$);}
452
drh348784e2000-05-29 20:41:49 +0000453exprlist(A) ::= exprlist(X) COMMA expritem(Y).
454 {A = sqliteExprListAppend(X,Y,0);}
455exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
456expritem(A) ::= expr(X). {A = X;}
457expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000458
drh348784e2000-05-29 20:41:49 +0000459
drhc4a3c772001-04-04 11:48:57 +0000460cmd ::= CREATE(S) uniqueflag INDEX ids(X) ON ids(Y) LP idxlist(Z) RP(E).
drh348784e2000-05-29 20:41:49 +0000461 {sqliteCreateIndex(pParse, &X, &Y, Z, &S, &E);}
462uniqueflag ::= UNIQUE.
463uniqueflag ::= .
464
465%type idxlist {IdList*}
466%destructor idxlist {sqliteIdListDelete($$);}
467%type idxitem {Token}
468
469idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
470 {A = sqliteIdListAppend(X,&Y);}
471idxlist(A) ::= idxitem(Y).
472 {A = sqliteIdListAppend(0,&Y);}
drhc4a3c772001-04-04 11:48:57 +0000473idxitem(A) ::= ids(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000474
drhc4a3c772001-04-04 11:48:57 +0000475cmd ::= DROP INDEX ids(X). {sqliteDropIndex(pParse, &X);}
drh982cef72000-05-30 16:27:03 +0000476
drhc4a3c772001-04-04 11:48:57 +0000477cmd ::= COPY ids(X) FROM ids(Y) USING DELIMITERS STRING(Z).
drh982cef72000-05-30 16:27:03 +0000478 {sqliteCopy(pParse,&X,&Y,&Z);}
drhc4a3c772001-04-04 11:48:57 +0000479cmd ::= COPY ids(X) FROM ids(Y).
drh982cef72000-05-30 16:27:03 +0000480 {sqliteCopy(pParse,&X,&Y,0);}
drhdce2cbe2000-05-31 02:27:49 +0000481
482cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
drhc4a3c772001-04-04 11:48:57 +0000483cmd ::= VACUUM ids(X). {sqliteVacuum(pParse,&X);}
drhf57b14a2001-09-14 18:54:08 +0000484
485cmd ::= PRAGMA ids(X) EQ ids(Y). {sqlitePragma(pParse,&X,&Y,0);}
486cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlitePragma(pParse,&X,&Y,0);}
487cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlitePragma(pParse,&X,&Y,0);}
488cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlitePragma(pParse,&X,&Y,1);}
489plus_num(A) ::= plus_opt number(X). {A = X;}
490minus_num(A) ::= MINUS number(X). {A = X;}
491number(A) ::= INTEGER(X). {A = X;}
492number(A) ::= FLOAT(X). {A = X;}
493plus_opt ::= PLUS.
494plus_opt ::= .