diff options
author | Anders Broman <anders.broman@ericsson.com> | 2006-11-19 16:24:18 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2006-11-19 16:24:18 +0000 |
commit | a0b76c2fa22311a72775e9e5a34a6d652ef50ddb (patch) | |
tree | d8fec75adc36e6bca7ace76d3e6ac95a87ff8027 /tools | |
parent | ce36a197666b16794801555125137476e093f4e9 (diff) |
Update to the latest versions from sqlite.
svn path=/trunk/; revision=19932
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lemon/lemon.c | 59 | ||||
-rw-r--r-- | tools/lemon/lempar.c | 41 |
2 files changed, 73 insertions, 27 deletions
diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index 075e64bdab..1ba274151e 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -25,6 +25,7 @@ ** drh@acm.org ** http://www.hwaci.com/drh/ ** +** Updated to sqlite lemon version 1.40 ** $Id$ */ #include <stdio.h> @@ -203,6 +204,7 @@ struct lemon { struct symbol **symbols; /* Sorted array of pointers to symbols */ int errorcnt; /* Number of errors */ struct symbol *errsym; /* The error symbol */ + struct symbol *wildcard; /* Token that matches anything */ char *name; /* Name of the generated parser */ char *arg; /* Declaration of the 3th argument to parser */ char *tokentype; /* Type of terminal symbols in the parser stack */ @@ -1479,6 +1481,7 @@ int main(int argc _U_, char **argv) fprintf(stderr,"Exactly one filename argument is required.\n"); exit(1); } + memset(&lem, 0, sizeof(lem)); lem.errorcnt = 0; /* Initialize the machine */ @@ -1488,15 +1491,6 @@ int main(int argc _U_, char **argv) lem.argv0 = argv[0]; lem.filename = get_optarg(0); lem.basisflag = basisflag; - lem.has_fallback = 0; - lem.nconflict = 0; - lem.name = lem.include = lem.arg = lem.tokentype = lem.start = 0; - lem.vartype = 0; - lem.stacksize = NULL; - lem.error = lem.overflow = lem.failure = lem.accept = lem.tokendest = - lem.tokenprefix = lem.outname = lem.extracode = 0; - lem.vardest = 0; - lem.tablesize = 0; Symbol_new("$"); lem.errsym = Symbol_new("error"); lem.outdirname = outdirname; @@ -1506,7 +1500,7 @@ int main(int argc _U_, char **argv) /* Parse the input file */ Parse(&lem); if( lem.errorcnt ) exit(lem.errorcnt); - if( lem.rule==0 ){ + if( lem.nrule==0 ){ fprintf(stderr,"Empty grammar.\n"); exit(1); } @@ -2005,7 +1999,8 @@ struct pstate { RESYNC_AFTER_DECL_ERROR, WAITING_FOR_DESTRUCTOR_SYMBOL, WAITING_FOR_DATATYPE_SYMBOL, - WAITING_FOR_FALLBACK_ID + WAITING_FOR_FALLBACK_ID, + WAITING_FOR_WILDCARD_ID } state; /* The state of the parser */ struct symbol *fallback; /* The fallback token */ struct symbol *lhs; /* Left-hand side of current rule */ @@ -2308,6 +2303,8 @@ to follow the previous rule."); }else if( strcmp(x,"fallback")==0 ){ psp->fallback = 0; psp->state = WAITING_FOR_FALLBACK_ID; + }else if( strcmp(x,"wildcard")==0 ){ + psp->state = WAITING_FOR_WILDCARD_ID; }else{ ErrorMsg(psp->filename,psp->tokenlineno, "Unknown declaration keyword: \"%%%s\".",x); @@ -2408,6 +2405,25 @@ to follow the previous rule."); } } break; + case WAITING_FOR_WILDCARD_ID: + if( x[0]=='.' ){ + psp->state = WAITING_FOR_DECL_OR_RULE; + }else if( !isupper(x[0]) ){ + ErrorMsg(psp->filename, psp->tokenlineno, + "%%wildcard argument \"%s\" should be a token", x); + psp->errorcnt++; + }else{ + struct symbol *sp = Symbol_new(x); + if( psp->gp->wildcard==0 ){ + psp->gp->wildcard = sp; + }else{ + ErrorMsg(psp->filename, psp->tokenlineno, + "Extra wildcard to token: %s", x); + psp->errorcnt++; + } + } + break; + case RESYNC_AFTER_RULE_ERROR: /* if( x[0]=='.' ) psp->state = WAITING_FOR_DECL_OR_RULE; ** break; */ @@ -3200,7 +3216,7 @@ PRIVATE char *append_str(const char *zText, int n, int p1, int p2){ if( z==0 ) return ""; while( n-- > 0 ){ c = *(zText++); - if( c=='%' && zText[0]=='d' ){ + if( c=='%' && n>0 && zText[0]=='d' ){ sprintf(zInt, "%d", p1); p1 = p2; strcpy(&z[used], zInt); @@ -3534,6 +3550,10 @@ void ReportTable( 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++; + if( lemp->wildcard ){ + fprintf(out,"#define YYWILDCARD %d\n", + lemp->wildcard->index); lineno++; + } print_stack_union(out,lemp,&lineno,mhflag); if( lemp->stacksize ){ if( atoi(lemp->stacksize)<=0 ){ @@ -3929,7 +3949,8 @@ void ReportHeader(struct lemon *lemp) ** of defaults. ** ** In this version, we take the most frequent REDUCE action and make -** it the default. +** it the default. Except, there is no default if the wildcard token +** is a possible look-ahead. */ void CompressTables(struct lemon *lemp) { @@ -3938,13 +3959,18 @@ void CompressTables(struct lemon *lemp) struct rule *rp, *rp2, *rbest; int nbest, n; int i; + int usesWildcard; for(i=0; i<lemp->nstate; i++){ stp = lemp->sorted[i]; nbest = 0; rbest = 0; + usesWildcard = 0; for(ap=stp->ap; ap; ap=ap->next){ + if( ap->type==SHIFT && ap->sp==lemp->wildcard ){ + usesWildcard = 1; + } if( ap->type!=REDUCE ) continue; rp = ap->x.rp; if( rp==rbest ) continue; @@ -3962,8 +3988,10 @@ void CompressTables(struct lemon *lemp) } /* Do not make a default if the number of rules to default - ** is not at least 1 */ - if( nbest<1 ) continue; + ** is not at least 1 or if the wildcard token is a possible + ** lookahead. + */ + if( nbest<1 || usesWildcard ) continue; /* Combine matching REDUCE actions into a single default */ @@ -4119,6 +4147,7 @@ char *Strsafe(const char *y) { char *z; + if( y==0 ) return 0; z = Strsafe_find(y); if( z==0 && (z=malloc( strlen(y)+1 ))!=0 ){ strcpy(z,y); diff --git a/tools/lemon/lempar.c b/tools/lemon/lempar.c index 39d3a4fd17..e3ab97a9c5 100644 --- a/tools/lemon/lempar.c +++ b/tools/lemon/lempar.c @@ -17,6 +17,7 @@ ** Boston, MA 02111-1307, USA. ** ** Modified 1997 to make it suitable for use with makeheaders. +* Updated to sqlite lemon version 1.22 */ /* First off, code is include which follows the "include" declaration ** in the input file. */ @@ -125,7 +126,8 @@ ** yy_default[] Default action for each state. */ %% -#define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0])) +#define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0])) + /* The next table maps tokens into fallback tokens. If a construct ** like the following: @@ -339,7 +341,7 @@ void ParseFree( */ static int yy_find_shift_action( yyParser *pParser, /* The parser */ - int iLookAhead /* The look-ahead token */ + YYCODETYPE iLookAhead /* The look-ahead token */ ){ int i; int stateno = pParser->yystack[pParser->yyidx].stateno; @@ -352,19 +354,34 @@ static int yy_find_shift_action( } i += iLookAhead; if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ + if( iLookAhead>0 ){ #ifdef YYFALLBACK - int iFallback; /* Fallback token */ - if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) - && (iFallback = yyFallback[iLookAhead])!=0 ){ + int iFallback; /* Fallback token */ + if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) + && (iFallback = yyFallback[iLookAhead])!=0 ){ #ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); + if( yyTraceFILE ){ + fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); + } +#endif + return yy_find_shift_action(pParser, iFallback); } #endif - return yy_find_shift_action(pParser, iFallback); +#ifdef YYWILDCARD + int j = i - iLookAhead + YYWILDCARD; + if( j>=0 && j<YY_SZ_ACTTAB && yy_lookahead[j]==YYWILDCARD ){ +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]); + } +#endif /* NDEBUG */ + + return yy_action[j]; + } +#endif /* YYWILDCARD */ } -#endif return yy_default[stateno]; }else{ return yy_action[i]; @@ -381,7 +398,7 @@ static int yy_find_shift_action( */ static int yy_find_reduce_action( int stateno, /* Current state number */ - int iLookAhead /* The look-ahead token */ + YYCODETYPE iLookAhead /* The look-ahead token */ ){ int i; /* int stateno = pParser->yystack[pParser->yyidx].stateno; */ @@ -474,7 +491,7 @@ static void yy_reduce( yymsp = &yypParser->yystack[yypParser->yyidx]; #ifndef NDEBUG if( yyTraceFILE && yyruleno>=0 - && yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){ + && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, yyRuleName[yyruleno]); } |