/ Check-in [dcf2bafc]
Login

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

Overview
Comment:Enhance LEMON to track which symbols actually carry semantic content. Output the list of symbols that do not carry content at the end of the report, but do not (yet) do anything else with the information.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:dcf2bafc159179859b91ffea3a4ebd70b5ca6de9e1d515eaf9afde8cfff26c6c
User & Date: drh 2018-04-21 20:24:19
Context
2018-04-21
22:40
Performance improvements on the main loop of the LEMON-generated parser. check-in: fec1ebad user: drh tags: trunk
20:24
Enhance LEMON to track which symbols actually carry semantic content. Output the list of symbols that do not carry content at the end of the report, but do not (yet) do anything else with the information. check-in: dcf2bafc user: drh tags: trunk
14:11
A few more tests for upsert. check-in: b78005b6 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/lemon.c.

   266    266     int destLineno;          /* Line number for start of destructor.  Set to
   267    267                              ** -1 for duplicate destructors. */
   268    268     char *datatype;          /* The data type of information held by this
   269    269                              ** object. Only used if type==NONTERMINAL */
   270    270     int dtnum;               /* The data type number.  In the parser, the value
   271    271                              ** stack is a union.  The .yy%d element of this
   272    272                              ** union is the correct data type for this object */
          273  +  int bContent;            /* True if this symbol ever carries content - if
          274  +                           ** it is ever more than just syntax */
   273    275     /* The following fields are used by MULTITERMINALs only */
   274    276     int nsubsym;             /* Number of constituent symbols in the MULTI */
   275    277     struct symbol **subsym;  /* Array of constituent symbols */
   276    278   };
   277    279   
   278    280   /* Each production rule in the grammar is stored in the following
   279    281   ** structure.  */
................................................................................
  2373   2375             int i;
  2374   2376             rp->ruleline = psp->tokenlineno;
  2375   2377             rp->rhs = (struct symbol**)&rp[1];
  2376   2378             rp->rhsalias = (const char**)&(rp->rhs[psp->nrhs]);
  2377   2379             for(i=0; i<psp->nrhs; i++){
  2378   2380               rp->rhs[i] = psp->rhs[i];
  2379   2381               rp->rhsalias[i] = psp->alias[i];
         2382  +            if( rp->rhsalias[i]!=0 ){ rp->rhs[i]->bContent = 1; }
  2380   2383             }
  2381   2384             rp->lhs = psp->lhs;
  2382   2385             rp->lhsalias = psp->lhsalias;
  2383   2386             rp->nrhs = psp->nrhs;
  2384   2387             rp->code = 0;
  2385   2388             rp->noCode = 1;
  2386   2389             rp->precsym = 0;
................................................................................
  3278   3281     }
  3279   3282     return result;
  3280   3283   }
  3281   3284   
  3282   3285   /* Generate the "*.out" log file */
  3283   3286   void ReportOutput(struct lemon *lemp)
  3284   3287   {
  3285         -  int i;
         3288  +  int i, n;
  3286   3289     struct state *stp;
  3287   3290     struct config *cfp;
  3288   3291     struct action *ap;
  3289   3292     struct rule *rp;
  3290   3293     FILE *fp;
  3291   3294   
  3292   3295     fp = file_open(lemp,".out","wb");
................................................................................
  3318   3321       for(ap=stp->ap; ap; ap=ap->next){
  3319   3322         if( PrintAction(ap,fp,30) ) fprintf(fp,"\n");
  3320   3323       }
  3321   3324       fprintf(fp,"\n");
  3322   3325     }
  3323   3326     fprintf(fp, "----------------------------------------------------\n");
  3324   3327     fprintf(fp, "Symbols:\n");
         3328  +  fprintf(fp, "The first-set of non-terminals is shown after the name.\n\n");
  3325   3329     for(i=0; i<lemp->nsymbol; i++){
  3326   3330       int j;
  3327   3331       struct symbol *sp;
  3328   3332   
  3329   3333       sp = lemp->symbols[i];
  3330   3334       fprintf(fp, "  %3d: %s", i, sp->name);
  3331   3335       if( sp->type==NONTERMINAL ){
................................................................................
  3338   3342             fprintf(fp, " %s", lemp->symbols[j]->name);
  3339   3343           }
  3340   3344         }
  3341   3345       }
  3342   3346       if( sp->prec>=0 ) fprintf(fp," (precedence=%d)", sp->prec);
  3343   3347       fprintf(fp, "\n");
  3344   3348     }
         3349  +  fprintf(fp, "----------------------------------------------------\n");
         3350  +  fprintf(fp, "Syntax-only Symbols:\n");
         3351  +  fprintf(fp, "The following symbols never carry semantic content.\n\n");
         3352  +  for(i=n=0; i<lemp->nsymbol; i++){
         3353  +    int w;
         3354  +    struct symbol *sp = lemp->symbols[i];
         3355  +    if( sp->bContent ) continue;
         3356  +    w = (int)strlen(sp->name);
         3357  +    if( n>0 && n+w>75 ){
         3358  +      fprintf(fp,"\n");
         3359  +      n = 0;
         3360  +    }
         3361  +    if( n>0 ){
         3362  +      fprintf(fp, " ");
         3363  +      n++;
         3364  +    }
         3365  +    fprintf(fp, "%s", sp->name);
         3366  +    n += w;
         3367  +  }
         3368  +  if( n>0 ) fprintf(fp, "\n");
  3345   3369     fprintf(fp, "----------------------------------------------------\n");
  3346   3370     fprintf(fp, "Rules:\n");
  3347   3371     for(rp=lemp->rule; rp; rp=rp->next){
  3348   3372       fprintf(fp, "%4d: ", rp->iRule);
  3349   3373       rule_print(fp, rp);
  3350   3374       fprintf(fp,".");
  3351   3375       if( rp->precsym ){