SQLite

Check-in [f36b122d97]
Login

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

Overview
Comment:Do not sort terminal symbols by name. The terminals remain in the same order that they are encountered in the grammar file. This results in parse tables that are 25% smaller. (CVS 1261)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f36b122d9767fa9e6dc5bcce04b5606d67cad3d9
User & Date: drh 2004-02-22 00:08:05.000
Context
2004-02-22
16:27
Rearrange the grammar some so that tokens that are used together appear together in the grammar file. This reduces the size of the parser tables and some of the jump tables in switch statements. (CVS 1262) (check-in: d372c16ec6 user: drh tags: trunk)
00:08
Do not sort terminal symbols by name. The terminals remain in the same order that they are encountered in the grammar file. This results in parse tables that are 25% smaller. (CVS 1261) (check-in: f36b122d97 user: drh tags: trunk)
2004-02-21
19:41
Test cases for printf of double overflows. (CVS 1260) (check-in: 96a6d2d3ff user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to tool/lemon.c.
1383
1384
1385
1386
1387
1388
1389

1390
1391
1392
1393
1394
1395
1396
    exit(1);
  }

  /* Count and index the symbols of the grammar */
  lem.nsymbol = Symbol_count();
  Symbol_new("{default}");
  lem.symbols = Symbol_arrayof();

  qsort(lem.symbols,lem.nsymbol+1,sizeof(struct symbol*),
        (int(*)())Symbolcmpp);
  for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
  for(i=1; isupper(lem.symbols[i]->name[0]); i++);
  lem.nterminal = i;

  /* Generate a reprint of the grammar, if requested on the command line */







>







1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
    exit(1);
  }

  /* Count and index the symbols of the grammar */
  lem.nsymbol = Symbol_count();
  Symbol_new("{default}");
  lem.symbols = Symbol_arrayof();
  for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
  qsort(lem.symbols,lem.nsymbol+1,sizeof(struct symbol*),
        (int(*)())Symbolcmpp);
  for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
  for(i=1; isupper(lem.symbols[i]->name[0]); i++);
  lem.nterminal = i;

  /* Generate a reprint of the grammar, if requested on the command line */
3882
3883
3884
3885
3886
3887
3888
3889

3890


3891




3892
3893


3894
3895
3896
3897
3898
3899
3900
3901
    sp->destructor = 0;
    sp->datatype = 0;
    Symbol_insert(sp,sp->name);
  }
  return sp;
}

/* Compare two symbols */

int Symbolcmpp(a,b)


struct symbol **a;




struct symbol **b;
{


  return strcmp((**a).name,(**b).name);
}

/* There is one instance of the following structure for each
** associative array of type "x2".
*/
struct s_x2 {
  int size;               /* The number of available slots. */







|
>
|
>
>
|
>
>
>
>
|
<
>
>
|







3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900

3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
    sp->destructor = 0;
    sp->datatype = 0;
    Symbol_insert(sp,sp->name);
  }
  return sp;
}

/* Compare two symbols for working purposes
**
** Symbols that begin with upper case letters (terminals or tokens)
** must sort before symbols that begin with lower case letters
** (non-terminals).  Other than that, the order does not matter.
**
** We find experimentally that leaving the symbols in their original
** order (the order they appeared in the grammar file) gives the
** smallest parser tables in SQLite.
*/
int Symbolcmpp(struct symbol **a, struct symbol **b){

  int i1 = (**a).index + 10000000*((**a).name[0]>'Z');
  int i2 = (**b).index + 10000000*((**b).name[0]>'Z');
  return i1-i2;
}

/* There is one instance of the following structure for each
** associative array of type "x2".
*/
struct s_x2 {
  int size;               /* The number of available slots. */