From 865f040da3fae247b0ac9caa5bcb9ecd00581ffb Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 7 Apr 2024 16:16:33 -0700 Subject: [PATCH] Removed argument queue --- examples/test.modal | 3 ++- makefile | 2 +- src/modal.c | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/test.modal b/examples/test.modal index f8c9e7b..22c8abc 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -4,5 +4,6 @@ <> (reverse/l (?h ?t) ?l) (reverse/l ?t (?h ?l)) <> (reverse/l (?h) ?l) (str (?h ?l)) <> (implode str ?*) (?*) +<> ((read)) (?:) -(implode reverse (explode hello)) \ No newline at end of file +(implode reverse (explode hello)) (read) \ No newline at end of file diff --git a/makefile b/makefile index af2582e..cd47e71 100644 --- a/makefile +++ b/makefile @@ -8,7 +8,7 @@ all: dest bin/modal dest: @ mkdir -p bin run: all - @ bin/modal examples/test.modal "(arg1)" "(arg2)" "(arg3)" + @ bin/modal examples/test.modal "(arg1) (arg2 (arg3))" test: all @ bin/modal -v @ bin/modal examples/test.modal 2> /dev/null diff --git a/src/modal.c b/src/modal.c index af6e1f8..e935f2e 100644 --- a/src/modal.c +++ b/src/modal.c @@ -4,7 +4,7 @@ typedef struct { char *a, *b; } Rule; -static int rules_len, direction, queue; +static int rules_len, direction; static Rule rules[0x100]; static char dict[0x8000], *dict_ = dict; static char bank_a[0x4000], *prog_ = bank_a; @@ -54,7 +54,8 @@ match(char *p, Rule *r) int i; char c, *a = r->a, *b = p; for(i = 0x21; i < 0x7f; i++) - regs[i] = 0; + if((char)i != ':') + regs[i] = 0; while((c = *a)) { if(c == '?') { int id = (int)*(++a); @@ -100,11 +101,10 @@ plode(char *s) } static int -commit(char r, char *incoming) +commit(char r) { int depth = 0; char c, *s = regs[(int)r]; - if(r == ':' && incoming != NULL) s = incoming, queue++; if(!s) return !fprintf(stderr, "?%c Empty\n", r); if(r == '*') s = plode(s); @@ -164,7 +164,7 @@ parse_rulefrag(char *line) } static int -rewrite(char *incoming) +rewrite(void) { char c, *p = direction ? bank_b : bank_a; while((c = *p) && c <= ' ') p++; @@ -185,7 +185,7 @@ rewrite(char *incoming) char cc, *b = r->b; while((cc = *b++)) { if(cc == '?') - commit(*b++, incoming); + commit(*b++); else *outp_++ = cc; } @@ -231,8 +231,8 @@ main(int argc, char **argv) } *w++ = 0; fclose(f); - queue = 2; - while(rewrite(argv[queue])) + regs[':'] = argv[2]; + while(rewrite()) ; print_rules(); return 0;