📄 dump
字号:
1.1 (drh 29-May-00): /*1.30 (drh 16-Sep-01): ** 2001 September 151.1 (drh 29-May-00): **1.30 (drh 16-Sep-01): ** The author disclaims copyright to this source code. In place of1.30 (drh 16-Sep-01): ** a legal notice, here is a blessing:1.1 (drh 29-May-00): **1.30 (drh 16-Sep-01): ** May you do good and not evil.1.30 (drh 16-Sep-01): ** May you find forgiveness for yourself and forgive others.1.30 (drh 16-Sep-01): ** May you share freely, never taking more than you give.1.1 (drh 29-May-00): **1.1 (drh 29-May-00): *************************************************************************1.1 (drh 29-May-00): ** This file contains SQLite's grammar for SQL. Process this file1.1 (drh 29-May-00): ** using the lemon parser generator to generate C code that runs1.1 (drh 29-May-00): ** the parser. Lemon will also generate a header file containing1.1 (drh 29-May-00): ** numeric codes for all of the tokens.1.1 (drh 29-May-00): **1.99 (drh 16-Jul-03): ** @(#) $Id: parse.y,v 1.98 2003/05/17 19:04:04 drh Exp $1.1 (drh 29-May-00): */1.1 (drh 29-May-00): %token_prefix TK_1.1 (drh 29-May-00): %token_type {Token}1.29 (drh 14-Sep-01): %default_type {Token}1.1 (drh 29-May-00): %extra_argument {Parse *pParse}1.1 (drh 29-May-00): %syntax_error {1.89 (drh 28-Jan-03): if( pParse->zErrMsg==0 ){1.89 (drh 28-Jan-03): if( TOKEN.z[0] ){1.89 (drh 28-Jan-03): sqliteSetNString(&pParse->zErrMsg, 1.89 (drh 28-Jan-03): "near \"", -1, TOKEN.z, TOKEN.n, "\": syntax error", -1, 0);1.89 (drh 28-Jan-03): }else{1.89 (drh 28-Jan-03): sqliteSetString(&pParse->zErrMsg, "incomplete SQL statement", 0);1.89 (drh 28-Jan-03): }1.89 (drh 28-Jan-03): }1.89 (drh 28-Jan-03): pParse->nErr++;1.1 (drh 29-May-00): }1.1 (drh 29-May-00): %name sqliteParser1.1 (drh 29-May-00): %include {1.1 (drh 29-May-00): #include "sqliteInt.h"1.1 (drh 29-May-00): #include "parse.h"1.38 (drh 06-Nov-01): 1.38 (drh 06-Nov-01): /*1.68 (drh 24-May-02): ** An instance of this structure holds information about the1.68 (drh 24-May-02): ** LIMIT clause of a SELECT statement.1.38 (drh 06-Nov-01): */1.68 (drh 24-May-02): struct LimitVal {1.68 (drh 24-May-02): int limit; /* The LIMIT value. -1 if there is no limit */1.68 (drh 24-May-02): int offset; /* The OFFSET. 0 if there is none */1.68 (drh 24-May-02): };1.64 (danielk1 15-May-02): 1.64 (danielk1 15-May-02): /*1.68 (drh 24-May-02): ** An instance of the following structure describes the event of a1.68 (drh 24-May-02): ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,1.68 (drh 24-May-02): ** TK_DELETE, or TK_INSTEAD. If the event is of the form1.68 (drh 24-May-02): **1.68 (drh 24-May-02): ** UPDATE ON (a,b,c)1.68 (drh 24-May-02): **1.68 (drh 24-May-02): ** Then the "b" IdList records the list "a,b,c".1.64 (danielk1 15-May-02): */1.68 (drh 24-May-02): struct TrigEvent { int a; IdList * b; };1.86 (drh 07-Jan-03): 1.86 (drh 07-Jan-03): } // end %include1.1 (drh 29-May-00): 1.1 (drh 29-May-00): // These are extra tokens used by the lexer but never seen by the1.1 (drh 29-May-00): // parser. We put them in a rule so that the parser generator will1.22 (drh 19-Jun-00): // add them to the parse.h output file.1.1 (drh 29-May-00): //1.27 (drh 04-Apr-01): %nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION1.27 (drh 04-Apr-01): COLUMN AGG_FUNCTION.1.27 (drh 04-Apr-01): 1.27 (drh 04-Apr-01): // Input is zero or more commands.1.27 (drh 04-Apr-01): input ::= cmdlist.1.1 (drh 29-May-00): 1.1 (drh 29-May-00): // A list of commands is zero or more commands1.1 (drh 29-May-00): //1.1 (drh 29-May-00): cmdlist ::= ecmd.1.57 (drh 13-Mar-02): cmdlist ::= cmdlist ecmd.1.90 (drh 29-Jan-03): ecmd ::= explain cmdx SEMI.1.57 (drh 13-Mar-02): ecmd ::= SEMI.1.90 (drh 29-Jan-03): cmdx ::= cmd. { sqliteExec(pParse); }1.75 (drh 25-Jun-02): explain ::= EXPLAIN. { sqliteBeginParse(pParse, 1); }1.75 (drh 25-Jun-02): explain ::= . { sqliteBeginParse(pParse, 0); }1.1 (drh 29-May-00): 1.34 (drh 06-Oct-01): ///////////////////// Begin and end transactions. ////////////////////////////1.27 (drh 04-Apr-01): //1.46 (drh 02-Feb-02): 1.47 (drh 03-Feb-02): cmd ::= BEGIN trans_opt onconf(R). {sqliteBeginTransaction(pParse,R);}1.27 (drh 04-Apr-01): trans_opt ::= .1.27 (drh 04-Apr-01): trans_opt ::= TRANSACTION.1.76 (drh 01-Jul-02): trans_opt ::= TRANSACTION nm.1.27 (drh 04-Apr-01): cmd ::= COMMIT trans_opt. {sqliteCommitTransaction(pParse);}1.27 (drh 04-Apr-01): cmd ::= END trans_opt. {sqliteCommitTransaction(pParse);}1.27 (drh 04-Apr-01): cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);}1.27 (drh 04-Apr-01): 1.34 (drh 06-Oct-01): ///////////////////// The CREATE TABLE statement ////////////////////////////1.1 (drh 29-May-00): //1.1 (drh 29-May-00): cmd ::= create_table create_table_args.1.76 (drh 01-Jul-02): create_table ::= CREATE(X) temp(T) TABLE nm(Y). {1.87 (drh 13-Jan-03): sqliteStartTable(pParse,&X,&Y,T,0);1.51 (drh 18-Feb-02): }1.35 (drh 08-Oct-01): %type temp {int}1.93 (drh 27-Mar-03): temp(A) ::= TEMP. {A = 1;}1.93 (drh 27-Mar-03): temp(A) ::= . {A = 0;}1.51 (drh 18-Feb-02): create_table_args ::= LP columnlist conslist_opt RP(X). {1.51 (drh 18-Feb-02): sqliteEndTable(pParse,&X,0);1.51 (drh 18-Feb-02): }1.51 (drh 18-Feb-02): create_table_args ::= AS select(S). {1.51 (drh 18-Feb-02): sqliteEndTable(pParse,0,S);1.51 (drh 18-Feb-02): sqliteSelectDelete(S);1.51 (drh 18-Feb-02): }1.1 (drh 29-May-00): columnlist ::= columnlist COMMA column.1.1 (drh 29-May-00): columnlist ::= column.1.1 (drh 29-May-00): 1.1 (drh 29-May-00): // About the only information used for a column is the name of the1.1 (drh 29-May-00): // column. The type is always just "text". But the code will accept1.1 (drh 29-May-00): // an elaborate typename. Perhaps someday we'll do something with it.1.1 (drh 29-May-00): //1.1 (drh 29-May-00): column ::= columnid type carglist. 1.76 (drh 01-Jul-02): columnid ::= nm(X). {sqliteAddColumn(pParse,&X);}1.27 (drh 04-Apr-01): 1.27 (drh 04-Apr-01): // An IDENTIFIER can be a generic identifier, or one of several1.27 (drh 04-Apr-01): // keywords. Any non-standard keyword can also be an identifier.1.27 (drh 04-Apr-01): //1.2 (drh 30-May-00): %type id {Token}1.27 (drh 04-Apr-01): id(A) ::= ID(X). {A = X;}1.71 (drh 06-Jun-02): 1.72 (drh 06-Jun-02): // The following directive causes tokens ABORT, AFTER, ASC, etc. to1.72 (drh 06-Jun-02): // fallback to ID if they will not parse as their original value.1.72 (drh 06-Jun-02): // This obviates the need for the "id" nonterminal.1.72 (drh 06-Jun-02): //1.71 (drh 06-Jun-02): %fallback ID 1.92 (drh 20-Mar-03): ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT1.92 (drh 20-Mar-03): COPY DATABASE DEFERRED DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR1.76 (drh 01-Jul-02): IGNORE IMMEDIATE INITIALLY INSTEAD MATCH KEY1.76 (drh 01-Jul-02): OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT1.71 (drh 06-Jun-02): TEMP TRIGGER VACUUM VIEW.1.27 (drh 04-Apr-01): 1.27 (drh 04-Apr-01): // And "ids" is an identifer-or-string.1.27 (drh 04-Apr-01): //1.27 (drh 04-Apr-01): %type ids {Token}1.76 (drh 01-Jul-02): ids(A) ::= ID(X). {A = X;}1.27 (drh 04-Apr-01): ids(A) ::= STRING(X). {A = X;}1.27 (drh 04-Apr-01): 1.76 (drh 01-Jul-02): // The name of a column or table can be any of the following:1.76 (drh 01-Jul-02): //1.76 (drh 01-Jul-02): %type nm {Token}1.76 (drh 01-Jul-02): nm(A) ::= ID(X). {A = X;}1.76 (drh 01-Jul-02): nm(A) ::= STRING(X). {A = X;}1.76 (drh 01-Jul-02): nm(A) ::= JOIN_KW(X). {A = X;}1.76 (drh 01-Jul-02): 1.34 (drh 06-Oct-01): type ::= .1.34 (drh 06-Oct-01): type ::= typename(X). {sqliteAddColumnType(pParse,&X,&X);}1.34 (drh 06-Oct-01): type ::= typename(X) LP signed RP(Y). {sqliteAddColumnType(pParse,&X,&Y);}1.34 (drh 06-Oct-01): type ::= typename(X) LP signed COMMA signed RP(Y).1.34 (drh 06-Oct-01): {sqliteAddColumnType(pParse,&X,&Y);}1.34 (drh 06-Oct-01): %type typename {Token}1.34 (drh 06-Oct-01): typename(A) ::= ids(X). {A = X;}1.34 (drh 06-Oct-01): typename(A) ::= typename(X) ids. {A = X;}1.99 (drh 16-Jul-03): %type signed {int}1.99 (drh 16-Jul-03): signed(A) ::= INTEGER(X). { A = atoi(X.z); }1.99 (drh 16-Jul-03): signed(A) ::= PLUS INTEGER(X). { A = atoi(X.z); }1.99 (drh 16-Jul-03): signed(A) ::= MINUS INTEGER(X). { A = -atoi(X.z); }1.1 (drh 29-May-00): carglist ::= carglist carg.1.1 (drh 29-May-00): carglist ::= .1.76 (drh 01-Jul-02): carg ::= CONSTRAINT nm ccons.1.1 (drh 29-May-00): carg ::= ccons.1.7 (drh 03-Jun-00): carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}1.7 (drh 03-Jun-00): carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}1.7 (drh 03-Jun-00): carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}1.7 (drh 03-Jun-00): carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}1.7 (drh 03-Jun-00): carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}1.7 (drh 03-Jun-00): carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}1.7 (drh 03-Jun-00): carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}1.7 (drh 03-Jun-00): carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}1.7 (drh 03-Jun-00): carg ::= DEFAULT NULL. 1.1 (drh 29-May-00): 1.34 (drh 06-Oct-01): // In addition to the type name, we also care about the primary key and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -