aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-09-07 19:52:55 +0000
committerdrh <drh@noemail.net>2015-09-07 19:52:55 +0000
commita248a722cf721cf294bd591ccb2e7398aeb6ecdf (patch)
tree1d27185ec164d87da5a16593306cb9bb2b2467be /src
parent3bd48ab213bdfd776d04b4e9be4641bc0d0583e4 (diff)
downloadsqlite-a248a722cf721cf294bd591ccb2e7398aeb6ecdf.tar.gz
sqlite-a248a722cf721cf294bd591ccb2e7398aeb6ecdf.zip
Change the parser engine so that it (once again) waits for a lookahead token
before reducing, even in a SHIFTREDUCE action. FossilOrigin-Name: 2c17a1358353a0845b039283be79353f033e2491
Diffstat (limited to 'src')
-rw-r--r--src/lempar.c76
-rw-r--r--src/parse.y2
-rw-r--r--src/tokenize.c2
3 files changed, 42 insertions, 38 deletions
diff --git a/src/lempar.c b/src/lempar.c
index d014ebcc7..f983ff752 100644
--- a/src/lempar.c
+++ b/src/lempar.c
@@ -167,9 +167,13 @@ static const YYCODETYPE yyFallback[] = {
** + The semantic value stored at this level of the stack. This is
** the information used by the action routines in the grammar.
** It is sometimes called the "minor" token.
+**
+** After the "shift" half of a SHIFTREDUCE action, the stateno field
+** actually contains the reduce action for the second half of the
+** SHIFTREDUCE.
*/
struct yyStackEntry {
- YYACTIONTYPE stateno; /* The state-number */
+ YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
YYCODETYPE major; /* The major token value. This is the code
** number for the token at this stack level */
YYMINORTYPE minor; /* The user-supplied minor token value. This
@@ -403,6 +407,7 @@ static int yy_find_shift_action(
int i;
int stateno = pParser->yystack[pParser->yyidx].stateno;
+ if( stateno>=YY_MIN_REDUCE ) return stateno;
if( stateno>YY_SHIFT_COUNT
|| (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
return yy_default[stateno];
@@ -507,9 +512,31 @@ static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){
}
/*
+** Print tracing information for a SHIFT action
+*/
+#ifndef NDEBUG
+static void yyTraceShift(yyParser *yypParser, int yyNewState){
+ if( yyTraceFILE ){
+ int i;
+ if( yyNewState<YYNSTATE ){
+ fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
+ fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
+ for(i=1; i<=yypParser->yyidx; i++)
+ fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
+ fprintf(yyTraceFILE,"\n");
+ }else{
+ fprintf(yyTraceFILE,"%sShift *\n",yyTracePrompt);
+ }
+ }
+}
+#else
+# define yyTraceShift(X,Y)
+#endif
+
+/*
** Perform a shift action. Return the number of errors.
*/
-static int yy_shift(
+static void yy_shift(
yyParser *yypParser, /* The parser to be shifted */
int yyNewState, /* The new state to shift in */
int yyMajor, /* The major token to shift in */
@@ -525,14 +552,14 @@ static int yy_shift(
#if YYSTACKDEPTH>0
if( yypParser->yyidx>=YYSTACKDEPTH ){
yyStackOverflow(yypParser, yypMinor);
- return 1;
+ return;
}
#else
if( yypParser->yyidx>=yypParser->yystksz ){
yyGrowStack(yypParser);
if( yypParser->yyidx>=yypParser->yystksz ){
yyStackOverflow(yypParser, yypMinor);
- return 1;
+ return;
}
}
#endif
@@ -540,21 +567,7 @@ static int yy_shift(
yytos->stateno = (YYACTIONTYPE)yyNewState;
yytos->major = (YYCODETYPE)yyMajor;
yytos->minor = *yypMinor;
-#ifndef NDEBUG
- if( yyTraceFILE && yypParser->yyidx>0 ){
- int i;
- if( yyNewState<YYNSTATE ){
- fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
- fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
- for(i=1; i<=yypParser->yyidx; i++)
- fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
- fprintf(yyTraceFILE,"\n");
- }else{
- fprintf(yyTraceFILE,"%sShift *\n",yyTracePrompt);
- }
- }
-#endif
- return 0;
+ yyTraceShift(yypParser, yyNewState);
}
/* The following table contains information about every rule that
@@ -628,6 +641,7 @@ static void yy_reduce(
yypParser->yyidx -= yysize;
yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
if( yyact <= YY_MAX_SHIFTREDUCE ){
+ if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
/* If the reduce action popped at least
** one element off the stack, then we can push the new element back
** onto the stack here, and skip the stack overflow test in yy_shift().
@@ -638,16 +652,9 @@ static void yy_reduce(
yymsp->stateno = (YYACTIONTYPE)yyact;
yymsp->major = (YYCODETYPE)yygoto;
yymsp->minor = yygotominor;
-#ifndef NDEBUG
- if( yyTraceFILE ){
- fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyact);
- }
-#endif
+ yyTraceShift(yypParser, yyact);
}else{
- if( yy_shift(yypParser,yyact,yygoto,&yygotominor) ) yyact = 0;
- }
- if( yyact>=YY_MIN_SHIFTREDUCE ){
- yy_reduce(yypParser, yyact - YY_MIN_SHIFTREDUCE);
+ yy_shift(yypParser,yyact,yygoto,&yygotominor);
}
}else{
assert( yyact == YY_ACCEPT_ACTION );
@@ -775,13 +782,10 @@ void Parse(
do{
yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
if( yyact <= YY_MAX_SHIFTREDUCE ){
- if( yy_shift(yypParser,yyact,yymajor,&yyminorunion)==0 ){
- yypParser->yyerrcnt--;
- yymajor = YYNOCODE;
- if( yyact > YY_MAX_SHIFT ){
- yy_reduce(yypParser, yyact-YY_MIN_SHIFTREDUCE);
- }
- }
+ if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
+ yy_shift(yypParser,yyact,yymajor,&yyminorunion);
+ yypParser->yyerrcnt--;
+ yymajor = YYNOCODE;
}else if( yyact <= YY_MAX_REDUCE ){
yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
}else{
@@ -883,7 +887,7 @@ void Parse(
#endif
}
}while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
-#ifdef SQLITE_DEBUG
+#ifndef NDEBUG
if( yyTraceFILE ){
fprintf(yyTraceFILE,"%sReturn\n",yyTracePrompt);
}
diff --git a/src/parse.y b/src/parse.y
index cdfef7bd3..e99feeefc 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -587,7 +587,7 @@ from(A) ::= FROM seltablist(X). {
//
stl_prefix(A) ::= seltablist(X) joinop(Y). {
A = X;
- if( A && A->nSrc>0 ) A->a[A->nSrc-1].fg.jointype = (u8)Y;
+ if( ALWAYS(A && A->nSrc>0) ) A->a[A->nSrc-1].fg.jointype = (u8)Y;
}
stl_prefix(A) ::= . {A = 0;}
seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I)
diff --git a/src/tokenize.c b/src/tokenize.c
index 30a8ad06d..6b5ad2790 100644
--- a/src/tokenize.c
+++ b/src/tokenize.c
@@ -459,12 +459,12 @@ abort_parse:
assert( zSql[i]==0 );
if( lastTokenParsed!=TK_SEMI ){
sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
+ pParse->zTail = &zSql[i];
}
if( pParse->rc==SQLITE_OK && db->mallocFailed==0 ){
sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
}
}
- pParse->zTail = &zSql[i];
#ifdef YYTRACKMAXSTACKDEPTH
sqlite3_mutex_enter(sqlite3MallocMutex());
sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,