Modified stdout register

This commit is contained in:
Devine Lu Linvega 2024-04-08 19:57:33 -07:00
parent beda05c9da
commit 16a1617820
3 changed files with 16 additions and 17 deletions

View File

@ -1,4 +1,6 @@
<> (?: print) () <> (NAME) (Modal)
<> (?: print $) (?:)
<> ($ ?x) (?x $)
(Welcome to Modal! $ (Welcome to NAME
Have fun.\n) print Have fun!) print

View File

@ -4,7 +4,6 @@
<> (reverse/l (?h ?t) ?l) (reverse/l ?t (?h ?l)) <> (reverse/l (?h ?t) ?l) (reverse/l ?t (?h ?l))
<> (reverse/l (?h) ?l) (str (?h ?l)) <> (reverse/l (?h) ?l) (str (?h ?l))
<> (implode str ?*) (?*) <> (implode str ?*) (?*)
<> ((read)) (?:)
<> (empty-register) (?x) <> (empty-register) (?x)
<> (explode ?*) (str (?*)) <> (explode ?*) (str (?*))
<> (eq ?x ?x) (#t) <> (eq ?x ?x) (#t)
@ -14,4 +13,4 @@
<> (?x pop) () <> (?x pop) ()
<> (print ?:) () <> (print ?:) ()
(implode reverse (explode hello)) (read) (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.)

View File

@ -62,14 +62,6 @@ set_reg(int r, char *b)
char *a = regs[r], *aa = walk(a), *bb = walk(b); char *a = regs[r], *aa = walk(a), *bb = walk(b);
while(a < aa && b < bb) while(a < aa && b < bb)
if(*a++ != *b++) return 0; if(*a++ != *b++) return 0;
} else if(r == ':') {
char *bb = walk(b);
if(*b == '(') b++, --bb;
while(b < bb) {
char c = *(b++);
if(c == '\\' && *(b++) == 'n') c = 0xa;
putc(c, stdout);
}
} else } else
regs[r] = b; regs[r] = b;
return 1; return 1;
@ -81,7 +73,15 @@ put_reg(char r)
char *s = regs[(int)r]; char *s = regs[(int)r];
if(r == '*') if(r == '*')
s = plode(s); s = plode(s);
else if(s) { else if(r == ':') {
char *bb = walk(s);
if(*s == '(') s++, --bb;
while(s < bb) {
char c = *(s++);
if(c == '\\' && *(s++) == 'n') c = 0xa;
putc(c, stdout);
}
} else if(s) {
char *ss = walk(s); char *ss = walk(s);
while((s < ss)) *outp_++ = *s++; while((s < ss)) *outp_++ = *s++;
} else } else
@ -95,7 +95,6 @@ match_rule(char *p, Rule *r)
int i; int i;
char c, *a = r->a, *b = p; char c, *a = r->a, *b = p;
for(i = 0x21; i < 0x7f; i++) for(i = 0x21; i < 0x7f; i++)
if((char)i != ':')
regs[i] = 0; regs[i] = 0;
while((c = *a)) { while((c = *a)) {
if(c == '?') { if(c == '?') {
@ -211,7 +210,6 @@ main(int argc, char **argv)
} }
while(*(--w) <= ' ') *w = 0; while(*(--w) <= ' ') *w = 0;
fclose(f); fclose(f);
regs[':'] = argv[2];
while(rewrite()) while(rewrite())
; ;
print_rules(); print_rules();