/ Check-in [c46d94a8]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:In the lemon-generated parser, automatically promote SHIFTREDUCE actions on nonterminal systems to pure REDUCE actions, for a performance enhancement.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c46d94a8cde816ca383e771721ebd4900de77950cba700e35a26f70fd5b794a4
User & Date: drh 2017-06-28 11:56:18
Context
2017-06-28
13:47
In the lemon-generated parser, store the number of symbols on the RHS of each rule as a negative number and add it to the stack pointer, rather than storing the value as a positive and subtracting it. This makes the parser faster. check-in: b362f0d8 user: drh tags: trunk
11:56
In the lemon-generated parser, automatically promote SHIFTREDUCE actions on nonterminal systems to pure REDUCE actions, for a performance enhancement. check-in: c46d94a8 user: drh tags: trunk
01:21
Simplify error handling logic in sqlite3_exec() to save about 40 bytes. check-in: 6480916c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/lemon.c.

  3293   3293   ** Return negative if no action should be generated.
  3294   3294   */
  3295   3295   PRIVATE int compute_action(struct lemon *lemp, struct action *ap)
  3296   3296   {
  3297   3297     int act;
  3298   3298     switch( ap->type ){
  3299   3299       case SHIFT:  act = ap->x.stp->statenum;                        break;
  3300         -    case SHIFTREDUCE: act = ap->x.rp->iRule + lemp->nstate;        break;
         3300  +    case SHIFTREDUCE: {
         3301  +      act = ap->x.rp->iRule + lemp->nstate;
         3302  +      /* Since a SHIFT is inherient after a prior REDUCE, convert any
         3303  +      ** SHIFTREDUCE action with a nonterminal on the LHS into a simple
         3304  +      ** REDUCE action: */
         3305  +      if( ap->sp->index>=lemp->nterminal ) act += lemp->nrule;
         3306  +      break;
         3307  +    }
  3301   3308       case REDUCE: act = ap->x.rp->iRule + lemp->nstate+lemp->nrule; break;
  3302   3309       case ERROR:  act = lemp->nstate + lemp->nrule*2;               break;
  3303   3310       case ACCEPT: act = lemp->nstate + lemp->nrule*2 + 1;           break;
  3304   3311       default:     act = -1; break;
  3305   3312     }
  3306   3313     return act;
  3307   3314   }

Changes to tool/lempar.c.

   704    704   %%
   705    705   /********** End reduce actions ************************************************/
   706    706     };
   707    707     assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
   708    708     yygoto = yyRuleInfo[yyruleno].lhs;
   709    709     yysize = yyRuleInfo[yyruleno].nrhs;
   710    710     yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
   711         -  if( yyact <= YY_MAX_SHIFTREDUCE ){
   712         -    if( yyact>YY_MAX_SHIFT ){
   713         -      yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
   714         -    }
          711  +
          712  +  /* There are no SHIFTREDUCE actions on nonterminals because the table
          713  +  ** generator has simplified them to pure REDUCE actions. */
          714  +  assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
          715  +
          716  +  /* It is not possible for a REDUCE to be followed by an error */
          717  +  assert( yyact!=YY_ERROR_ACTION );
          718  +
          719  +  if( yyact==YY_ACCEPT_ACTION ){
          720  +    yypParser->yytos -= yysize;
          721  +    yy_accept(yypParser);
          722  +  }else{
   715    723       yymsp -= yysize-1;
   716    724       yypParser->yytos = yymsp;
   717    725       yymsp->stateno = (YYACTIONTYPE)yyact;
   718    726       yymsp->major = (YYCODETYPE)yygoto;
   719    727       yyTraceShift(yypParser, yyact);
   720         -  }else{
   721         -    assert( yyact == YY_ACCEPT_ACTION );
   722         -    yypParser->yytos -= yysize;
   723         -    yy_accept(yypParser);
   724    728     }
   725    729   }
   726    730   
   727    731   /*
   728    732   ** The following code executes when the parse fails
   729    733   */
   730    734   #ifndef YYNOERRORRECOVERY