diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index 7eb72b6524..b32c032b6b 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -3404,10 +3404,14 @@ PRIVATE char *append_str(const char *zText, int n, int p1, int p2, int bNoSubst) ** zCode is a string that is the action associated with a rule. Expand ** the symbols in this string so that the refer to elements of the parser ** stack. +** +** Return 1 if the expanded code requires that "yylhsminor" local variable +** to be defined. */ -PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){ +PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){ char *cp, *xp; int i; + int rc = 0; /* True if yylhsminor is used */ char lhsused = 0; /* True if the LHS element has been used */ char lhsdirect; /* True if LHS writes directly into stack */ char used[MAXRHS]; /* True for each RHS element which is used */ @@ -3457,9 +3461,7 @@ PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){ if( lhsdirect ){ sprintf(zLhs, "yymsp[%d].minor.yy%d",1-rp->nrhs,rp->lhs->dtnum); }else{ - append_str(0,0,0,0,0); - append_str(" YYMINORTYPE yylhsminor;\n", 0, 0, 0, 0); - rp->codePrefix = Strsafe(append_str(0,0,0,0,0)); + rc = 1; sprintf(zLhs, "yylhsminor.yy%d",rp->lhs->dtnum); } @@ -3564,6 +3566,8 @@ PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){ /* Suffix code generation complete */ cp = append_str(0,0,0,0,0); if( cp ) rp->codeSuffix = Strsafe(cp); + + return rc; } /* @@ -4232,9 +4236,13 @@ void ReportTable( tplt_xfer(lemp->name,in,out,&lineno); /* Generate code which executes during each REDUCE action */ + i = 0; for(rp=lemp->rule; rp; rp=rp->next){ - translate_code(lemp, rp); + i += translate_code(lemp, rp); } + if( i ){ + fprintf(out," YYMINORTYPE yylhsminor;\n"); lineno++; + } /* First output rules other than the default: rule */ for(rp=lemp->rule; rp; rp=rp->next){ struct rule *rp2; /* Other rules with the same action */ diff --git a/tools/lemon/lempar.c b/tools/lemon/lempar.c index b3ab0da067..25ac970367 100644 --- a/tools/lemon/lempar.c +++ b/tools/lemon/lempar.c @@ -636,8 +636,6 @@ static void yy_reduce( } #endif /* NDEBUG */ - /* yygotominor = yyzerominor; */ - /* Check that the stack is large enough to grow by a single entry ** if the RHS of the rule is empty. This ensures that there is room ** enough on the stack to push the LHS value */