drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 1 | /* |
| 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 | ** |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame^] | 29 | ** @(#) $Id: parse.y,v 1.12 2000/06/06 13:54:15 drh Exp $ |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 30 | */ |
| 31 | %token_prefix TK_ |
| 32 | %token_type {Token} |
| 33 | %extra_argument {Parse *pParse} |
| 34 | %syntax_error { |
| 35 | sqliteSetNString(&pParse->zErrMsg,"syntax error near \"",0,TOKEN.z,TOKEN.n, |
| 36 | "\"", 1, 0); |
| 37 | pParse->sErrToken = TOKEN; |
| 38 | } |
| 39 | %name sqliteParser |
| 40 | %include { |
| 41 | #include "sqliteInt.h" |
| 42 | #include "parse.h" |
| 43 | } |
| 44 | |
| 45 | |
| 46 | // Input is zero or more commands. |
| 47 | input ::= cmdlist. |
| 48 | |
| 49 | // These are extra tokens used by the lexer but never seen by the |
| 50 | // parser. We put them in a rule so that the parser generator will |
| 51 | // add them to the sqliteTokens.h output file. |
| 52 | // |
| 53 | input ::= END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION |
| 54 | UMINUS FIELD. |
| 55 | |
| 56 | // A list of commands is zero or more commands |
| 57 | // |
| 58 | cmdlist ::= ecmd. |
| 59 | cmdlist ::= cmdlist SEMI ecmd. |
| 60 | ecmd ::= explain cmd. {sqliteExec(pParse);} |
| 61 | ecmd ::= cmd. {sqliteExec(pParse);} |
| 62 | ecmd ::= . |
| 63 | explain ::= EXPLAIN. {pParse->explain = 1;} |
| 64 | |
| 65 | // The first form of a command is a CREATE TABLE statement. |
| 66 | // |
| 67 | cmd ::= create_table create_table_args. |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 68 | create_table ::= CREATE(X) TABLE id(Y). {sqliteStartTable(pParse,&X,&Y);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 69 | create_table_args ::= LP columnlist conslist_opt RP(X). |
| 70 | {sqliteEndTable(pParse,&X);} |
| 71 | columnlist ::= columnlist COMMA column. |
| 72 | columnlist ::= column. |
| 73 | |
| 74 | // About the only information used for a column is the name of the |
| 75 | // column. The type is always just "text". But the code will accept |
| 76 | // an elaborate typename. Perhaps someday we'll do something with it. |
| 77 | // |
| 78 | column ::= columnid type carglist. |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 79 | columnid ::= id(X). {sqliteAddColumn(pParse,&X);} |
| 80 | %type id {Token} |
| 81 | id(A) ::= ID(X). {A = X;} |
| 82 | id(A) ::= STRING(X). {A = X;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 83 | type ::= typename. |
| 84 | type ::= typename LP signed RP. |
| 85 | type ::= typename LP signed COMMA signed RP. |
| 86 | typename ::= ID. |
| 87 | typename ::= typename ID. |
| 88 | signed ::= INTEGER. |
| 89 | signed ::= PLUS INTEGER. |
| 90 | signed ::= MINUS INTEGER. |
| 91 | carglist ::= carglist carg. |
| 92 | carglist ::= . |
| 93 | carg ::= CONSTRAINT ID ccons. |
| 94 | carg ::= ccons. |
drh | 7020f65 | 2000-06-03 18:06:52 +0000 | [diff] [blame] | 95 | carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 96 | carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 97 | carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 98 | carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 99 | carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);} |
| 100 | carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 101 | carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 102 | carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);} |
| 103 | carg ::= DEFAULT NULL. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 104 | |
| 105 | // In addition to the type name, we also care about the primary key. |
| 106 | // |
| 107 | ccons ::= NOT NULL. |
| 108 | ccons ::= PRIMARY KEY sortorder. |
| 109 | {sqliteCreateIndex(pParse,0,0,0,0,0);} |
| 110 | ccons ::= UNIQUE. |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame^] | 111 | ccons ::= CHECK LP expr RP. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 112 | |
| 113 | // For the time being, the only constraint we care about is the primary |
| 114 | // key. |
| 115 | // |
| 116 | conslist_opt ::= . |
| 117 | conslist_opt ::= COMMA conslist. |
| 118 | conslist ::= conslist COMMA tcons. |
| 119 | conslist ::= tcons. |
| 120 | tcons ::= CONSTRAINT ID tcons2. |
| 121 | tcons ::= tcons2. |
| 122 | tcons2 ::= PRIMARY KEY LP idxlist(X) RP. |
| 123 | {sqliteCreateIndex(pParse,0,0,X,0,0);} |
| 124 | tcons2 ::= UNIQUE LP idlist RP. |
| 125 | tcons2 ::= CHECK expr. |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 126 | idlist ::= idlist COMMA id. |
| 127 | idlist ::= id. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 128 | |
| 129 | // The next command format is dropping tables. |
| 130 | // |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 131 | cmd ::= DROP TABLE id(X). {sqliteDropTable(pParse,&X);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 132 | |
| 133 | // The select statement |
| 134 | // |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 135 | cmd ::= select(X). { |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 136 | sqliteSelect(pParse, X, SRT_Callback, 0); |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 137 | sqliteSelectDelete(X); |
| 138 | } |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 139 | |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 140 | %type select {Select*} |
| 141 | %destructor select {sqliteSelectDelete($$);} |
| 142 | |
| 143 | select(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y) |
| 144 | orderby_opt(Z). { |
| 145 | A = sqliteSelectNew(W,X,Y,0,0,Z,D); |
| 146 | } |
| 147 | |
| 148 | // The "distinct" nonterminal is true (1) if the DISTINCT keyword is |
| 149 | // present and false (0) if it is not. |
| 150 | // |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 151 | %type distinct {int} |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 152 | distinct(A) ::= DISTINCT. {A = 1;} |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 153 | distinct(A) ::= ALL. {A = 0;} |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 154 | distinct(A) ::= . {A = 0;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 155 | |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 156 | // selcollist is a list of expressions that are to become the return |
| 157 | // values of the SELECT statement. In the case of "SELECT * FROM ..." |
| 158 | // the selcollist value is NULL. |
| 159 | // |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 160 | %type selcollist {ExprList*} |
| 161 | %destructor selcollist {sqliteExprListDelete($$);} |
| 162 | %type sclp {ExprList*} |
| 163 | %destructor sclp {sqliteExprListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 164 | sclp(A) ::= selcollist(X) COMMA. {A = X;} |
| 165 | sclp(A) ::= . {A = 0;} |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 166 | selcollist(A) ::= STAR. {A = 0;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 167 | selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);} |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 168 | selcollist(A) ::= sclp(P) expr(X) as ID(Y). {A = sqliteExprListAppend(P,X,&Y);} |
| 169 | selcollist(A) ::= sclp(P) expr(X) as STRING(Y). |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 170 | {A = sqliteExprListAppend(P,X,&Y);} |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 171 | as ::= . |
| 172 | as ::= AS. |
| 173 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 174 | |
| 175 | %type seltablist {IdList*} |
| 176 | %destructor seltablist {sqliteIdListDelete($$);} |
| 177 | %type stl_prefix {IdList*} |
| 178 | %destructor stl_prefix {sqliteIdListDelete($$);} |
| 179 | %type from {IdList*} |
| 180 | %destructor from {sqliteIdListDelete($$);} |
| 181 | |
| 182 | from(A) ::= FROM seltablist(X). {A = X;} |
| 183 | stl_prefix(A) ::= seltablist(X) COMMA. {A = X;} |
| 184 | stl_prefix(A) ::= . {A = 0;} |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 185 | seltablist(A) ::= stl_prefix(X) id(Y). {A = sqliteIdListAppend(X,&Y);} |
| 186 | seltablist(A) ::= stl_prefix(X) id(Y) AS id(Z). |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 187 | {A = sqliteIdListAppend(X,&Y); |
| 188 | sqliteIdListAddAlias(A,&Z);} |
| 189 | |
| 190 | %type orderby_opt {ExprList*} |
| 191 | %destructor orderby_opt {sqliteExprListDelete($$);} |
| 192 | %type sortlist {ExprList*} |
| 193 | %destructor sortlist {sqliteExprListDelete($$);} |
| 194 | %type sortitem {Expr*} |
| 195 | %destructor sortitem {sqliteExprDelete($$);} |
| 196 | |
| 197 | orderby_opt(A) ::= . {A = 0;} |
| 198 | orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;} |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 199 | sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). { |
| 200 | A = sqliteExprListAppend(X,Y,0); |
| 201 | A->a[A->nExpr-1].idx = Z; /* 0 for ascending order, 1 for decending */ |
| 202 | } |
| 203 | sortlist(A) ::= sortitem(Y) sortorder(Z). { |
| 204 | A = sqliteExprListAppend(0,Y,0); |
| 205 | A->a[0].idx = Z; |
| 206 | } |
drh | da9d6c4 | 2000-05-31 18:20:14 +0000 | [diff] [blame] | 207 | sortitem(A) ::= expr(X). {A = X;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 208 | |
| 209 | %type sortorder {int} |
| 210 | |
| 211 | sortorder(A) ::= ASC. {A = 0;} |
| 212 | sortorder(A) ::= DESC. {A = 1;} |
| 213 | sortorder(A) ::= . {A = 0;} |
| 214 | |
| 215 | cmd ::= DELETE FROM ID(X) where_opt(Y). |
| 216 | {sqliteDeleteFrom(pParse, &X, Y);} |
| 217 | |
| 218 | %type where_opt {Expr*} |
| 219 | %destructor where_opt {sqliteExprDelete($$);} |
| 220 | |
| 221 | where_opt(A) ::= . {A = 0;} |
| 222 | where_opt(A) ::= WHERE expr(X). {A = X;} |
| 223 | |
| 224 | %type setlist {ExprList*} |
| 225 | %destructor setlist {sqliteExprListDelete($$);} |
| 226 | |
| 227 | cmd ::= UPDATE ID(X) SET setlist(Y) where_opt(Z). |
| 228 | {sqliteUpdate(pParse,&X,Y,Z);} |
| 229 | |
| 230 | setlist(A) ::= ID(X) EQ expr(Y) COMMA setlist(Z). |
| 231 | {A = sqliteExprListAppend(Z,Y,&X);} |
| 232 | setlist(A) ::= ID(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);} |
| 233 | |
| 234 | cmd ::= INSERT INTO ID(X) fieldlist_opt(F) VALUES LP itemlist(Y) RP. |
| 235 | {sqliteInsert(pParse, &X, Y, F);} |
| 236 | |
| 237 | |
| 238 | %type itemlist {ExprList*} |
| 239 | %destructor itemlist {sqliteExprListDelete($$);} |
| 240 | %type item {Expr*} |
| 241 | %destructor item {sqliteExprDelete($$);} |
| 242 | |
| 243 | itemlist(A) ::= itemlist(X) COMMA item(Y). {A = sqliteExprListAppend(X,Y,0);} |
| 244 | itemlist(A) ::= item(X). {A = sqliteExprListAppend(0,X,0);} |
| 245 | item(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);} |
drh | 7020f65 | 2000-06-03 18:06:52 +0000 | [diff] [blame] | 246 | item(A) ::= PLUS INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);} |
| 247 | item(A) ::= MINUS INTEGER(X). { |
| 248 | A = sqliteExpr(TK_INTEGER, 0, 0, 0); |
| 249 | A->token.z = 0; |
| 250 | sqliteSetNString(&A->token.z, "-", 1, X.z, X.n, 0); |
| 251 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 252 | item(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);} |
drh | 7020f65 | 2000-06-03 18:06:52 +0000 | [diff] [blame] | 253 | item(A) ::= PLUS FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);} |
| 254 | item(A) ::= MINUS FLOAT(X). { |
| 255 | A = sqliteExpr(TK_FLOAT, 0, 0, 0); |
| 256 | A->token.z = 0; |
| 257 | sqliteSetNString(&A->token.z, "-", 1, X.z, X.n, 0); |
| 258 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 259 | item(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);} |
drh | 8be5113 | 2000-06-03 19:19:41 +0000 | [diff] [blame] | 260 | item(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 261 | |
| 262 | %type fieldlist_opt {IdList*} |
| 263 | %destructor fieldlist_opt {sqliteIdListDelete($$);} |
| 264 | %type fieldlist {IdList*} |
| 265 | %destructor fieldlist {sqliteIdListDelete($$);} |
| 266 | |
| 267 | fieldlist_opt(A) ::= . {A = 0;} |
| 268 | fieldlist_opt(A) ::= LP fieldlist(X) RP. {A = X;} |
| 269 | fieldlist(A) ::= fieldlist(X) COMMA ID(Y). {A = sqliteIdListAppend(X,&Y);} |
| 270 | fieldlist(A) ::= ID(Y). {A = sqliteIdListAppend(0,&Y);} |
| 271 | |
| 272 | %left OR. |
| 273 | %left AND. |
drh | 8be5113 | 2000-06-03 19:19:41 +0000 | [diff] [blame] | 274 | %right NOT. |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 275 | %left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 276 | %left GT GE LT LE. |
| 277 | %left PLUS MINUS. |
| 278 | %left STAR SLASH PERCENT. |
drh | 8be5113 | 2000-06-03 19:19:41 +0000 | [diff] [blame] | 279 | %right UMINUS. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 280 | |
| 281 | %type expr {Expr*} |
| 282 | %destructor expr {sqliteExprDelete($$);} |
| 283 | |
| 284 | expr(A) ::= LP expr(X) RP. {A = X;} |
| 285 | expr(A) ::= ID(X). {A = sqliteExpr(TK_ID, 0, 0, &X);} |
| 286 | expr(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);} |
| 287 | expr(A) ::= ID(X) DOT ID(Y). {Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X); |
| 288 | Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y); |
| 289 | A = sqliteExpr(TK_DOT, temp1, temp2, 0);} |
| 290 | expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);} |
| 291 | expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);} |
| 292 | expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);} |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 293 | expr(A) ::= ID(X) LP exprlist(Y) RP. {A = sqliteExprFunction(Y, &X);} |
| 294 | expr(A) ::= ID(X) LP STAR RP. {A = sqliteExprFunction(0, &X);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 295 | expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);} |
| 296 | expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);} |
| 297 | expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);} |
| 298 | expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);} |
| 299 | expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);} |
| 300 | expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);} |
| 301 | expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);} |
| 302 | expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);} |
drh | dce2cbe | 2000-05-31 02:27:49 +0000 | [diff] [blame] | 303 | expr(A) ::= expr(X) LIKE expr(Y). {A = sqliteExpr(TK_LIKE, X, Y, 0);} |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame^] | 304 | expr(A) ::= expr(X) NOT LIKE expr(Y). { |
| 305 | A = sqliteExpr(TK_LIKE, X, Y, 0); |
| 306 | A = sqliteExpr(TK_NOT, A, 0, 0); |
| 307 | } |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 308 | expr(A) ::= expr(X) GLOB expr(Y). {A = sqliteExpr(TK_GLOB,X,Y,0);} |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame^] | 309 | expr(A) ::= expr(X) NOT GLOB expr(Y). { |
| 310 | A = sqliteExpr(TK_GLOB, X, Y, 0); |
| 311 | A = sqliteExpr(TK_NOT, A, 0, 0); |
| 312 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 313 | expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);} |
| 314 | expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);} |
| 315 | expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);} |
| 316 | expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);} |
| 317 | expr(A) ::= expr(X) ISNULL. {A = sqliteExpr(TK_ISNULL, X, 0, 0);} |
| 318 | expr(A) ::= expr(X) NOTNULL. {A = sqliteExpr(TK_NOTNULL, X, 0, 0);} |
| 319 | expr(A) ::= NOT expr(X). {A = sqliteExpr(TK_NOT, X, 0, 0);} |
drh | 8be5113 | 2000-06-03 19:19:41 +0000 | [diff] [blame] | 320 | expr(A) ::= MINUS expr(X). [UMINUS] {A = sqliteExpr(TK_UMINUS, X, 0, 0);} |
| 321 | expr(A) ::= PLUS expr(X). [UMINUS] {A = X;} |
drh | 19a775c | 2000-06-05 18:54:46 +0000 | [diff] [blame] | 322 | expr(A) ::= LP select(X) RP. { |
| 323 | A = sqliteExpr(TK_SELECT, 0, 0, 0); |
| 324 | A->pSelect = X; |
| 325 | } |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 326 | expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). { |
| 327 | ExprList *pList = sqliteExprListAppend(0, X, 0); |
| 328 | pList = sqliteExprListAppend(pList, Y, 0); |
| 329 | A = sqliteExpr(TK_BETWEEN, W, 0, 0); |
| 330 | A->pList = pList; |
| 331 | } |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame^] | 332 | expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). { |
| 333 | ExprList *pList = sqliteExprListAppend(0, X, 0); |
| 334 | pList = sqliteExprListAppend(pList, Y, 0); |
| 335 | A = sqliteExpr(TK_BETWEEN, W, 0, 0); |
| 336 | A->pList = pList; |
| 337 | A = sqliteExpr(TK_NOT, A, 0, 0); |
| 338 | } |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 339 | expr(A) ::= expr(X) IN LP exprlist(Y) RP. { |
| 340 | A = sqliteExpr(TK_IN, X, 0, 0); |
| 341 | A->pList = Y; |
| 342 | } |
| 343 | expr(A) ::= expr(X) IN LP select(Y) RP. { |
| 344 | A = sqliteExpr(TK_IN, X, 0, 0); |
| 345 | A->pSelect = Y; |
| 346 | } |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame^] | 347 | expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP. { |
| 348 | A = sqliteExpr(TK_IN, X, 0, 0); |
| 349 | A->pList = Y; |
| 350 | A = sqliteExpr(TK_NOT, A, 0, 0); |
| 351 | } |
| 352 | expr(A) ::= expr(X) NOT IN LP select(Y) RP. { |
| 353 | A = sqliteExpr(TK_IN, X, 0, 0); |
| 354 | A->pSelect = Y; |
| 355 | A = sqliteExpr(TK_NOT, A, 0, 0); |
| 356 | } |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 357 | |
| 358 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 359 | |
| 360 | %type exprlist {ExprList*} |
| 361 | %destructor exprlist {sqliteExprListDelete($$);} |
| 362 | %type expritem {Expr*} |
| 363 | %destructor expritem {sqliteExprDelete($$);} |
| 364 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 365 | exprlist(A) ::= exprlist(X) COMMA expritem(Y). |
| 366 | {A = sqliteExprListAppend(X,Y,0);} |
| 367 | exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);} |
| 368 | expritem(A) ::= expr(X). {A = X;} |
| 369 | expritem(A) ::= . {A = 0;} |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 370 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 371 | |
| 372 | cmd ::= CREATE(S) uniqueflag INDEX ID(X) ON ID(Y) LP idxlist(Z) RP(E). |
| 373 | {sqliteCreateIndex(pParse, &X, &Y, Z, &S, &E);} |
| 374 | uniqueflag ::= UNIQUE. |
| 375 | uniqueflag ::= . |
| 376 | |
| 377 | %type idxlist {IdList*} |
| 378 | %destructor idxlist {sqliteIdListDelete($$);} |
| 379 | %type idxitem {Token} |
| 380 | |
| 381 | idxlist(A) ::= idxlist(X) COMMA idxitem(Y). |
| 382 | {A = sqliteIdListAppend(X,&Y);} |
| 383 | idxlist(A) ::= idxitem(Y). |
| 384 | {A = sqliteIdListAppend(0,&Y);} |
| 385 | idxitem(A) ::= ID(X). {A = X;} |
| 386 | |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 387 | cmd ::= DROP INDEX id(X). {sqliteDropIndex(pParse, &X);} |
| 388 | |
| 389 | cmd ::= COPY id(X) FROM id(Y) USING DELIMITERS STRING(Z). |
| 390 | {sqliteCopy(pParse,&X,&Y,&Z);} |
| 391 | cmd ::= COPY id(X) FROM id(Y). |
| 392 | {sqliteCopy(pParse,&X,&Y,0);} |
drh | dce2cbe | 2000-05-31 02:27:49 +0000 | [diff] [blame] | 393 | |
| 394 | cmd ::= VACUUM. {sqliteVacuum(pParse,0);} |
| 395 | cmd ::= VACUUM id(X). {sqliteVacuum(pParse,&X);} |