Fix for a{0} bug.

This commit is contained in:
Arnold D. Robbins 2020-01-01 22:47:29 +02:00
parent 4d9b12969e
commit a3e9e8285e
2 changed files with 12 additions and 2 deletions

View File

@ -50,7 +50,7 @@ Node *arglist = 0; /* list of args for current function */
%token <i> NL ',' '{' '(' '|' ';' '/' ')' '}' '[' ']' %token <i> NL ',' '{' '(' '|' ';' '/' ')' '}' '[' ']'
%token <i> ARRAY %token <i> ARRAY
%token <i> MATCH NOTMATCH MATCHOP %token <i> MATCH NOTMATCH MATCHOP
%token <i> FINAL DOT ALL CCL NCCL CHAR OR STAR QUEST PLUS EMPTYRE %token <i> FINAL DOT ALL CCL NCCL CHAR OR STAR QUEST PLUS EMPTYRE ZERO
%token <i> AND BOR APPEND EQ GE GT LE LT NE IN %token <i> AND BOR APPEND EQ GE GT LE LT NE IN
%token <i> ARG BLTIN BREAK CLOSE CONTINUE DELETE DO EXIT FOR FUNC %token <i> ARG BLTIN BREAK CLOSE CONTINUE DELETE DO EXIT FOR FUNC
%token <i> SUB GSUB IF INDEX LSUBSTR MATCHFCN NEXT NEXTFILE %token <i> SUB GSUB IF INDEX LSUBSTR MATCHFCN NEXT NEXTFILE

12
b.c
View File

@ -263,6 +263,8 @@ void penter(Node *p) /* set up parent pointers and leaf indices */
parent(left(p)) = p; parent(left(p)) = p;
parent(right(p)) = p; parent(right(p)) = p;
break; break;
case ZERO:
break;
default: /* can't happen */ default: /* can't happen */
FATAL("can't happen: unknown type %d in penter", type(p)); FATAL("can't happen: unknown type %d in penter", type(p));
break; break;
@ -277,6 +279,7 @@ void freetr(Node *p) /* free parse tree */
xfree(p); xfree(p);
break; break;
UNARY UNARY
case ZERO:
freetr(left(p)); freetr(left(p));
xfree(p); xfree(p);
break; break;
@ -436,6 +439,8 @@ void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfo
cfoll(f,left(v)); cfoll(f,left(v));
cfoll(f,right(v)); cfoll(f,right(v));
break; break;
case ZERO:
break;
default: /* can't happen */ default: /* can't happen */
FATAL("can't happen: unknown type %d in cfoll", type(v)); FATAL("can't happen: unknown type %d in cfoll", type(v));
} }
@ -479,6 +484,8 @@ int first(Node *p) /* collects initially active leaves of p into setvec */
b = first(right(p)); b = first(right(p));
if (first(left(p)) == 0 || b == 0) return(0); if (first(left(p)) == 0 || b == 0) return(0);
return(1); return(1);
case ZERO:
return 0;
} }
FATAL("can't happen: unknown type %d in first", type(p)); /* can't happen */ FATAL("can't happen: unknown type %d in first", type(p)); /* can't happen */
return(-1); return(-1);
@ -838,6 +845,9 @@ Node *unary(Node *np)
case QUEST: case QUEST:
rtok = relex(); rtok = relex();
return (unary(op2(QUEST, np, NIL))); return (unary(op2(QUEST, np, NIL)));
case ZERO:
rtok = relex();
return (unary(op2(ZERO, np, NIL)));
default: default:
return (np); return (np);
} }
@ -1191,7 +1201,7 @@ rescan:
if (repeat(starttok, prestr-starttok, lastatom, if (repeat(starttok, prestr-starttok, lastatom,
startreptok - lastatom, n, m) > 0) { startreptok - lastatom, n, m) > 0) {
if (n == 0 && m == 0) { if (n == 0 && m == 0) {
return EMPTYRE; return ZERO;
} }
/* must rescan input for next token */ /* must rescan input for next token */
goto rescan; goto rescan;