diff options
author | drh <drh@noemail.net> | 2016-04-30 17:19:30 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2016-04-30 17:19:30 +0000 |
commit | 2e55b04da45c2fb17a0464f0480af33082c23810 (patch) | |
tree | e1fd03d96573cce068b7a9fe40a74a198cf1a5a8 /tool/lemon.c | |
parent | 99f5de771faee5c3bcf2ab8758e821220edf4867 (diff) | |
download | sqlite-2e55b04da45c2fb17a0464f0480af33082c23810.tar.gz sqlite-2e55b04da45c2fb17a0464f0480af33082c23810.zip |
More bug fixes to Lemon identified by Kelvin Sherlock. None of these
have any impact on SQLite.
FossilOrigin-Name: 762bdc55f8878ee2ef65af2165a8e7fdbddf0160
Diffstat (limited to 'tool/lemon.c')
-rw-r--r-- | tool/lemon.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/tool/lemon.c b/tool/lemon.c index 2f76465d8..01c8a1da9 100644 --- a/tool/lemon.c +++ b/tool/lemon.c @@ -3556,14 +3556,11 @@ PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){ } - if( rp->lhsalias==0 ){ - /* There is no LHS value symbol. */ - lhsdirect = 1; - }else if( rp->nrhs==0 ){ + if( rp->nrhs==0 ){ /* If there are no RHS symbols, then writing directly to the LHS is ok */ lhsdirect = 1; }else if( rp->rhsalias[0]==0 ){ - /* The left-most RHS symbol has not value. LHS direct is ok. But + /* The left-most RHS symbol has no value. LHS direct is ok. But ** we have to call the distructor on the RHS symbol first. */ lhsdirect = 1; if( has_destructor(rp->rhs[0],lemp) ){ @@ -3572,6 +3569,9 @@ PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){ rp->rhs[0]->index,1-rp->nrhs); rp->codePrefix = Strsafe(append_str(0,0,0,0)); } + }else if( rp->lhsalias==0 ){ + /* There is no LHS value symbol. */ + lhsdirect = 1; }else if( strcmp(rp->lhsalias,rp->rhsalias[0])==0 ){ /* The LHS symbol and the left-most RHS symbol are the same, so ** direct writing is allowed */ @@ -3715,7 +3715,7 @@ PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){ /* Suffix code generation complete */ cp = append_str(0,0,0,0); - if( cp ) rp->codeSuffix = Strsafe(cp); + if( cp && cp[0] ) rp->codeSuffix = Strsafe(cp); return rc; } @@ -4397,7 +4397,14 @@ void ReportTable( for(rp=lemp->rule; rp; rp=rp->next){ struct rule *rp2; /* Other rules with the same action */ if( rp->code==0 ) continue; - if( rp->code[0]=='\n' && rp->code[1]==0 ) continue; /* Will be default: */ + if( rp->code[0]=='\n' + && rp->code[1]==0 + && rp->codePrefix==0 + && rp->codeSuffix==0 + ){ + /* No actions, so this will be part of the "default:" rule */ + continue; + } fprintf(out," case %d: /* ", rp->iRule); writeRuleText(out, rp); fprintf(out, " */\n"); lineno++; @@ -4420,6 +4427,8 @@ void ReportTable( for(rp=lemp->rule; rp; rp=rp->next){ if( rp->code==0 ) continue; assert( rp->code[0]=='\n' && rp->code[1]==0 ); + assert( rp->codePrefix==0 ); + assert( rp->codeSuffix==0 ); fprintf(out," /* (%d) ", rp->iRule); writeRuleText(out, rp); fprintf(out, " */ yytestcase(yyruleno==%d);\n", rp->iRule); lineno++; |