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