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