From 921cb53e2af4516716c71972d123f71f7342b285 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 4 Apr 2024 11:54:31 -0700 Subject: [PATCH] Starting rewrite --- src/modal.c | 17 ++++++++++------- test.modal | 6 ++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/modal.c b/src/modal.c index 35b4c26..7db2b7b 100644 --- a/src/modal.c +++ b/src/modal.c @@ -6,8 +6,9 @@ typedef struct { static int rules_len; static Rule rules[0x100]; -static char dict[0x8000], *next = dict; +static char dict[0x8000], *dict_ = dict; static char prog[0x1000], *prog_ = prog; +static char outp[0x1000], *outp_ = outp; static char *regs[0x100]; static char * @@ -38,7 +39,7 @@ match(char *p, Rule *r) } static int -reduce(void) +rewrite(void) { char c, *p = prog; while((c = *p)) { @@ -47,6 +48,7 @@ reduce(void) Rule *r = &rules[i]; match(p, r); } + *outp_++ = c; p++; } return 1; @@ -60,23 +62,23 @@ display(void) Rule *r = &rules[i]; printf("Rule #%d: %s -> %s\n", i, r->a, r->b); } - printf("Program: %s\n", prog); + printf("\nEval: %s -- %s\n", prog, outp); } static char * parse_rulefrag(FILE *f) { int depth = 0; - char c, *origin = next; + char c, *origin = dict_; while(f && fread(&c, 1, 1, f) && c && c != 0xa) { if(c == '(') depth++; if(c == ')') --depth; if(c == ' ' && !depth) break; else - *next++ = c; + *dict_++ = c; } - *next++ = 0; + *dict_++ = 0; return origin; } @@ -122,6 +124,7 @@ main(int argc, char **argv) if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v') return !printf("Modal - Modal Interpreter, 3 Apr 2024.\n"); parse(argv[1]); + rewrite(); display(); - return !reduce(); + return 0; } \ No newline at end of file diff --git a/test.modal b/test.modal index 10e1116..9a0ea5c 100644 --- a/test.modal +++ b/test.modal @@ -1,5 +1,3 @@ -<> (?x world) (?x whurl) -<> (?b bar) (?b baz) +<> bar baz -(hello world) -((foo baz) bar) \ No newline at end of file +foo bar \ No newline at end of file