-C Fix\san\sassert()\sin\sfts3\sthat\scould\sfail\sdue\sto\scorrupt\sdatabase\srecords.
-D 2019-11-26T02:03:16.599
+C Add\sthe\snew\s-S\soption\sto\sthe\slemon\sparser\sgenerator\sto\scause\sit\sto\soutput\nSQL\sthat\sdescribes\sthe\sinput\sgrammar.
+D 2019-11-26T02:22:39.237
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
-F Makefile.in bf24a9abbb277afa2fbe6bac80a181f22be6c48de771cd260c9851ecf6165dc1
+F Makefile.in d3a862c9742f5a08230a3b295c0a47fd3067f19356dc39935280135f90474b04
F Makefile.linux-gcc f609543700659711fbd230eced1f01353117621dccae7b9fb70daa64236c5241
-F Makefile.msc c7e3548d5c9dc12bedf47366ca3f1438196f635d81f08fda44c6c1f290c4bcf8
+F Makefile.msc 0b0acbf34bb238170bdf1fd343a1fd37bc81c042ce029c1cc53fe15b5d4ed07b
F README.md 1514a365ffca3c138e00c5cc839906108a01011a6b082bad19b09781e3aa498a
F VERSION 081500f0aeaadc989d85aafbc717af45512018aebc73d89e5c2368fe62a600ff
F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50
F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce
F tool/index_usage.c 9ec344d29cbeb03fdc0fce668eedfb7495792170de933adf95cf8d6904a166ad
F tool/kvtest-speed.sh 4761a9c4b3530907562314d7757995787f7aef8f
-F tool/lemon.c 61d5f0af1eff8f754b75ddca668c9897fd30759e389bfffb42ce9e4d38fd4746
+F tool/lemon.c aff705f55b49fa539b84f6d0268b187fd13073fdea8974eb1e48f46f65ecd711
F tool/lempar.c 34b136b281ae022277738d8b51061237fb330deaa317010d89375117e3a028aa
F tool/libvers.c caafc3b689638a1d88d44bc5f526c2278760d9b9
F tool/loadfts.c c3c64e4d5e90e8ba41159232c2189dba4be7b862
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P b0b655625cf491c832a259d29a67660b8d5943c201617900a83d0660b2673377
-R 6a3e9607b61fc3aebf23982510da9bef
-U dan
-Z 453598f27a16514babf1153abdc2edcc
+P 5d9a369301a65f320a0696fcf1f062ca5976ef34350590c07aecf5335c66d872
+R 56c7b11c47c4d5d638f60332aad4d82b
+U drh
+Z 3f689fa3f8b556a4e2fda3bc9d802efd
/********** From the file "report.h" *************************************/
void Reprint(struct lemon *);
void ReportOutput(struct lemon *);
-void ReportTable(struct lemon *, int);
+void ReportTable(struct lemon *, int, int);
void ReportHeader(struct lemon *);
void CompressTables(struct lemon *);
void ResortStates(struct lemon *);
static int mhflag = 0;
static int nolinenosflag = 0;
static int noResort = 0;
+ static int sqlFlag = 0;
static struct s_options options[] = {
{OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."},
{OPT_FLAG, "r", (char*)&noResort, "Do not sort or renumber states"},
{OPT_FLAG, "s", (char*)&statistics,
"Print parser stats to standard output."},
+ {OPT_FLAG, "S", (char*)&sqlFlag,
+ "Generate the *.sql file describing the parser tables."},
{OPT_FLAG, "x", (char*)&version, "Print the version number."},
{OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."},
{OPT_FSTR, "W", 0, "Ignored. (Placeholder for '-W' compiler options.)"},
if( !quiet ) ReportOutput(&lem);
/* Generate the source code for the parser */
- ReportTable(&lem, mhflag);
+ ReportTable(&lem, mhflag, sqlFlag);
/* Produce a header file for use by the scanner. (This step is
** omitted if the "-m" option is used because makeheaders will
/* Generate C source code for the parser */
void ReportTable(
struct lemon *lemp,
- int mhflag /* Output in makeheaders format if true */
+ int mhflag, /* Output in makeheaders format if true */
+ int sqlFlag /* Generate the *.sql file too */
){
- FILE *out, *in;
+ FILE *out, *in, *sql;
char line[LINESIZE];
int lineno;
struct state *stp;
fclose(in);
return;
}
+ if( sqlFlag==0 ){
+ sql = 0;
+ }else{
+ sql = file_open(lemp, ".sql", "wb");
+ if( sql==0 ){
+ fclose(in);
+ fclose(out);
+ return;
+ }
+ fprintf(sql,
+ "CREATE TABLE symbol(\n"
+ " id INTEGER PRIMARY KEY,\n"
+ " name TEXT NOT NULL,\n"
+ " isTerminal BOOLEAN NOT NULL,\n"
+ " fallback INTEGER REFERENCES symbol\n"
+ ");\n"
+ );
+ for(i=0; i<lemp->nsymbol; i++){
+ fprintf(sql,
+ "INSERT INTO symbol(id,name,isTerminal,fallback)"
+ "VALUES(%d,'%s',%s",
+ i, lemp->symbols[i]->name,
+ i<lemp->nterminal ? "TRUE" : "FALSE"
+ );
+ if( lemp->symbols[i]->fallback ){
+ fprintf(sql, ",%d);\n", lemp->symbols[i]->fallback->index);
+ }else{
+ fprintf(sql, ",NULL);\n");
+ }
+ }
+ fprintf(sql,
+ "CREATE TABLE rule(\n"
+ " ruleid INTEGER PRIMARY KEY,\n"
+ " lhs INTEGER REFERENCES symbol(id)\n"
+ ");\n"
+ "CREATE TABLE rulerhs(\n"
+ " ruleid INTEGER REFERENCES rule(ruleid),\n"
+ " pos INTEGER,\n"
+ " sym INTEGER REFERENCES symbol(id)\n"
+ ");\n"
+ );
+ for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){
+ assert( i==rp->iRule );
+ fprintf(sql,
+ "INSERT INTO rule(ruleid,lhs)VALUES(%d,%d);\n",
+ rp->iRule, rp->lhs->index
+ );
+ for(j=0; j<rp->nrhs; j++){
+ struct symbol *sp = rp->rhs[j];
+ if( sp->type!=MULTITERMINAL ){
+ fprintf(sql,
+ "INSERT INTO rulerhs(ruleid,pos,sym)VALUES(%d,%d,%d);\n",
+ i,j,sp->index
+ );
+ }else{
+ int k;
+ for(k=0; k<sp->nsubsym; k++){
+ fprintf(sql,
+ "INSERT INTO rulerhs(ruleid,pos,sym)VALUES(%d,%d,%d);\n",
+ i,j,sp->subsym[k]->index
+ );
+ }
+ }
+ }
+ }
+ }
lineno = 1;
tplt_xfer(lemp->name,in,out,&lineno);
acttab_free(pActtab);
fclose(in);
fclose(out);
+ if( sql ) fclose(sql);
return;
}