Removed extra check from apply_rule
This commit is contained in:
parent
97f8cf03ac
commit
d8325fabcc
16
src/modal.c
16
src/modal.c
|
@ -103,10 +103,10 @@ write_rule(Rule *r, char *s, int create)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
apply_rule(Rule *r, char *s)
|
apply_rule(Rule *r, char **regs, char *s)
|
||||||
{
|
{
|
||||||
unsigned int i, id;
|
unsigned int i, id;
|
||||||
char c, *a = r->a, *regs[0x08], *reg;
|
char c, *a = r->a, *b = r->b, *origin = dst_, *reg;
|
||||||
/* phase: clean registers */
|
/* phase: clean registers */
|
||||||
for(i = 0; i < r->ptr; i++)
|
for(i = 0; i < r->ptr; i++)
|
||||||
regs[i] = NULL;
|
regs[i] = NULL;
|
||||||
|
@ -129,8 +129,6 @@ apply_rule(Rule *r, char *s)
|
||||||
if(c != *s++) return 0;
|
if(c != *s++) return 0;
|
||||||
}
|
}
|
||||||
/* phase: write rule */
|
/* phase: write rule */
|
||||||
if(!(c = *s) || spacer(c)) {
|
|
||||||
char *b = r->b, *origin = dst_;
|
|
||||||
while((c = *b++)) {
|
while((c = *b++)) {
|
||||||
if(c == '?') {
|
if(c == '?') {
|
||||||
id = *b - '0';
|
id = *b - '0';
|
||||||
|
@ -147,8 +145,6 @@ apply_rule(Rule *r, char *s)
|
||||||
}
|
}
|
||||||
return write_rule(r, s, 0);
|
return write_rule(r, s, 0);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
find_register(Rule *r, char reg)
|
find_register(Rule *r, char reg)
|
||||||
|
@ -199,7 +195,7 @@ compile_rule(Rule *r, int id, char *src)
|
||||||
static int
|
static int
|
||||||
rewrite(void)
|
rewrite(void)
|
||||||
{
|
{
|
||||||
char c, last = 0, *cap, *s = src_;
|
char c, last = 0, *cap, *s = src_, *regs[0x08];
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
while((c = *s)) {
|
while((c = *s)) {
|
||||||
if(spacer(last)) {
|
if(spacer(last)) {
|
||||||
|
@ -217,11 +213,11 @@ rewrite(void)
|
||||||
compile_rule(&lambda, -1, s + 2);
|
compile_rule(&lambda, -1, s + 2);
|
||||||
s = cap;
|
s = cap;
|
||||||
while(*s == ' ') s++;
|
while(*s == ' ') s++;
|
||||||
return apply_rule(&lambda, s);
|
return apply_rule(&lambda, regs, s);
|
||||||
}
|
}
|
||||||
/* phase: match */
|
/* phase: match */
|
||||||
for(r = rules; r < rules_; r++)
|
for(r = rules; r < rules_; r++)
|
||||||
if(apply_rule(r, s)) return 1;
|
if(apply_rule(r, regs, s)) return 1;
|
||||||
}
|
}
|
||||||
*dst_++ = last = c;
|
*dst_++ = last = c;
|
||||||
s++;
|
s++;
|
||||||
|
@ -240,7 +236,7 @@ main(int argc, char **argv)
|
||||||
return !printf("usage: modal [-vqn] source.modal\n");
|
return !printf("usage: modal [-vqn] source.modal\n");
|
||||||
for(i = 1; i < argc && *argv[i] == '-'; i++) {
|
for(i = 1; i < argc && *argv[i] == '-'; i++) {
|
||||||
switch(argv[i][1]) {
|
switch(argv[i][1]) {
|
||||||
case 'v': /* version */ return !printf("Modal Interpreter, 24 Apr 2024.\n");
|
case 'v': /* version */ return !printf("Modal Interpreter, 25 Apr 2024.\n");
|
||||||
case 'q': /* quiet */ quiet = 1; break;
|
case 'q': /* quiet */ quiet = 1; break;
|
||||||
case 'n': /* infinite */ cycles = 0xffffffff; break;
|
case 'n': /* infinite */ cycles = 0xffffffff; break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue