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