Removed argument queue

This commit is contained in:
Devine Lu Linvega 2024-04-07 16:16:33 -07:00
parent c61e775241
commit 865f040da3
3 changed files with 11 additions and 10 deletions

View File

@ -4,5 +4,6 @@
<> (reverse/l (?h ?t) ?l) (reverse/l ?t (?h ?l)) <> (reverse/l (?h ?t) ?l) (reverse/l ?t (?h ?l))
<> (reverse/l (?h) ?l) (str (?h ?l)) <> (reverse/l (?h) ?l) (str (?h ?l))
<> (implode str ?*) (?*) <> (implode str ?*) (?*)
<> ((read)) (?:)
(implode reverse (explode hello)) (implode reverse (explode hello)) (read)

View File

@ -8,7 +8,7 @@ all: dest bin/modal
dest: dest:
@ mkdir -p bin @ mkdir -p bin
run: all run: all
@ bin/modal examples/test.modal "(arg1)" "(arg2)" "(arg3)" @ bin/modal examples/test.modal "(arg1) (arg2 (arg3))"
test: all test: all
@ bin/modal -v @ bin/modal -v
@ bin/modal examples/test.modal 2> /dev/null @ bin/modal examples/test.modal 2> /dev/null

View File

@ -4,7 +4,7 @@ typedef struct {
char *a, *b; char *a, *b;
} Rule; } Rule;
static int rules_len, direction, queue; static int rules_len, direction;
static Rule rules[0x100]; static Rule rules[0x100];
static char dict[0x8000], *dict_ = dict; static char dict[0x8000], *dict_ = dict;
static char bank_a[0x4000], *prog_ = bank_a; static char bank_a[0x4000], *prog_ = bank_a;
@ -54,7 +54,8 @@ match(char *p, Rule *r)
int i; int i;
char c, *a = r->a, *b = p; char c, *a = r->a, *b = p;
for(i = 0x21; i < 0x7f; i++) for(i = 0x21; i < 0x7f; i++)
regs[i] = 0; if((char)i != ':')
regs[i] = 0;
while((c = *a)) { while((c = *a)) {
if(c == '?') { if(c == '?') {
int id = (int)*(++a); int id = (int)*(++a);
@ -100,11 +101,10 @@ plode(char *s)
} }
static int static int
commit(char r, char *incoming) commit(char r)
{ {
int depth = 0; int depth = 0;
char c, *s = regs[(int)r]; char c, *s = regs[(int)r];
if(r == ':' && incoming != NULL) s = incoming, queue++;
if(!s) return !fprintf(stderr, "?%c Empty\n", r); if(!s) return !fprintf(stderr, "?%c Empty\n", r);
if(r == '*') if(r == '*')
s = plode(s); s = plode(s);
@ -164,7 +164,7 @@ parse_rulefrag(char *line)
} }
static int static int
rewrite(char *incoming) rewrite(void)
{ {
char c, *p = direction ? bank_b : bank_a; char c, *p = direction ? bank_b : bank_a;
while((c = *p) && c <= ' ') p++; while((c = *p) && c <= ' ') p++;
@ -185,7 +185,7 @@ rewrite(char *incoming)
char cc, *b = r->b; char cc, *b = r->b;
while((cc = *b++)) { while((cc = *b++)) {
if(cc == '?') if(cc == '?')
commit(*b++, incoming); commit(*b++);
else else
*outp_++ = cc; *outp_++ = cc;
} }
@ -231,8 +231,8 @@ main(int argc, char **argv)
} }
*w++ = 0; *w++ = 0;
fclose(f); fclose(f);
queue = 2; regs[':'] = argv[2];
while(rewrite(argv[queue])) while(rewrite())
; ;
print_rules(); print_rules();
return 0; return 0;