Housekeeping

This commit is contained in:
Devine Lu Linvega 2024-04-11 09:08:07 -07:00
parent 5f70f09ce3
commit 50424f4d0c
1 changed files with 16 additions and 16 deletions

View File

@ -129,6 +129,19 @@ commit_rule(Rule *r, char *s, int create)
return 1; return 1;
} }
static int
write_rule(Rule *r, char last, char *res)
{
char cc, *b = r->b;
if(!*b && last == ' ') outp_--;
while((cc = *b++))
if(cc == '?')
put_reg(*b++);
else
*outp_++ = cc;
return commit_rule(r, res, 0);
}
static char * static char *
parse_frag(char *s) parse_frag(char *s)
{ {
@ -142,19 +155,6 @@ parse_frag(char *s)
return s; return s;
} }
static int
write(Rule *r, char last, char *res)
{
char cc, *b = r->b;
if(!*b && last == ' ') outp_--;
while((cc = *b++))
if(cc == '?')
put_reg(*b++);
else
*outp_++ = cc;
return commit_rule(r, res, 0);
}
static char * static char *
create_rule(Rule *r, int id, char *s) create_rule(Rule *r, int id, char *s)
{ {
@ -182,11 +182,11 @@ rewrite(void)
r = λ r = λ
p = create_rule(&lambda, -1, p) + 1; p = create_rule(&lambda, -1, p) + 1;
if((res = match_rule(&lambda, p)) != NULL) if((res = match_rule(&lambda, p)) != NULL)
return write(&lambda, last, res); return write_rule(&lambda, last, res);
} }
for(r = rules; r < rules_; r++) for(r = rules; r < rules_; r++)
if((res = match_rule(r, p)) != NULL) if((res = match_rule(r, p)) != NULL)
return write(r, last, res); return write_rule(r, last, res);
} }
*outp_++ = last = c; *outp_++ = last = c;
p++; p++;
@ -203,7 +203,7 @@ main(int argc, char **argv)
if(argc < 2) if(argc < 2)
return !printf("usage: modal [-v] source.modal\n"); return !printf("usage: modal [-v] source.modal\n");
if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v') if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v')
return !printf("Modal Interpreter, 10 Apr 2024.\n"); return !printf("Modal Interpreter, 11 Apr 2024.\n");
if(!(f = fopen(argv[1], "r"))) if(!(f = fopen(argv[1], "r")))
return !printf("Invalid Modal file: %s.\n", argv[1]); return !printf("Invalid Modal file: %s.\n", argv[1]);
while(fread(&c, 1, 1, f)) { while(fread(&c, 1, 1, f)) {