blob: b5519895de7c5d736148643fc8edf3c88e725abb [file] [log] [blame]
drh348784e2000-05-29 20:41:49 +00001/*
drhb19a2bc2001-09-16 00:13:26 +00002** 2001 September 15
drh348784e2000-05-29 20:41:49 +00003**
drhb19a2bc2001-09-16 00:13:26 +00004** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
drh348784e2000-05-29 20:41:49 +00006**
drhb19a2bc2001-09-16 00:13:26 +00007** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
drh348784e2000-05-29 20:41:49 +000010**
11*************************************************************************
12** This file contains SQLite's grammar for SQL. Process this file
13** using the lemon parser generator to generate C code that runs
14** the parser. Lemon will also generate a header file containing
15** numeric codes for all of the tokens.
16**
drhadbca9c2001-09-27 15:11:53 +000017** @(#) $Id: parse.y,v 1.32 2001/09/27 15:11:54 drh Exp $
drh348784e2000-05-29 20:41:49 +000018*/
19%token_prefix TK_
20%token_type {Token}
drhf57b14a2001-09-14 18:54:08 +000021%default_type {Token}
drh348784e2000-05-29 20:41:49 +000022%extra_argument {Parse *pParse}
23%syntax_error {
drhc837e702000-06-08 16:26:24 +000024 sqliteSetString(&pParse->zErrMsg,"syntax error",0);
drh348784e2000-05-29 20:41:49 +000025 pParse->sErrToken = TOKEN;
26}
27%name sqliteParser
28%include {
29#include "sqliteInt.h"
30#include "parse.h"
31}
32
drh348784e2000-05-29 20:41:49 +000033// These are extra tokens used by the lexer but never seen by the
34// parser. We put them in a rule so that the parser generator will
drh6206d502000-06-19 19:09:08 +000035// add them to the parse.h output file.
drh348784e2000-05-29 20:41:49 +000036//
drhc4a3c772001-04-04 11:48:57 +000037%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
38 COLUMN AGG_FUNCTION.
39
40// Input is zero or more commands.
41input ::= cmdlist.
drh348784e2000-05-29 20:41:49 +000042
43// A list of commands is zero or more commands
44//
45cmdlist ::= ecmd.
46cmdlist ::= cmdlist SEMI ecmd.
47ecmd ::= explain cmd. {sqliteExec(pParse);}
48ecmd ::= cmd. {sqliteExec(pParse);}
49ecmd ::= .
50explain ::= EXPLAIN. {pParse->explain = 1;}
51
drhc4a3c772001-04-04 11:48:57 +000052// Begin and end transactions. Transaction support is sparse.
53// Some backends support only COMMIT and not ROLLBACK. There can
54// be only a single active transaction at a time.
55//
56cmd ::= BEGIN trans_opt. {sqliteBeginTransaction(pParse);}
57trans_opt ::= .
58trans_opt ::= TRANSACTION.
59trans_opt ::= TRANSACTION ids.
60cmd ::= COMMIT trans_opt. {sqliteCommitTransaction(pParse);}
61cmd ::= END trans_opt. {sqliteCommitTransaction(pParse);}
62cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);}
63
drh348784e2000-05-29 20:41:49 +000064// The first form of a command is a CREATE TABLE statement.
65//
66cmd ::= create_table create_table_args.
drhc4a3c772001-04-04 11:48:57 +000067create_table ::= CREATE(X) TABLE ids(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.
drhc4a3c772001-04-04 11:48:57 +000078columnid ::= ids(X). {sqliteAddColumn(pParse,&X);}
79
80// An IDENTIFIER can be a generic identifier, or one of several
81// keywords. Any non-standard keyword can also be an identifier.
82// We also make DESC and identifier since it comes up so often.
83//
drh982cef72000-05-30 16:27:03 +000084%type id {Token}
drhc4a3c772001-04-04 11:48:57 +000085id(A) ::= DESC(X). {A = X;}
86id(A) ::= ASC(X). {A = X;}
87id(A) ::= DELIMITERS(X). {A = X;}
88id(A) ::= EXPLAIN(X). {A = X;}
89id(A) ::= VACUUM(X). {A = X;}
90id(A) ::= BEGIN(X). {A = X;}
91id(A) ::= END(X). {A = X;}
drhf57b14a2001-09-14 18:54:08 +000092id(A) ::= PRAGMA(X). {A = X;}
93id(A) ::= CLUSTER(X). {A = X;}
drhc4a3c772001-04-04 11:48:57 +000094id(A) ::= ID(X). {A = X;}
95
96// And "ids" is an identifer-or-string.
97//
98%type ids {Token}
99ids(A) ::= id(X). {A = X;}
100ids(A) ::= STRING(X). {A = X;}
101
drh348784e2000-05-29 20:41:49 +0000102type ::= typename.
103type ::= typename LP signed RP.
104type ::= typename LP signed COMMA signed RP.
drhc4a3c772001-04-04 11:48:57 +0000105typename ::= ids.
106typename ::= typename ids.
drh348784e2000-05-29 20:41:49 +0000107signed ::= INTEGER.
108signed ::= PLUS INTEGER.
109signed ::= MINUS INTEGER.
110carglist ::= carglist carg.
111carglist ::= .
drhc4a3c772001-04-04 11:48:57 +0000112carg ::= CONSTRAINT ids ccons.
drh348784e2000-05-29 20:41:49 +0000113carg ::= ccons.
drh7020f652000-06-03 18:06:52 +0000114carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
115carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
116carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
117carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
118carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
119carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
120carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
121carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
122carg ::= DEFAULT NULL.
drh348784e2000-05-29 20:41:49 +0000123
124// In addition to the type name, we also care about the primary key.
125//
126ccons ::= NOT NULL.
drh717e6402001-09-27 03:22:32 +0000127ccons ::= PRIMARY KEY sortorder. {sqliteCreateIndex(pParse,0,0,0,1,0,0);}
drhadbca9c2001-09-27 15:11:53 +0000128ccons ::= UNIQUE. {sqliteCreateIndex(pParse,0,0,0,1,0,0);}
drh4794b982000-06-06 13:54:14 +0000129ccons ::= CHECK LP expr RP.
drh348784e2000-05-29 20:41:49 +0000130
131// For the time being, the only constraint we care about is the primary
132// key.
133//
134conslist_opt ::= .
135conslist_opt ::= COMMA conslist.
136conslist ::= conslist COMMA tcons.
drha2e1bb52001-01-04 14:20:18 +0000137conslist ::= conslist tcons.
drh348784e2000-05-29 20:41:49 +0000138conslist ::= tcons.
drhc4a3c772001-04-04 11:48:57 +0000139tcons ::= CONSTRAINT ids.
drh717e6402001-09-27 03:22:32 +0000140tcons ::= PRIMARY KEY LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,1,0,0);}
drhadbca9c2001-09-27 15:11:53 +0000141tcons ::= UNIQUE LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,1,0,0);}
drha2e1bb52001-01-04 14:20:18 +0000142tcons ::= CHECK expr.
drhadbca9c2001-09-27 15:11:53 +0000143// idlist ::= idlist COMMA ids.
144// idlist ::= ids.
drh348784e2000-05-29 20:41:49 +0000145
146// The next command format is dropping tables.
147//
drhc4a3c772001-04-04 11:48:57 +0000148cmd ::= DROP TABLE ids(X). {sqliteDropTable(pParse,&X);}
drh348784e2000-05-29 20:41:49 +0000149
150// The select statement
151//
drh9bb61fe2000-06-05 16:01:39 +0000152cmd ::= select(X). {
drhfef52082000-06-06 01:50:43 +0000153 sqliteSelect(pParse, X, SRT_Callback, 0);
drh9bb61fe2000-06-05 16:01:39 +0000154 sqliteSelectDelete(X);
155}
drhefb72512000-05-31 20:00:52 +0000156
drh9bb61fe2000-06-05 16:01:39 +0000157%type select {Select*}
158%destructor select {sqliteSelectDelete($$);}
drh82c3d632000-06-06 21:56:07 +0000159%type oneselect {Select*}
160%destructor oneselect {sqliteSelectDelete($$);}
drh9bb61fe2000-06-05 16:01:39 +0000161
drh82c3d632000-06-06 21:56:07 +0000162select(A) ::= oneselect(X). {A = X;}
163select(A) ::= select(X) joinop(Y) oneselect(Z). {
drhdaffd0e2001-04-11 14:28:42 +0000164 if( Z ){
drh82c3d632000-06-06 21:56:07 +0000165 Z->op = Y;
166 Z->pPrior = X;
drhdaffd0e2001-04-11 14:28:42 +0000167 }
168 A = Z;
drh82c3d632000-06-06 21:56:07 +0000169}
170%type joinop {int}
171joinop(A) ::= UNION. {A = TK_UNION;}
172joinop(A) ::= UNION ALL. {A = TK_ALL;}
173joinop(A) ::= INTERSECT. {A = TK_INTERSECT;}
174joinop(A) ::= EXCEPT. {A = TK_EXCEPT;}
175oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
176 groupby_opt(P) having_opt(Q) orderby_opt(Z). {
drh22827922000-06-06 17:27:05 +0000177 A = sqliteSelectNew(W,X,Y,P,Q,Z,D);
drh9bb61fe2000-06-05 16:01:39 +0000178}
179
180// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
181// present and false (0) if it is not.
182//
drhefb72512000-05-31 20:00:52 +0000183%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000184distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000185distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000186distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000187
drh9bb61fe2000-06-05 16:01:39 +0000188// selcollist is a list of expressions that are to become the return
189// values of the SELECT statement. In the case of "SELECT * FROM ..."
190// the selcollist value is NULL.
191//
drh348784e2000-05-29 20:41:49 +0000192%type selcollist {ExprList*}
193%destructor selcollist {sqliteExprListDelete($$);}
194%type sclp {ExprList*}
195%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000196sclp(A) ::= selcollist(X) COMMA. {A = X;}
197sclp(A) ::= . {A = 0;}
drh9bb61fe2000-06-05 16:01:39 +0000198selcollist(A) ::= STAR. {A = 0;}
drh348784e2000-05-29 20:41:49 +0000199selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);}
drhc4a3c772001-04-04 11:48:57 +0000200selcollist(A) ::= sclp(P) expr(X) as ids(Y). {A = sqliteExprListAppend(P,X,&Y);}
drh9bb61fe2000-06-05 16:01:39 +0000201as ::= .
202as ::= AS.
203
drh348784e2000-05-29 20:41:49 +0000204
205%type seltablist {IdList*}
206%destructor seltablist {sqliteIdListDelete($$);}
207%type stl_prefix {IdList*}
208%destructor stl_prefix {sqliteIdListDelete($$);}
209%type from {IdList*}
210%destructor from {sqliteIdListDelete($$);}
211
212from(A) ::= FROM seltablist(X). {A = X;}
213stl_prefix(A) ::= seltablist(X) COMMA. {A = X;}
214stl_prefix(A) ::= . {A = 0;}
drhc4a3c772001-04-04 11:48:57 +0000215seltablist(A) ::= stl_prefix(X) ids(Y). {A = sqliteIdListAppend(X,&Y);}
216seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). {
217 A = sqliteIdListAppend(X,&Y);
218 sqliteIdListAddAlias(A,&Z);
219}
drh348784e2000-05-29 20:41:49 +0000220
221%type orderby_opt {ExprList*}
222%destructor orderby_opt {sqliteExprListDelete($$);}
223%type sortlist {ExprList*}
224%destructor sortlist {sqliteExprListDelete($$);}
225%type sortitem {Expr*}
226%destructor sortitem {sqliteExprDelete($$);}
227
228orderby_opt(A) ::= . {A = 0;}
229orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh9bb61fe2000-06-05 16:01:39 +0000230sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
231 A = sqliteExprListAppend(X,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000232 if( A ) A->a[A->nExpr-1].sortOrder = Z; /* 0=ascending, 1=decending */
drh9bb61fe2000-06-05 16:01:39 +0000233}
234sortlist(A) ::= sortitem(Y) sortorder(Z). {
235 A = sqliteExprListAppend(0,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000236 if( A ) A->a[0].sortOrder = Z;
drh9bb61fe2000-06-05 16:01:39 +0000237}
drhda9d6c42000-05-31 18:20:14 +0000238sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000239
240%type sortorder {int}
241
242sortorder(A) ::= ASC. {A = 0;}
243sortorder(A) ::= DESC. {A = 1;}
244sortorder(A) ::= . {A = 0;}
245
drh22827922000-06-06 17:27:05 +0000246%type groupby_opt {ExprList*}
247%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000248groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000249groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
250
251%type having_opt {Expr*}
252%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000253having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000254having_opt(A) ::= HAVING expr(X). {A = X;}
255
drh82c3d632000-06-06 21:56:07 +0000256
drhc4a3c772001-04-04 11:48:57 +0000257cmd ::= DELETE FROM ids(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000258 {sqliteDeleteFrom(pParse, &X, Y);}
259
260%type where_opt {Expr*}
261%destructor where_opt {sqliteExprDelete($$);}
262
263where_opt(A) ::= . {A = 0;}
264where_opt(A) ::= WHERE expr(X). {A = X;}
265
266%type setlist {ExprList*}
267%destructor setlist {sqliteExprListDelete($$);}
268
drhc4a3c772001-04-04 11:48:57 +0000269cmd ::= UPDATE ids(X) SET setlist(Y) where_opt(Z).
drh348784e2000-05-29 20:41:49 +0000270 {sqliteUpdate(pParse,&X,Y,Z);}
271
drhc4a3c772001-04-04 11:48:57 +0000272setlist(A) ::= setlist(Z) COMMA ids(X) EQ expr(Y).
drh348784e2000-05-29 20:41:49 +0000273 {A = sqliteExprListAppend(Z,Y,&X);}
drhc4a3c772001-04-04 11:48:57 +0000274setlist(A) ::= ids(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000275
drhc4a3c772001-04-04 11:48:57 +0000276cmd ::= INSERT INTO ids(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
drh5974a302000-06-07 14:42:26 +0000277 {sqliteInsert(pParse, &X, Y, 0, F);}
drhc4a3c772001-04-04 11:48:57 +0000278cmd ::= INSERT INTO ids(X) inscollist_opt(F) select(S).
drh5974a302000-06-07 14:42:26 +0000279 {sqliteInsert(pParse, &X, 0, S, F);}
drh348784e2000-05-29 20:41:49 +0000280
281
282%type itemlist {ExprList*}
283%destructor itemlist {sqliteExprListDelete($$);}
284%type item {Expr*}
285%destructor item {sqliteExprDelete($$);}
286
287itemlist(A) ::= itemlist(X) COMMA item(Y). {A = sqliteExprListAppend(X,Y,0);}
288itemlist(A) ::= item(X). {A = sqliteExprListAppend(0,X,0);}
289item(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000290item(A) ::= PLUS INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
291item(A) ::= MINUS INTEGER(X). {
drh6e142f52000-06-08 13:36:40 +0000292 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000293 if( A ) A->pLeft = sqliteExpr(TK_INTEGER, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000294}
drh348784e2000-05-29 20:41:49 +0000295item(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000296item(A) ::= PLUS FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
297item(A) ::= MINUS FLOAT(X). {
drh6e142f52000-06-08 13:36:40 +0000298 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000299 if( A ) A->pLeft = sqliteExpr(TK_FLOAT, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000300}
drh348784e2000-05-29 20:41:49 +0000301item(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drh8be51132000-06-03 19:19:41 +0000302item(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);}
drh348784e2000-05-29 20:41:49 +0000303
drh967e8b72000-06-21 13:59:10 +0000304%type inscollist_opt {IdList*}
305%destructor inscollist_opt {sqliteIdListDelete($$);}
306%type inscollist {IdList*}
307%destructor inscollist {sqliteIdListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000308
drhc4a3c772001-04-04 11:48:57 +0000309inscollist_opt(A) ::= . {A = 0;}
310inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
311inscollist(A) ::= inscollist(X) COMMA ids(Y). {A = sqliteIdListAppend(X,&Y);}
312inscollist(A) ::= ids(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000313
314%left OR.
315%left AND.
drh8be51132000-06-03 19:19:41 +0000316%right NOT.
drhfef52082000-06-06 01:50:43 +0000317%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000318%left GT GE LT LE.
319%left PLUS MINUS.
drh31884b02000-06-09 14:14:32 +0000320%left STAR SLASH.
drh00400772000-06-16 20:51:26 +0000321%left CONCAT.
drh8be51132000-06-03 19:19:41 +0000322%right UMINUS.
drh348784e2000-05-29 20:41:49 +0000323
324%type expr {Expr*}
325%destructor expr {sqliteExprDelete($$);}
326
drhe1b6a5b2000-07-29 13:06:59 +0000327expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
drhe1b6a5b2000-07-29 13:06:59 +0000328expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
drhc4a3c772001-04-04 11:48:57 +0000329expr(A) ::= id(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
330expr(A) ::= ids(X) DOT ids(Y). {
drhe1b6a5b2000-07-29 13:06:59 +0000331 Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
332 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
333 A = sqliteExpr(TK_DOT, temp1, temp2, 0);
334}
drh348784e2000-05-29 20:41:49 +0000335expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
336expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
337expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhe1b6a5b2000-07-29 13:06:59 +0000338expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
339 A = sqliteExprFunction(Y, &X);
340 sqliteExprSpan(A,&X,&E);
341}
342expr(A) ::= ID(X) LP STAR RP(E). {
343 A = sqliteExprFunction(0, &X);
344 sqliteExprSpan(A,&X,&E);
345}
drh348784e2000-05-29 20:41:49 +0000346expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
347expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
348expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
349expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
350expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
351expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
352expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
353expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drhdce2cbe2000-05-31 02:27:49 +0000354expr(A) ::= expr(X) LIKE expr(Y). {A = sqliteExpr(TK_LIKE, X, Y, 0);}
drh4794b982000-06-06 13:54:14 +0000355expr(A) ::= expr(X) NOT LIKE expr(Y). {
356 A = sqliteExpr(TK_LIKE, X, Y, 0);
357 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000358 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000359}
drhfef52082000-06-06 01:50:43 +0000360expr(A) ::= expr(X) GLOB expr(Y). {A = sqliteExpr(TK_GLOB,X,Y,0);}
drh4794b982000-06-06 13:54:14 +0000361expr(A) ::= expr(X) NOT GLOB expr(Y). {
362 A = sqliteExpr(TK_GLOB, X, Y, 0);
363 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000364 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000365}
drh348784e2000-05-29 20:41:49 +0000366expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
367expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
368expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
369expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000370expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drhe1b6a5b2000-07-29 13:06:59 +0000371expr(A) ::= expr(X) ISNULL(E). {
372 A = sqliteExpr(TK_ISNULL, X, 0, 0);
373 sqliteExprSpan(A,&X->span,&E);
374}
375expr(A) ::= expr(X) NOTNULL(E). {
376 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
377 sqliteExprSpan(A,&X->span,&E);
378}
379expr(A) ::= NOT(B) expr(X). {
380 A = sqliteExpr(TK_NOT, X, 0, 0);
381 sqliteExprSpan(A,&B,&X->span);
382}
383expr(A) ::= MINUS(B) expr(X). [UMINUS] {
384 A = sqliteExpr(TK_UMINUS, X, 0, 0);
385 sqliteExprSpan(A,&B,&X->span);
386}
387expr(A) ::= PLUS(B) expr(X). [UMINUS] {
388 A = X;
389 sqliteExprSpan(A,&B,&X->span);
390}
391expr(A) ::= LP(B) select(X) RP(E). {
drh19a775c2000-06-05 18:54:46 +0000392 A = sqliteExpr(TK_SELECT, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000393 if( A ) A->pSelect = X;
drhe1b6a5b2000-07-29 13:06:59 +0000394 sqliteExprSpan(A,&B,&E);
drh19a775c2000-06-05 18:54:46 +0000395}
drhfef52082000-06-06 01:50:43 +0000396expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
397 ExprList *pList = sqliteExprListAppend(0, X, 0);
398 pList = sqliteExprListAppend(pList, Y, 0);
399 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000400 if( A ) A->pList = pList;
drhe1b6a5b2000-07-29 13:06:59 +0000401 sqliteExprSpan(A,&W->span,&Y->span);
drhfef52082000-06-06 01:50:43 +0000402}
drh4794b982000-06-06 13:54:14 +0000403expr(A) ::= expr(W) NOT 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);
drhdaffd0e2001-04-11 14:28:42 +0000407 if( A ) A->pList = pList;
drh4794b982000-06-06 13:54:14 +0000408 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000409 sqliteExprSpan(A,&W->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000410}
drhe1b6a5b2000-07-29 13:06:59 +0000411expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000412 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000413 if( A ) A->pList = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000414 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000415}
drhe1b6a5b2000-07-29 13:06:59 +0000416expr(A) ::= expr(X) IN LP select(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000417 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000418 if( A ) A->pSelect = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000419 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000420}
drhe1b6a5b2000-07-29 13:06:59 +0000421expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000422 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000423 if( A ) A->pList = Y;
drh4794b982000-06-06 13:54:14 +0000424 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000425 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000426}
drhe1b6a5b2000-07-29 13:06:59 +0000427expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000428 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000429 if( A ) A->pSelect = Y;
drh4794b982000-06-06 13:54:14 +0000430 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000431 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000432}
drhfef52082000-06-06 01:50:43 +0000433
434
drh348784e2000-05-29 20:41:49 +0000435
436%type exprlist {ExprList*}
437%destructor exprlist {sqliteExprListDelete($$);}
438%type expritem {Expr*}
439%destructor expritem {sqliteExprDelete($$);}
440
drh348784e2000-05-29 20:41:49 +0000441exprlist(A) ::= exprlist(X) COMMA expritem(Y).
442 {A = sqliteExprListAppend(X,Y,0);}
443exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
444expritem(A) ::= expr(X). {A = X;}
445expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000446
drh348784e2000-05-29 20:41:49 +0000447
drh717e6402001-09-27 03:22:32 +0000448cmd ::= CREATE(S) uniqueflag(U) INDEX ids(X) ON ids(Y) LP idxlist(Z) RP(E).
449 {sqliteCreateIndex(pParse, &X, &Y, Z, U, &S, &E);}
450
451%type uniqueflag {int}
452uniqueflag(A) ::= UNIQUE. { A = 1; }
453uniqueflag(A) ::= . { A = 0; }
drh348784e2000-05-29 20:41:49 +0000454
455%type idxlist {IdList*}
456%destructor idxlist {sqliteIdListDelete($$);}
457%type idxitem {Token}
458
459idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
460 {A = sqliteIdListAppend(X,&Y);}
461idxlist(A) ::= idxitem(Y).
462 {A = sqliteIdListAppend(0,&Y);}
drhc4a3c772001-04-04 11:48:57 +0000463idxitem(A) ::= ids(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000464
drhc4a3c772001-04-04 11:48:57 +0000465cmd ::= DROP INDEX ids(X). {sqliteDropIndex(pParse, &X);}
drh982cef72000-05-30 16:27:03 +0000466
drhc4a3c772001-04-04 11:48:57 +0000467cmd ::= COPY ids(X) FROM ids(Y) USING DELIMITERS STRING(Z).
drh982cef72000-05-30 16:27:03 +0000468 {sqliteCopy(pParse,&X,&Y,&Z);}
drhc4a3c772001-04-04 11:48:57 +0000469cmd ::= COPY ids(X) FROM ids(Y).
drh982cef72000-05-30 16:27:03 +0000470 {sqliteCopy(pParse,&X,&Y,0);}
drhdce2cbe2000-05-31 02:27:49 +0000471
472cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
drhc4a3c772001-04-04 11:48:57 +0000473cmd ::= VACUUM ids(X). {sqliteVacuum(pParse,&X);}
drhf57b14a2001-09-14 18:54:08 +0000474
475cmd ::= PRAGMA ids(X) EQ ids(Y). {sqlitePragma(pParse,&X,&Y,0);}
476cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlitePragma(pParse,&X,&Y,0);}
477cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlitePragma(pParse,&X,&Y,0);}
478cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlitePragma(pParse,&X,&Y,1);}
479plus_num(A) ::= plus_opt number(X). {A = X;}
480minus_num(A) ::= MINUS number(X). {A = X;}
481number(A) ::= INTEGER(X). {A = X;}
482number(A) ::= FLOAT(X). {A = X;}
483plus_opt ::= PLUS.
484plus_opt ::= .