From 4a24f7adcf9e0e7b362c8771a256b690b0b16297 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 20 Mar 2016 10:58:56 -0500 Subject: [PATCH] Lemon update 2016-02-17 12:34:03 on branch parser-performance - More agressive use of /*A-overwrites-X*/ in the parser. Fix an off-by-one error in parser stack overflow detection. (user: drh) --- tools/lemon/lemon.c | 9 ++++++++- tools/lemon/lempar.c | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index 264809896a..34d0b1ca3d 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -3412,6 +3412,7 @@ PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){ char *cp, *xp; int i; int rc = 0; /* True if yylhsminor is used */ + int dontUseRhs0 = 0; /* If true, use of left-most RHS label is illegal */ const char *zSkip = 0; /* The zOvwrt comment within rp->code, or NULL */ char lhsused = 0; /* True if the LHS element has been used */ char lhsdirect; /* True if LHS writes directly into stack */ @@ -3482,6 +3483,7 @@ PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){ if( cp==zSkip ){ append_str(zOvwrt,0,0,0,0); cp += lemonStrlen(zOvwrt)-1; + dontUseRhs0 = 1; continue; } if( ISALPHA(*cp) && (cp==rp->code || (!ISALNUM(cp[-1]) && cp[-1]!='_')) ){ @@ -3496,7 +3498,12 @@ PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){ }else{ for(i=0; inrhs; i++){ if( rp->rhsalias[i] && strcmp(cp,rp->rhsalias[i])==0 ){ - if( cp!=rp->code && cp[-1]=='@' ){ + if( i==0 && dontUseRhs0 ){ + ErrorMsg(lemp->filename,rp->ruleline, + "Label %s used after '%s'.", + rp->rhsalias[0], zOvwrt); + lemp->errorcnt++; + }else if( cp!=rp->code && cp[-1]=='@' ){ /* If the argument is of the form @X then substituted ** the token number of X, not the value of X */ append_str("yymsp[%d].major",-1,i-rp->nrhs+1,0,0); diff --git a/tools/lemon/lempar.c b/tools/lemon/lempar.c index 25ac970367..f17d6eea39 100644 --- a/tools/lemon/lempar.c +++ b/tools/lemon/lempar.c @@ -646,14 +646,14 @@ static void yy_reduce( } #endif #if YYSTACKDEPTH>0 - if( yypParser->yyidx>=YYSTACKDEPTH ){ + if( yypParser->yyidx>=YYSTACKDEPTH-1 ){ yyStackOverflow(yypParser); return; } #else - if( yypParser->yyidx>=yypParser->yystksz ){ + if( yypParser->yyidx>=yypParser->yystksz-1 ){ yyGrowStack(yypParser); - if( yypParser->yyidx>=yypParser->yystksz ){ + if( yypParser->yyidx>=yypParser->yystksz-1 ){ yyStackOverflow(yypParser); return; }