Housekeeping

This commit is contained in:
Devine Lu Linvega 2024-04-04 20:38:45 -07:00
parent 70d567011e
commit b0499fad18
2 changed files with 11 additions and 13 deletions

View File

@ -1,3 +1,4 @@
<> (copy ?x) (?x ?x) <> (?x dup) (?x ?x)
<> (?x ?y swap) (?y ?x)
(copy ABC) (A B swap) dup

View File

@ -74,7 +74,6 @@ save(void)
static int static int
rewrite(void) rewrite(void)
{ {
char c, *p = prog; char c, *p = prog;
while((c = *p)) { while((c = *p)) {
int i; int i;
@ -107,10 +106,8 @@ static void
print_rules(void) print_rules(void)
{ {
int i; int i;
for(i = 0; i < rules_len; i++) { for(i = 0; i < rules_len; i++)
Rule *r = &rules[i]; printf("Rule #%d: %s -> %s\n", i, rules[i].a, rules[i].b);
printf("Rule #%d: %s -> %s\n", i, r->a, r->b);
}
printf("\n"); printf("\n");
} }
@ -158,19 +155,19 @@ static int
parse(char *path) parse(char *path)
{ {
FILE *f; FILE *f;
char c, token[0x40], *tokptr; char c, token[0x40], *token_;
if(!(f = fopen(path, "r"))) if(!(f = fopen(path, "r")))
return !printf("Invalid file: %s\n", path); return !printf("Invalid file: %s\n", path);
tokptr = token; token_ = token;
while(f && fread(&c, 1, 1, f)) { while(f && fread(&c, 1, 1, f)) {
if(c < 0x21) if(c < 0x21)
*tokptr++ = 0x00, tokenize(token, f), tokptr = token; *token_++ = 0x00, tokenize(token, f), token_ = token;
else if(tokptr - token < 0x3f) else if(token_ - token < 0x3f)
*tokptr++ = c; *token_++ = c;
else else
return printf("Token too long: %s\n", token); return printf("Token too long: %s\n", token);
} }
*tokptr++ = 0x00, tokenize(token, f), tokptr = token; *token_++ = 0x00, tokenize(token, f), token_ = token;
fclose(f); fclose(f);
return 1; return 1;
} }