Removed argument queue
This commit is contained in:
parent
c61e775241
commit
865f040da3
|
@ -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))
|
||||
(implode reverse (explode hello)) (read)
|
2
makefile
2
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
|
||||
|
|
16
src/modal.c
16
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;
|
||||
|
|
Loading…
Reference in New Issue