diff --git a/examples/hello.modal b/examples/hello.modal index a417206..ce71e00 100644 --- a/examples/hello.modal +++ b/examples/hello.modal @@ -3,4 +3,4 @@ <> ($ ?x) (?x $) $ (Welcome to NAME -Have fun!) print \ No newline at end of file +Have fun!\n\n) print \ No newline at end of file diff --git a/examples/test.modal b/examples/test.modal index ce61fe4..6e1a3b9 100644 --- a/examples/test.modal +++ b/examples/test.modal @@ -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.) \ No newline at end of file diff --git a/makefile b/makefile index 297bc15..090551a 100644 --- a/makefile +++ b/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))" diff --git a/src/modal.c b/src/modal.c index d9290d4..86c5f00 100644 --- a/src/modal.c +++ b/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; } \ No newline at end of file