rewritting egrep.y is should be easier than understanding and refactoring the original
This commit is contained in:
@ -80,8 +80,8 @@ static void cgotofn(void);
|
|||||||
static int cstate(int v);
|
static int cstate(int v);
|
||||||
static int member(int symb, int set, int torf);
|
static int member(int symb, int set, int torf);
|
||||||
static int notin(int n);
|
static int notin(int n);
|
||||||
static void synerror(void);
|
static void syntax_error(void);
|
||||||
static void overflo(void);
|
static void table_overflow(void);
|
||||||
static void add(int *array, int n);
|
static void add(int *array, int n);
|
||||||
static void follow(unsigned int v);
|
static void follow(unsigned int v);
|
||||||
static int unary(int x, int d);
|
static int unary(int x, int d);
|
||||||
@ -208,7 +208,7 @@ int yylex(void) {
|
|||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
if (c == '\0')
|
if (c == '\0')
|
||||||
synerror();
|
syntax_error();
|
||||||
if ( (c == '-')
|
if ( (c == '-')
|
||||||
&& (cclcnt > 0)
|
&& (cclcnt > 0)
|
||||||
&& (chars[nxtchar-1] != 0)) {
|
&& (chars[nxtchar-1] != 0)) {
|
||||||
@ -216,7 +216,7 @@ int yylex(void) {
|
|||||||
c = chars[nxtchar-1];
|
c = chars[nxtchar-1];
|
||||||
while ((unsigned int)c < (unsigned int)d) {
|
while ((unsigned int)c < (unsigned int)d) {
|
||||||
if (nxtchar >= MAXLIN)
|
if (nxtchar >= MAXLIN)
|
||||||
overflo();
|
table_overflow();
|
||||||
chars[nxtchar++] = ++c;
|
chars[nxtchar++] = ++c;
|
||||||
cclcnt++;
|
cclcnt++;
|
||||||
}
|
}
|
||||||
@ -224,7 +224,7 @@ int yylex(void) {
|
|||||||
} /* if() */
|
} /* if() */
|
||||||
} /* if() */
|
} /* if() */
|
||||||
if (nxtchar >= MAXLIN)
|
if (nxtchar >= MAXLIN)
|
||||||
overflo();
|
table_overflow();
|
||||||
chars[nxtchar++] = c;
|
chars[nxtchar++] = c;
|
||||||
cclcnt++;
|
cclcnt++;
|
||||||
} while ((c = nextch()) != ']');
|
} while ((c = nextch()) != ']');
|
||||||
@ -232,7 +232,7 @@ int yylex(void) {
|
|||||||
return (x);
|
return (x);
|
||||||
case '\\':
|
case '\\':
|
||||||
if ((c = nextch()) == '\0')
|
if ((c = nextch()) == '\0')
|
||||||
synerror();
|
syntax_error();
|
||||||
yylval = c;
|
yylval = c;
|
||||||
return (CHAR);
|
return (CHAR);
|
||||||
case '$':
|
case '$':
|
||||||
@ -247,14 +247,14 @@ int yylex(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void synerror(void) {
|
void syntax_error(void) {
|
||||||
yyerror("Syntax error");
|
yyerror("Syntax error");
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
unsigned int enter(int x) {
|
unsigned int enter(int x) {
|
||||||
if(line >= MAXLIN)
|
if(line >= MAXLIN)
|
||||||
overflo();
|
table_overflow();
|
||||||
name[line] = x;
|
name[line] = x;
|
||||||
left[line] = 0;
|
left[line] = 0;
|
||||||
right[line] = 0;
|
right[line] = 0;
|
||||||
@ -271,7 +271,7 @@ unsigned int cclenter(int x) {
|
|||||||
static
|
static
|
||||||
int node(int x, int l, int r) {
|
int node(int x, int l, int r) {
|
||||||
if(line >= MAXLIN)
|
if(line >= MAXLIN)
|
||||||
overflo();
|
table_overflow();
|
||||||
name[line] = x;
|
name[line] = x;
|
||||||
left[line] = l;
|
left[line] = l;
|
||||||
right[line] = r;
|
right[line] = r;
|
||||||
@ -283,7 +283,7 @@ int node(int x, int l, int r) {
|
|||||||
static
|
static
|
||||||
int unary(int x, int d) {
|
int unary(int x, int d) {
|
||||||
if(line >= MAXLIN)
|
if(line >= MAXLIN)
|
||||||
overflo();
|
table_overflow();
|
||||||
name[line] = x;
|
name[line] = x;
|
||||||
left[line] = d;
|
left[line] = d;
|
||||||
right[line] = 0;
|
right[line] = 0;
|
||||||
@ -292,7 +292,7 @@ int unary(int x, int d) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void overflo(void) {
|
void table_overflow(void) {
|
||||||
yyerror("internal table overflow");
|
yyerror("internal table overflow");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,7 +408,7 @@ void cgotofn(void) {
|
|||||||
} /* end nextstate */
|
} /* end nextstate */
|
||||||
if (notin(n)) {
|
if (notin(n)) {
|
||||||
if (n >= NSTATES)
|
if (n >= NSTATES)
|
||||||
overflo();
|
table_overflow();
|
||||||
add(state, ++n);
|
add(state, ++n);
|
||||||
if (tmpstat[line] == 1)
|
if (tmpstat[line] == 1)
|
||||||
out[n] = 1;
|
out[n] = 1;
|
||||||
@ -464,11 +464,11 @@ int member(int symb, int set, int torf) {
|
|||||||
|
|
||||||
static
|
static
|
||||||
int notin(int n) {
|
int notin(int n) {
|
||||||
int i, j, pos;
|
int pos;
|
||||||
for (i=0; i<=n; i++) {
|
for (int i = 0; i <= n; i++) {
|
||||||
if (positions[state[i]] == count) {
|
if (positions[state[i]] == count) {
|
||||||
pos = state[i] + 1;
|
pos = state[i] + 1;
|
||||||
for (j=0; j < count; j++)
|
for (int j = 0; j < count; j++)
|
||||||
if (tmpstat[positions[pos++]] != 1) goto nxt;
|
if (tmpstat[positions[pos++]] != 1) goto nxt;
|
||||||
xstate = i;
|
xstate = i;
|
||||||
return (0);
|
return (0);
|
||||||
@ -480,13 +480,11 @@ int notin(int n) {
|
|||||||
|
|
||||||
static
|
static
|
||||||
void add(int *array, int n) {
|
void add(int *array, int n) {
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
if (nxtpos + count > MAXPOS)
|
if (nxtpos + count > MAXPOS)
|
||||||
overflo();
|
table_overflow();
|
||||||
array[n] = nxtpos;
|
array[n] = nxtpos;
|
||||||
positions[nxtpos++] = count;
|
positions[nxtpos++] = count;
|
||||||
for (i=3; i <= line; i++) {
|
for (unsigned i = 3; i <= line; i++) {
|
||||||
if (tmpstat[i] == 1) {
|
if (tmpstat[i] == 1) {
|
||||||
positions[nxtpos++] = i;
|
positions[nxtpos++] = i;
|
||||||
}
|
}
|
||||||
@ -495,28 +493,24 @@ void add(int *array, int n) {
|
|||||||
|
|
||||||
static
|
static
|
||||||
void follow(unsigned int v) {
|
void follow(unsigned int v) {
|
||||||
unsigned int p;
|
if (v == line) { return; }
|
||||||
|
|
||||||
if (v == line)
|
unsigned int p = parent[v];
|
||||||
return;
|
|
||||||
p = parent[v];
|
|
||||||
switch(name[p]) {
|
switch(name[p]) {
|
||||||
case STAR:
|
case STAR:
|
||||||
case PLUS: cstate(v);
|
case PLUS:
|
||||||
|
cstate(v);
|
||||||
follow(p);
|
follow(p);
|
||||||
return;
|
break;
|
||||||
|
|
||||||
case OR:
|
case OR:
|
||||||
case QUEST: follow(p);
|
case QUEST:
|
||||||
return;
|
|
||||||
|
|
||||||
case CAT:
|
|
||||||
if (v == left[p]) {
|
|
||||||
if (cstate(right[p]) == 0) {
|
|
||||||
follow(p);
|
follow(p);
|
||||||
|
break;
|
||||||
|
case CAT:
|
||||||
|
if (v == left[p]
|
||||||
|
&& cstate(right[p]) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else
|
|
||||||
follow(p);
|
follow(p);
|
||||||
return;
|
return;
|
||||||
case FINAL:
|
case FINAL:
|
||||||
@ -524,7 +518,7 @@ void follow(unsigned int v) {
|
|||||||
tmpstat[line] = 1;
|
tmpstat[line] = 1;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user