blob: 56e6af75af5ed8b94736f7ad490e3bc37ff6b17f [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**
drh382c0242001-10-06 16:33:02 +000017** @(#) $Id: parse.y,v 1.34 2001/10/06 16:33:03 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
drh382c0242001-10-06 16:33:02 +000052///////////////////// Begin and end transactions. ////////////////////////////
drhc4a3c772001-04-04 11:48:57 +000053//
54cmd ::= BEGIN trans_opt. {sqliteBeginTransaction(pParse);}
55trans_opt ::= .
56trans_opt ::= TRANSACTION.
57trans_opt ::= TRANSACTION ids.
58cmd ::= COMMIT trans_opt. {sqliteCommitTransaction(pParse);}
59cmd ::= END trans_opt. {sqliteCommitTransaction(pParse);}
60cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);}
61
drh382c0242001-10-06 16:33:02 +000062///////////////////// The CREATE TABLE statement ////////////////////////////
drh348784e2000-05-29 20:41:49 +000063//
64cmd ::= create_table create_table_args.
drhc4a3c772001-04-04 11:48:57 +000065create_table ::= CREATE(X) TABLE ids(Y). {sqliteStartTable(pParse,&X,&Y);}
drh348784e2000-05-29 20:41:49 +000066create_table_args ::= LP columnlist conslist_opt RP(X).
67 {sqliteEndTable(pParse,&X);}
68columnlist ::= columnlist COMMA column.
69columnlist ::= column.
70
71// About the only information used for a column is the name of the
72// column. The type is always just "text". But the code will accept
73// an elaborate typename. Perhaps someday we'll do something with it.
74//
75column ::= columnid type carglist.
drhc4a3c772001-04-04 11:48:57 +000076columnid ::= ids(X). {sqliteAddColumn(pParse,&X);}
77
78// An IDENTIFIER can be a generic identifier, or one of several
79// keywords. Any non-standard keyword can also be an identifier.
drh382c0242001-10-06 16:33:02 +000080// We also make DESC and identifier since it comes up so often (as
81// an abbreviation of "description").
drhc4a3c772001-04-04 11:48:57 +000082//
drh982cef72000-05-30 16:27:03 +000083%type id {Token}
drhc4a3c772001-04-04 11:48:57 +000084id(A) ::= DESC(X). {A = X;}
85id(A) ::= ASC(X). {A = X;}
86id(A) ::= DELIMITERS(X). {A = X;}
87id(A) ::= EXPLAIN(X). {A = X;}
88id(A) ::= VACUUM(X). {A = X;}
89id(A) ::= BEGIN(X). {A = X;}
90id(A) ::= END(X). {A = X;}
drhf57b14a2001-09-14 18:54:08 +000091id(A) ::= PRAGMA(X). {A = X;}
92id(A) ::= CLUSTER(X). {A = X;}
drhc4a3c772001-04-04 11:48:57 +000093id(A) ::= ID(X). {A = X;}
94
95// And "ids" is an identifer-or-string.
96//
97%type ids {Token}
98ids(A) ::= id(X). {A = X;}
99ids(A) ::= STRING(X). {A = X;}
100
drh382c0242001-10-06 16:33:02 +0000101type ::= .
102type ::= typename(X). {sqliteAddColumnType(pParse,&X,&X);}
103type ::= typename(X) LP signed RP(Y). {sqliteAddColumnType(pParse,&X,&Y);}
104type ::= typename(X) LP signed COMMA signed RP(Y).
105 {sqliteAddColumnType(pParse,&X,&Y);}
106%type typename {Token}
107typename(A) ::= ids(X). {A = X;}
108typename(A) ::= typename(X) ids. {A = X;}
drh348784e2000-05-29 20:41:49 +0000109signed ::= INTEGER.
110signed ::= PLUS INTEGER.
111signed ::= MINUS INTEGER.
112carglist ::= carglist carg.
113carglist ::= .
drhc4a3c772001-04-04 11:48:57 +0000114carg ::= CONSTRAINT ids ccons.
drh348784e2000-05-29 20:41:49 +0000115carg ::= ccons.
drh7020f652000-06-03 18:06:52 +0000116carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
117carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
118carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
119carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
120carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
121carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
122carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
123carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
124carg ::= DEFAULT NULL.
drh348784e2000-05-29 20:41:49 +0000125
drh382c0242001-10-06 16:33:02 +0000126// In addition to the type name, we also care about the primary key and
127// UNIQUE constraints.
drh348784e2000-05-29 20:41:49 +0000128//
drh382c0242001-10-06 16:33:02 +0000129ccons ::= NOT NULL. {sqliteAddNotNull(pParse);}
drh717e6402001-09-27 03:22:32 +0000130ccons ::= PRIMARY KEY sortorder. {sqliteCreateIndex(pParse,0,0,0,1,0,0);}
drhadbca9c2001-09-27 15:11:53 +0000131ccons ::= UNIQUE. {sqliteCreateIndex(pParse,0,0,0,1,0,0);}
drh4794b982000-06-06 13:54:14 +0000132ccons ::= CHECK LP expr RP.
drh348784e2000-05-29 20:41:49 +0000133
134// For the time being, the only constraint we care about is the primary
drh382c0242001-10-06 16:33:02 +0000135// key and UNIQUE. Both create indices.
drh348784e2000-05-29 20:41:49 +0000136//
137conslist_opt ::= .
138conslist_opt ::= COMMA conslist.
139conslist ::= conslist COMMA tcons.
drha2e1bb52001-01-04 14:20:18 +0000140conslist ::= conslist tcons.
drh348784e2000-05-29 20:41:49 +0000141conslist ::= tcons.
drhc4a3c772001-04-04 11:48:57 +0000142tcons ::= CONSTRAINT ids.
drh717e6402001-09-27 03:22:32 +0000143tcons ::= PRIMARY KEY LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,1,0,0);}
drhadbca9c2001-09-27 15:11:53 +0000144tcons ::= UNIQUE LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,1,0,0);}
drha2e1bb52001-01-04 14:20:18 +0000145tcons ::= CHECK expr.
drh348784e2000-05-29 20:41:49 +0000146
drh382c0242001-10-06 16:33:02 +0000147////////////////////////// The DROP TABLE /////////////////////////////////////
drh348784e2000-05-29 20:41:49 +0000148//
drhc4a3c772001-04-04 11:48:57 +0000149cmd ::= DROP TABLE ids(X). {sqliteDropTable(pParse,&X);}
drh348784e2000-05-29 20:41:49 +0000150
drh382c0242001-10-06 16:33:02 +0000151//////////////////////// The SELECT statement /////////////////////////////////
drh348784e2000-05-29 20:41:49 +0000152//
drh9bb61fe2000-06-05 16:01:39 +0000153cmd ::= select(X). {
drhfef52082000-06-06 01:50:43 +0000154 sqliteSelect(pParse, X, SRT_Callback, 0);
drh9bb61fe2000-06-05 16:01:39 +0000155 sqliteSelectDelete(X);
156}
drhefb72512000-05-31 20:00:52 +0000157
drh9bb61fe2000-06-05 16:01:39 +0000158%type select {Select*}
159%destructor select {sqliteSelectDelete($$);}
drh82c3d632000-06-06 21:56:07 +0000160%type oneselect {Select*}
161%destructor oneselect {sqliteSelectDelete($$);}
drh9bb61fe2000-06-05 16:01:39 +0000162
drh82c3d632000-06-06 21:56:07 +0000163select(A) ::= oneselect(X). {A = X;}
164select(A) ::= select(X) joinop(Y) oneselect(Z). {
drhdaffd0e2001-04-11 14:28:42 +0000165 if( Z ){
drh82c3d632000-06-06 21:56:07 +0000166 Z->op = Y;
167 Z->pPrior = X;
drhdaffd0e2001-04-11 14:28:42 +0000168 }
169 A = Z;
drh82c3d632000-06-06 21:56:07 +0000170}
171%type joinop {int}
172joinop(A) ::= UNION. {A = TK_UNION;}
173joinop(A) ::= UNION ALL. {A = TK_ALL;}
174joinop(A) ::= INTERSECT. {A = TK_INTERSECT;}
175joinop(A) ::= EXCEPT. {A = TK_EXCEPT;}
176oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
177 groupby_opt(P) having_opt(Q) orderby_opt(Z). {
drh22827922000-06-06 17:27:05 +0000178 A = sqliteSelectNew(W,X,Y,P,Q,Z,D);
drh9bb61fe2000-06-05 16:01:39 +0000179}
180
181// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
182// present and false (0) if it is not.
183//
drhefb72512000-05-31 20:00:52 +0000184%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000185distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000186distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000187distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000188
drh9bb61fe2000-06-05 16:01:39 +0000189// selcollist is a list of expressions that are to become the return
190// values of the SELECT statement. In the case of "SELECT * FROM ..."
191// the selcollist value is NULL.
192//
drh348784e2000-05-29 20:41:49 +0000193%type selcollist {ExprList*}
194%destructor selcollist {sqliteExprListDelete($$);}
195%type sclp {ExprList*}
196%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000197sclp(A) ::= selcollist(X) COMMA. {A = X;}
198sclp(A) ::= . {A = 0;}
drh9bb61fe2000-06-05 16:01:39 +0000199selcollist(A) ::= STAR. {A = 0;}
drh348784e2000-05-29 20:41:49 +0000200selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);}
drhc4a3c772001-04-04 11:48:57 +0000201selcollist(A) ::= sclp(P) expr(X) as ids(Y). {A = sqliteExprListAppend(P,X,&Y);}
drh9bb61fe2000-06-05 16:01:39 +0000202as ::= .
203as ::= AS.
204
drh348784e2000-05-29 20:41:49 +0000205
206%type seltablist {IdList*}
207%destructor seltablist {sqliteIdListDelete($$);}
208%type stl_prefix {IdList*}
209%destructor stl_prefix {sqliteIdListDelete($$);}
210%type from {IdList*}
211%destructor from {sqliteIdListDelete($$);}
212
213from(A) ::= FROM seltablist(X). {A = X;}
214stl_prefix(A) ::= seltablist(X) COMMA. {A = X;}
215stl_prefix(A) ::= . {A = 0;}
drhc4a3c772001-04-04 11:48:57 +0000216seltablist(A) ::= stl_prefix(X) ids(Y). {A = sqliteIdListAppend(X,&Y);}
217seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). {
218 A = sqliteIdListAppend(X,&Y);
219 sqliteIdListAddAlias(A,&Z);
220}
drh348784e2000-05-29 20:41:49 +0000221
222%type orderby_opt {ExprList*}
223%destructor orderby_opt {sqliteExprListDelete($$);}
224%type sortlist {ExprList*}
225%destructor sortlist {sqliteExprListDelete($$);}
226%type sortitem {Expr*}
227%destructor sortitem {sqliteExprDelete($$);}
228
229orderby_opt(A) ::= . {A = 0;}
230orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh9bb61fe2000-06-05 16:01:39 +0000231sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
232 A = sqliteExprListAppend(X,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000233 if( A ) A->a[A->nExpr-1].sortOrder = Z; /* 0=ascending, 1=decending */
drh9bb61fe2000-06-05 16:01:39 +0000234}
235sortlist(A) ::= sortitem(Y) sortorder(Z). {
236 A = sqliteExprListAppend(0,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000237 if( A ) A->a[0].sortOrder = Z;
drh9bb61fe2000-06-05 16:01:39 +0000238}
drhda9d6c42000-05-31 18:20:14 +0000239sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000240
241%type sortorder {int}
242
243sortorder(A) ::= ASC. {A = 0;}
244sortorder(A) ::= DESC. {A = 1;}
245sortorder(A) ::= . {A = 0;}
246
drh22827922000-06-06 17:27:05 +0000247%type groupby_opt {ExprList*}
248%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000249groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000250groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
251
252%type having_opt {Expr*}
253%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000254having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000255having_opt(A) ::= HAVING expr(X). {A = X;}
256
drh382c0242001-10-06 16:33:02 +0000257/////////////////////////// The DELETE statement /////////////////////////////
258//
drhc4a3c772001-04-04 11:48:57 +0000259cmd ::= DELETE FROM ids(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000260 {sqliteDeleteFrom(pParse, &X, Y);}
261
262%type where_opt {Expr*}
263%destructor where_opt {sqliteExprDelete($$);}
264
265where_opt(A) ::= . {A = 0;}
266where_opt(A) ::= WHERE expr(X). {A = X;}
267
268%type setlist {ExprList*}
269%destructor setlist {sqliteExprListDelete($$);}
270
drh382c0242001-10-06 16:33:02 +0000271////////////////////////// The UPDATE command ////////////////////////////////
272//
drhc4a3c772001-04-04 11:48:57 +0000273cmd ::= UPDATE ids(X) SET setlist(Y) where_opt(Z).
drh348784e2000-05-29 20:41:49 +0000274 {sqliteUpdate(pParse,&X,Y,Z);}
275
drhc4a3c772001-04-04 11:48:57 +0000276setlist(A) ::= setlist(Z) COMMA ids(X) EQ expr(Y).
drh348784e2000-05-29 20:41:49 +0000277 {A = sqliteExprListAppend(Z,Y,&X);}
drhc4a3c772001-04-04 11:48:57 +0000278setlist(A) ::= ids(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000279
drh382c0242001-10-06 16:33:02 +0000280////////////////////////// The INSERT command /////////////////////////////////
281//
drhc4a3c772001-04-04 11:48:57 +0000282cmd ::= INSERT INTO ids(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
drh5974a302000-06-07 14:42:26 +0000283 {sqliteInsert(pParse, &X, Y, 0, F);}
drhc4a3c772001-04-04 11:48:57 +0000284cmd ::= INSERT INTO ids(X) inscollist_opt(F) select(S).
drh5974a302000-06-07 14:42:26 +0000285 {sqliteInsert(pParse, &X, 0, S, F);}
drh348784e2000-05-29 20:41:49 +0000286
287
288%type itemlist {ExprList*}
289%destructor itemlist {sqliteExprListDelete($$);}
290%type item {Expr*}
291%destructor item {sqliteExprDelete($$);}
292
293itemlist(A) ::= itemlist(X) COMMA item(Y). {A = sqliteExprListAppend(X,Y,0);}
294itemlist(A) ::= item(X). {A = sqliteExprListAppend(0,X,0);}
295item(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000296item(A) ::= PLUS INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
297item(A) ::= MINUS INTEGER(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_INTEGER, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000300}
drh348784e2000-05-29 20:41:49 +0000301item(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000302item(A) ::= PLUS FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
303item(A) ::= MINUS FLOAT(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_FLOAT, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000306}
drh348784e2000-05-29 20:41:49 +0000307item(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drh8be51132000-06-03 19:19:41 +0000308item(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);}
drh348784e2000-05-29 20:41:49 +0000309
drh967e8b72000-06-21 13:59:10 +0000310%type inscollist_opt {IdList*}
311%destructor inscollist_opt {sqliteIdListDelete($$);}
312%type inscollist {IdList*}
313%destructor inscollist {sqliteIdListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000314
drhc4a3c772001-04-04 11:48:57 +0000315inscollist_opt(A) ::= . {A = 0;}
316inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
317inscollist(A) ::= inscollist(X) COMMA ids(Y). {A = sqliteIdListAppend(X,&Y);}
318inscollist(A) ::= ids(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000319
drh382c0242001-10-06 16:33:02 +0000320/////////////////////////// Expression Processing /////////////////////////////
321//
drh348784e2000-05-29 20:41:49 +0000322%left OR.
323%left AND.
drh8be51132000-06-03 19:19:41 +0000324%right NOT.
drhfef52082000-06-06 01:50:43 +0000325%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000326%left GT GE LT LE.
327%left PLUS MINUS.
drh31884b02000-06-09 14:14:32 +0000328%left STAR SLASH.
drh00400772000-06-16 20:51:26 +0000329%left CONCAT.
drh8be51132000-06-03 19:19:41 +0000330%right UMINUS.
drh348784e2000-05-29 20:41:49 +0000331
332%type expr {Expr*}
333%destructor expr {sqliteExprDelete($$);}
334
drhe1b6a5b2000-07-29 13:06:59 +0000335expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
drhe1b6a5b2000-07-29 13:06:59 +0000336expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
drhc4a3c772001-04-04 11:48:57 +0000337expr(A) ::= id(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
338expr(A) ::= ids(X) DOT ids(Y). {
drhe1b6a5b2000-07-29 13:06:59 +0000339 Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
340 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
341 A = sqliteExpr(TK_DOT, temp1, temp2, 0);
342}
drh348784e2000-05-29 20:41:49 +0000343expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
344expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
345expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhe1b6a5b2000-07-29 13:06:59 +0000346expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
347 A = sqliteExprFunction(Y, &X);
348 sqliteExprSpan(A,&X,&E);
349}
350expr(A) ::= ID(X) LP STAR RP(E). {
351 A = sqliteExprFunction(0, &X);
352 sqliteExprSpan(A,&X,&E);
353}
drh348784e2000-05-29 20:41:49 +0000354expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
355expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
356expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
357expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
358expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
359expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
360expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
361expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drhdce2cbe2000-05-31 02:27:49 +0000362expr(A) ::= expr(X) LIKE expr(Y). {A = sqliteExpr(TK_LIKE, X, Y, 0);}
drh4794b982000-06-06 13:54:14 +0000363expr(A) ::= expr(X) NOT LIKE expr(Y). {
364 A = sqliteExpr(TK_LIKE, X, Y, 0);
365 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000366 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000367}
drhfef52082000-06-06 01:50:43 +0000368expr(A) ::= expr(X) GLOB expr(Y). {A = sqliteExpr(TK_GLOB,X,Y,0);}
drh4794b982000-06-06 13:54:14 +0000369expr(A) ::= expr(X) NOT GLOB expr(Y). {
370 A = sqliteExpr(TK_GLOB, X, Y, 0);
371 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000372 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000373}
drh348784e2000-05-29 20:41:49 +0000374expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
375expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
376expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
377expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000378expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drhe1b6a5b2000-07-29 13:06:59 +0000379expr(A) ::= expr(X) ISNULL(E). {
380 A = sqliteExpr(TK_ISNULL, X, 0, 0);
381 sqliteExprSpan(A,&X->span,&E);
382}
drh33048c02001-10-01 14:29:22 +0000383expr(A) ::= expr(X) IS NULL(E). {
384 A = sqliteExpr(TK_ISNULL, X, 0, 0);
385 sqliteExprSpan(A,&X->span,&E);
386}
drhe1b6a5b2000-07-29 13:06:59 +0000387expr(A) ::= expr(X) NOTNULL(E). {
388 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
389 sqliteExprSpan(A,&X->span,&E);
390}
drh33048c02001-10-01 14:29:22 +0000391expr(A) ::= expr(X) NOT NULL(E). {
392 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
393 sqliteExprSpan(A,&X->span,&E);
394}
drhe1b6a5b2000-07-29 13:06:59 +0000395expr(A) ::= NOT(B) expr(X). {
396 A = sqliteExpr(TK_NOT, X, 0, 0);
397 sqliteExprSpan(A,&B,&X->span);
398}
399expr(A) ::= MINUS(B) expr(X). [UMINUS] {
400 A = sqliteExpr(TK_UMINUS, X, 0, 0);
401 sqliteExprSpan(A,&B,&X->span);
402}
403expr(A) ::= PLUS(B) expr(X). [UMINUS] {
404 A = X;
405 sqliteExprSpan(A,&B,&X->span);
406}
407expr(A) ::= LP(B) select(X) RP(E). {
drh19a775c2000-06-05 18:54:46 +0000408 A = sqliteExpr(TK_SELECT, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000409 if( A ) A->pSelect = X;
drhe1b6a5b2000-07-29 13:06:59 +0000410 sqliteExprSpan(A,&B,&E);
drh19a775c2000-06-05 18:54:46 +0000411}
drhfef52082000-06-06 01:50:43 +0000412expr(A) ::= expr(W) 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;
drhe1b6a5b2000-07-29 13:06:59 +0000417 sqliteExprSpan(A,&W->span,&Y->span);
drhfef52082000-06-06 01:50:43 +0000418}
drh4794b982000-06-06 13:54:14 +0000419expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
420 ExprList *pList = sqliteExprListAppend(0, X, 0);
421 pList = sqliteExprListAppend(pList, Y, 0);
422 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000423 if( A ) A->pList = pList;
drh4794b982000-06-06 13:54:14 +0000424 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000425 sqliteExprSpan(A,&W->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000426}
drhe1b6a5b2000-07-29 13:06:59 +0000427expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000428 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000429 if( A ) A->pList = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000430 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000431}
drhe1b6a5b2000-07-29 13:06:59 +0000432expr(A) ::= expr(X) IN LP select(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000433 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000434 if( A ) A->pSelect = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000435 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000436}
drhe1b6a5b2000-07-29 13:06:59 +0000437expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000438 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000439 if( A ) A->pList = Y;
drh4794b982000-06-06 13:54:14 +0000440 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000441 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000442}
drhe1b6a5b2000-07-29 13:06:59 +0000443expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000444 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000445 if( A ) A->pSelect = Y;
drh4794b982000-06-06 13:54:14 +0000446 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000447 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000448}
drhfef52082000-06-06 01:50:43 +0000449
450
drh348784e2000-05-29 20:41:49 +0000451
452%type exprlist {ExprList*}
453%destructor exprlist {sqliteExprListDelete($$);}
454%type expritem {Expr*}
455%destructor expritem {sqliteExprDelete($$);}
456
drh348784e2000-05-29 20:41:49 +0000457exprlist(A) ::= exprlist(X) COMMA expritem(Y).
458 {A = sqliteExprListAppend(X,Y,0);}
459exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
460expritem(A) ::= expr(X). {A = X;}
461expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000462
drh382c0242001-10-06 16:33:02 +0000463///////////////////////////// The CREATE INDEX command ///////////////////////
464//
drh717e6402001-09-27 03:22:32 +0000465cmd ::= CREATE(S) uniqueflag(U) INDEX ids(X) ON ids(Y) LP idxlist(Z) RP(E).
466 {sqliteCreateIndex(pParse, &X, &Y, Z, U, &S, &E);}
467
468%type uniqueflag {int}
469uniqueflag(A) ::= UNIQUE. { A = 1; }
470uniqueflag(A) ::= . { A = 0; }
drh348784e2000-05-29 20:41:49 +0000471
472%type idxlist {IdList*}
473%destructor idxlist {sqliteIdListDelete($$);}
474%type idxitem {Token}
475
476idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
477 {A = sqliteIdListAppend(X,&Y);}
478idxlist(A) ::= idxitem(Y).
479 {A = sqliteIdListAppend(0,&Y);}
drhc4a3c772001-04-04 11:48:57 +0000480idxitem(A) ::= ids(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000481
drh382c0242001-10-06 16:33:02 +0000482///////////////////////////// The CREATE INDEX command ///////////////////////
483//
484
drhc4a3c772001-04-04 11:48:57 +0000485cmd ::= DROP INDEX ids(X). {sqliteDropIndex(pParse, &X);}
drh982cef72000-05-30 16:27:03 +0000486
drh382c0242001-10-06 16:33:02 +0000487
488///////////////////////////// The DROP INDEX command /////////////////////////
489//
drhc4a3c772001-04-04 11:48:57 +0000490cmd ::= COPY ids(X) FROM ids(Y) USING DELIMITERS STRING(Z).
drh982cef72000-05-30 16:27:03 +0000491 {sqliteCopy(pParse,&X,&Y,&Z);}
drhc4a3c772001-04-04 11:48:57 +0000492cmd ::= COPY ids(X) FROM ids(Y).
drh982cef72000-05-30 16:27:03 +0000493 {sqliteCopy(pParse,&X,&Y,0);}
drhdce2cbe2000-05-31 02:27:49 +0000494
drh382c0242001-10-06 16:33:02 +0000495///////////////////////////// The VACUUM command /////////////////////////////
496//
drhdce2cbe2000-05-31 02:27:49 +0000497cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
drhc4a3c772001-04-04 11:48:57 +0000498cmd ::= VACUUM ids(X). {sqliteVacuum(pParse,&X);}
drhf57b14a2001-09-14 18:54:08 +0000499
drh382c0242001-10-06 16:33:02 +0000500///////////////////////////// The PRAGMA command /////////////////////////////
501//
drhf57b14a2001-09-14 18:54:08 +0000502cmd ::= PRAGMA ids(X) EQ ids(Y). {sqlitePragma(pParse,&X,&Y,0);}
503cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlitePragma(pParse,&X,&Y,0);}
504cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlitePragma(pParse,&X,&Y,0);}
505cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlitePragma(pParse,&X,&Y,1);}
drh382c0242001-10-06 16:33:02 +0000506cmd ::= PRAGMA ids(X) LP ids(Y) RP. {sqlitePragma(pParse,&X,&Y,0);}
drhf57b14a2001-09-14 18:54:08 +0000507plus_num(A) ::= plus_opt number(X). {A = X;}
508minus_num(A) ::= MINUS number(X). {A = X;}
509number(A) ::= INTEGER(X). {A = X;}
510number(A) ::= FLOAT(X). {A = X;}
511plus_opt ::= PLUS.
512plus_opt ::= .