Removed parse step

This commit is contained in:
Devine Lu Linvega 2024-04-06 08:02:54 -07:00
parent 767c7e93d5
commit 2322f51749
1 changed files with 9 additions and 18 deletions

View File

@ -36,9 +36,9 @@ static int
compare(char *a, char *b) compare(char *a, char *b)
{ {
int i = 0, al = walk(a) - a, bl = walk(b) - b; int i = 0, al = walk(a) - a, bl = walk(b) - b;
if(al != bl) return 0; if(al != bl)
while(a[i] == b[i]) while(a[i] == b[i])
if(!a[i] || ++i >= al) return 1; if(!a[i] || ++i >= al) return 1;
return 0; return 0;
} }
@ -67,7 +67,7 @@ match(char *p, Rule *r)
} }
static void static void
writereg(char r) bind(char r)
{ {
int depth = 0; int depth = 0;
char c, *s = regs[(int)r]; char c, *s = regs[(int)r];
@ -125,7 +125,7 @@ rewrite(void)
char cc, *b = r->b; char cc, *b = r->b;
while((cc = *b++)) { while((cc = *b++)) {
if(cc == '?') if(cc == '?')
writereg(*b++); bind(*b++);
else else
*outp_++ = cc; *outp_++ = cc;
} }
@ -179,26 +179,17 @@ parse_rulefrag(char *line)
return res; return res;
} }
static int
parse(char *path)
{
FILE *f;
int res;
if(!(f = fopen(path, "r")))
return !printf("Invalid file: %s\n", path);
res = fread(&prog, 1, 0x1000, f);
fclose(f);
return res;
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
FILE *f;
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 - Modal Interpreter, 4 Apr 2024.\n"); return !printf("Modal - Modal Interpreter, 4 Apr 2024.\n");
parse(argv[1]); if(!(f = fopen(argv[1], "r")))
return !printf("Invalid file: %s\n", argv[1]);
fread(&prog, 1, 0x1000, f), fclose(f);
print_rules(); print_rules();
printf(".. %s\n", prog); printf(".. %s\n", prog);
while(rewrite()) while(rewrite())