Removed parse step
This commit is contained in:
parent
767c7e93d5
commit
2322f51749
23
src/modal.c
23
src/modal.c
|
@ -36,7 +36,7 @@ static int
|
|||
compare(char *a, char *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])
|
||||
if(!a[i] || ++i >= al) return 1;
|
||||
return 0;
|
||||
|
@ -67,7 +67,7 @@ match(char *p, Rule *r)
|
|||
}
|
||||
|
||||
static void
|
||||
writereg(char r)
|
||||
bind(char r)
|
||||
{
|
||||
int depth = 0;
|
||||
char c, *s = regs[(int)r];
|
||||
|
@ -125,7 +125,7 @@ rewrite(void)
|
|||
char cc, *b = r->b;
|
||||
while((cc = *b++)) {
|
||||
if(cc == '?')
|
||||
writereg(*b++);
|
||||
bind(*b++);
|
||||
else
|
||||
*outp_++ = cc;
|
||||
}
|
||||
|
@ -179,26 +179,17 @@ parse_rulefrag(char *line)
|
|||
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
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
FILE *f;
|
||||
if(argc < 2)
|
||||
return !printf("usage: modal [-v] source.modal\n");
|
||||
if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v')
|
||||
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();
|
||||
printf(".. %s\n", prog);
|
||||
while(rewrite())
|
||||
|
|
Loading…
Reference in New Issue