Print rules as they happen
This commit is contained in:
parent
21ec6b9e6a
commit
eee55d5c6d
|
@ -3,4 +3,4 @@
|
|||
<> ($ ?x) (?x $)
|
||||
|
||||
$ (Welcome to NAME
|
||||
Have fun!) print
|
||||
Have fun!\n\n) print
|
|
@ -11,6 +11,6 @@
|
|||
<> (?x dup) (?x ?x)
|
||||
<> (?x ?y swap) (?y ?x)
|
||||
<> (?x pop) ()
|
||||
<> (print ?:) ()
|
||||
<> (print ?:) (?:)
|
||||
|
||||
(implode reverse (explode hello)) (explode hello) empty-register (eq abc abc) (eq abc def) (1 2 3) (4 5 6) swap pop dup (hey 1234 pop) (print Done.)
|
1
makefile
1
makefile
|
@ -9,6 +9,7 @@ dest:
|
|||
@ mkdir -p bin
|
||||
run: all bin/modal
|
||||
@ bin/modal examples/hello.modal 2> /dev/null
|
||||
@ bin/modal examples/test.modal
|
||||
test: bin/modal-debug bin/modal
|
||||
@ bin/modal -v
|
||||
@ bin/modal-debug examples/test.modal "(arg1) (arg2 (arg3))"
|
||||
|
|
21
src/modal.c
21
src/modal.c
|
@ -110,7 +110,7 @@ match_rule(char *p, Rule *r)
|
|||
}
|
||||
|
||||
static int
|
||||
commit_rule(Rule *r, char *s)
|
||||
commit_rule(Rule *r, char *s, int create)
|
||||
{
|
||||
while((*outp_++ = *s++))
|
||||
;
|
||||
|
@ -119,7 +119,9 @@ commit_rule(Rule *r, char *s)
|
|||
prog_ = bank_b, outp_ = bank_a;
|
||||
else
|
||||
prog_ = bank_a, outp_ = bank_b;
|
||||
if(r != NULL)
|
||||
if(create)
|
||||
fprintf(stderr, "<> (%s) (%s)\n", r->a, r->b);
|
||||
else
|
||||
fprintf(stderr, "%02d %s\n", r->id, prog_);
|
||||
return 1;
|
||||
}
|
||||
|
@ -144,7 +146,7 @@ add_rule(char *p)
|
|||
r->a = parse_rule(p), p = walk(p);
|
||||
while((c = *p) && c <= ' ') p++;
|
||||
r->b = parse_rule(p), p = walk(p);
|
||||
return commit_rule(NULL, p);
|
||||
return commit_rule(r, p, 1);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -168,7 +170,7 @@ rewrite(void)
|
|||
else
|
||||
*outp_++ = cc;
|
||||
}
|
||||
return commit_rule(r, res);
|
||||
return commit_rule(r, res, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -179,16 +181,6 @@ rewrite(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
print_rules(void)
|
||||
{
|
||||
Rule *r;
|
||||
fprintf(stderr, "\n");
|
||||
for(r = rules; r < rules_; r++)
|
||||
fprintf(stderr, "<> (%s) (%s)\n", r->a, r->b);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
@ -212,6 +204,5 @@ main(int argc, char **argv)
|
|||
fclose(f);
|
||||
while(rewrite())
|
||||
;
|
||||
print_rules();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue