Improved "Parser Statistics" output (the -s option) for the Lemon parser

generator.

FossilOrigin-Name: 809503e4efcdb498d176e8c0794a5ba0882adef2
This commit is contained in:
drh 2015-09-07 02:23:02 +00:00
parent 2d64034bc2
commit c75e0166f0
3 changed files with 61 additions and 28 deletions

View File

@ -1,5 +1,5 @@
C Improved\smemory\sbarrier\sthat\sshould\swork\swith\sMinGW\son\solder\sversions\sof\nWindows.
D 2015-09-06T10:31:37.987
C Improved\s"Parser\sStatistics"\soutput\s(the\s-s\soption)\sfor\sthe\sLemon\sparser\ngenerator.
D 2015-09-07T02:23:02.396
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in f85066ce844a28b671aaeeff320921cd0ce36239
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -1338,7 +1338,7 @@ F tool/fuzzershell.c f2fc86dd22df654b28851b85019d3bd007361751
F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4
F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5
F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce
F tool/lemon.c b12cb605725dabfa3a8607ec6bd9e978973c7af9
F tool/lemon.c cc515b02a6610ed76c93d49bd01fdb219356d7ac
F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc
F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862
F tool/logest.c eef612f8adf4d0993dafed0416064cf50d5d33c6
@ -1383,7 +1383,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 11a9a786ec06403addb47f5c6fb142b382fae522
R ddcc46edb79b17bfa61348716fbd1950
P 47dc24bd1e8f76eb17ba53a883b8984b3e1b2934
R d6df305b5709e894bdfc542577063f51
U drh
Z 19a2121ad81300b8c56d01dcfbdbe0e2
Z 643bd9ba035c2e0820f3e9522cf3c1e3

View File

@ -1 +1 @@
47dc24bd1e8f76eb17ba53a883b8984b3e1b2934
809503e4efcdb498d176e8c0794a5ba0882adef2

View File

@ -385,7 +385,8 @@ struct lemon {
char *outname; /* Name of the current output file */
char *tokenprefix; /* A prefix added to token names in the .h file */
int nconflict; /* Number of parsing conflicts */
int tablesize; /* Size of the parse tables */
int nactiontab; /* Number of entries in the yy_action[] table */
int tablesize; /* Total table size of all tables in bytes */
int basisflag; /* Print only basis configurations */
int has_fallback; /* True if any %fallback is seen in the grammar */
int nolinenosflag; /* True if #line statements should not be printed */
@ -1482,6 +1483,18 @@ static void handle_T_option(char *z){
lemon_strcpy(user_templatename, z);
}
/* forward reference */
static const char *minimum_size_type(int lwr, int upr, int *pnByte);
/* Print a single line of the "Parser Stats" output
*/
static void stats_line(const char *zLabel, int iValue){
int nLabel = lemonStrlen(zLabel);
printf(" %s%.*s %5d\n", zLabel,
35-nLabel, "................................",
iValue);
}
/* The main program. Parse the command line and do it... */
int main(int argc, char **argv)
{
@ -1613,11 +1626,15 @@ int main(int argc, char **argv)
if( !mhflag ) ReportHeader(&lem);
}
if( statistics ){
printf("Parser statistics: %d terminals, %d nonterminals, %d rules\n",
lem.nterminal, lem.nsymbol - lem.nterminal, lem.nrule);
printf(" %d states, %d parser table entries,"
" %d conflicts\n",
lem.nstate, lem.tablesize, lem.nconflict);
printf("Parser statistics:\n");
stats_line("terminal symbols", lem.nterminal);
stats_line("non-terminal symbols", lem.nsymbol - lem.nterminal);
stats_line("total symbols", lem.nsymbol);
stats_line("rules", lem.nrule);
stats_line("states", lem.nstate);
stats_line("conflicts", lem.nconflict);
stats_line("action table entries", lem.nactiontab);
stats_line("total table size (bytes)", lem.tablesize);
}
if( lem.nconflict > 0 ){
fprintf(stderr,"%d parsing conflicts.\n",lem.nconflict);
@ -3661,24 +3678,32 @@ void print_stack_union(
/*
** Return the name of a C datatype able to represent values between
** lwr and upr, inclusive.
** lwr and upr, inclusive. If pnByte!=NULL then also write the sizeof
** for that type (1, 2, or 4) into *pnByte.
*/
static const char *minimum_size_type(int lwr, int upr){
static const char *minimum_size_type(int lwr, int upr, int *pnByte){
const char *zType = "int";
int nByte = 4;
if( lwr>=0 ){
if( upr<=255 ){
return "unsigned char";
zType = "unsigned char";
nByte = 1;
}else if( upr<65535 ){
return "unsigned short int";
zType = "unsigned short int";
nByte = 2;
}else{
return "unsigned int";
zType = "unsigned int";
nByte = 4;
}
}else if( lwr>=-127 && upr<=127 ){
return "signed char";
zType = "signed char";
nByte = 1;
}else if( lwr>=-32767 && upr<32767 ){
return "short";
}else{
return "int";
zType = "short";
nByte = 2;
}
if( pnByte ) *pnByte = nByte;
return zType;
}
/*
@ -3742,7 +3767,9 @@ void ReportTable(
struct action *ap;
struct rule *rp;
struct acttab *pActtab;
int i, j, n;
int i, j, n, sz;
int szActionType; /* sizeof(YYACTIONTYPE) */
int szCodeType; /* sizeof(YYCODETYPE) */
const char *name;
int mnTknOfst, mxTknOfst;
int mnNtOfst, mxNtOfst;
@ -3783,10 +3810,10 @@ void ReportTable(
/* Generate the defines */
fprintf(out,"#define YYCODETYPE %s\n",
minimum_size_type(0, lemp->nsymbol+1)); lineno++;
minimum_size_type(0, lemp->nsymbol+1, &szCodeType)); lineno++;
fprintf(out,"#define YYNOCODE %d\n",lemp->nsymbol+1); lineno++;
fprintf(out,"#define YYACTIONTYPE %s\n",
minimum_size_type(0, lemp->nstate+lemp->nrule+5)); lineno++;
minimum_size_type(0, lemp->nstate+lemp->nrule+5, &szActionType)); lineno++;
if( lemp->wildcard ){
fprintf(out,"#define YYWILDCARD %d\n",
lemp->wildcard->index); lineno++;
@ -3900,7 +3927,8 @@ void ReportTable(
free(ax);
/* Output the yy_action table */
n = acttab_size(pActtab);
lemp->nactiontab = n = acttab_size(pActtab);
lemp->tablesize += n*szActionType;
fprintf(out,"#define YY_ACTTAB_COUNT (%d)\n", n); lineno++;
fprintf(out,"static const YYACTIONTYPE yy_action[] = {\n"); lineno++;
for(i=j=0; i<n; i++){
@ -3918,6 +3946,7 @@ void ReportTable(
fprintf(out, "};\n"); lineno++;
/* Output the yy_lookahead table */
lemp->tablesize += n*szCodeType;
fprintf(out,"static const YYCODETYPE yy_lookahead[] = {\n"); lineno++;
for(i=j=0; i<n; i++){
int la = acttab_yylookahead(pActtab, i);
@ -3941,7 +3970,8 @@ void ReportTable(
fprintf(out, "#define YY_SHIFT_MIN (%d)\n", mnTknOfst); lineno++;
fprintf(out, "#define YY_SHIFT_MAX (%d)\n", mxTknOfst); lineno++;
fprintf(out, "static const %s yy_shift_ofst[] = {\n",
minimum_size_type(mnTknOfst-1, mxTknOfst)); lineno++;
minimum_size_type(mnTknOfst-1, mxTknOfst, &sz)); lineno++;
lemp->tablesize += n*sz;
for(i=j=0; i<n; i++){
int ofst;
stp = lemp->sorted[i];
@ -3966,7 +3996,8 @@ void ReportTable(
fprintf(out, "#define YY_REDUCE_MIN (%d)\n", mnNtOfst); lineno++;
fprintf(out, "#define YY_REDUCE_MAX (%d)\n", mxNtOfst); lineno++;
fprintf(out, "static const %s yy_reduce_ofst[] = {\n",
minimum_size_type(mnNtOfst-1, mxNtOfst)); lineno++;
minimum_size_type(mnNtOfst-1, mxNtOfst, &sz)); lineno++;
lemp->tablesize += n*sz;
for(i=j=0; i<n; i++){
int ofst;
stp = lemp->sorted[i];
@ -3986,6 +4017,7 @@ void ReportTable(
/* Output the default action table */
fprintf(out, "static const YYACTIONTYPE yy_default[] = {\n"); lineno++;
n = lemp->nstate;
lemp->tablesize += n*szActionType;
for(i=j=0; i<n; i++){
stp = lemp->sorted[i];
if( j==0 ) fprintf(out," /* %5d */ ", i);
@ -4005,6 +4037,7 @@ void ReportTable(
if( lemp->has_fallback ){
int mx = lemp->nterminal - 1;
while( mx>0 && lemp->symbols[mx]->fallback==0 ){ mx--; }
lemp->tablesize += (mx+1)*szCodeType;
for(i=0; i<=mx; i++){
struct symbol *p = lemp->symbols[i];
if( p->fallback==0 ){