mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 04:01:31 +00:00
Lemon update 2016-02-17 04:33:10 on branch parser-performance
- Enhance Lemon so that if reduce code contains a comment of the form "/*A-overwrites-X*/" then a LHS label A is allowed to overwrite the RHS label X. (user: drh)
This commit is contained in:
parent
ab4c3a0c5e
commit
25972d79a7
1 changed files with 21 additions and 6 deletions
|
@ -3412,10 +3412,12 @@ PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){
|
||||||
char *cp, *xp;
|
char *cp, *xp;
|
||||||
int i;
|
int i;
|
||||||
int rc = 0; /* True if yylhsminor is used */
|
int rc = 0; /* True if yylhsminor is used */
|
||||||
|
const char *zSkip = 0; /* The zOvwrt comment within rp->code, or NULL */
|
||||||
char lhsused = 0; /* True if the LHS element has been used */
|
char lhsused = 0; /* True if the LHS element has been used */
|
||||||
char lhsdirect; /* True if LHS writes directly into stack */
|
char lhsdirect; /* True if LHS writes directly into stack */
|
||||||
char used[MAXRHS]; /* True for each RHS element which is used */
|
char used[MAXRHS]; /* True for each RHS element which is used */
|
||||||
char zLhs[50]; /* Convert the LHS symbol into this string */
|
char zLhs[50]; /* Convert the LHS symbol into this string */
|
||||||
|
char zOvwrt[900]; /* Comment that to allow LHS to overwrite RHS */
|
||||||
|
|
||||||
for(i=0; i<rp->nrhs; i++) used[i] = 0;
|
for(i=0; i<rp->nrhs; i++) used[i] = 0;
|
||||||
lhsused = 0;
|
lhsused = 0;
|
||||||
|
@ -3455,9 +3457,17 @@ PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){
|
||||||
rp->lhs->name, rp->lhsalias, rp->rhs[0]->name, rp->rhsalias[0]);
|
rp->lhs->name, rp->lhsalias, rp->rhs[0]->name, rp->rhsalias[0]);
|
||||||
lemp->errorcnt++;
|
lemp->errorcnt++;
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
sprintf(zOvwrt, "/*%s-overwrites-%s*/", rp->lhsalias, rp->rhsalias[0]);
|
||||||
|
zSkip = strstr(rp->code, zOvwrt);
|
||||||
|
if( zSkip!=0 ){
|
||||||
|
/* The code contains a special comment that indicates that it is safe
|
||||||
|
** for the LHS label to overwrite left-most RHS label. */
|
||||||
|
lhsdirect = 1;
|
||||||
}else{
|
}else{
|
||||||
lhsdirect = 0;
|
lhsdirect = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if( lhsdirect ){
|
if( lhsdirect ){
|
||||||
sprintf(zLhs, "yymsp[%d].minor.yy%d",1-rp->nrhs,rp->lhs->dtnum);
|
sprintf(zLhs, "yymsp[%d].minor.yy%d",1-rp->nrhs,rp->lhs->dtnum);
|
||||||
}else{
|
}else{
|
||||||
|
@ -3469,6 +3479,11 @@ PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){
|
||||||
|
|
||||||
/* This const cast is wrong but harmless, if we're careful. */
|
/* This const cast is wrong but harmless, if we're careful. */
|
||||||
for(cp=(char *)rp->code; *cp; cp++){
|
for(cp=(char *)rp->code; *cp; cp++){
|
||||||
|
if( cp==zSkip ){
|
||||||
|
append_str(zOvwrt,0,0,0,0);
|
||||||
|
cp += lemonStrlen(zOvwrt)-1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if( ISALPHA(*cp) && (cp==rp->code || (!ISALNUM(cp[-1]) && cp[-1]!='_')) ){
|
if( ISALPHA(*cp) && (cp==rp->code || (!ISALNUM(cp[-1]) && cp[-1]!='_')) ){
|
||||||
char saved;
|
char saved;
|
||||||
for(xp= &cp[1]; ISALNUM(*xp) || *xp=='_'; xp++);
|
for(xp= &cp[1]; ISALNUM(*xp) || *xp=='_'; xp++);
|
||||||
|
|
Loading…
Reference in a new issue