diff --git a/src/modal.c b/src/modal.c index 6e3541a..2b6ab6e 100644 --- a/src/modal.c +++ b/src/modal.c @@ -7,11 +7,32 @@ typedef struct { static int rules_len; static Rule rules[0x100]; static char dict[0x8000], *next = dict; -static char program[0x1000], *prog_ = program; +static char prog[0x1000], *prog_ = prog; + +static int +match(char *p, Rule *r) +{ + char c, *a = r->a, *b = p; + while((c = *a)) { + if(c != *b) return 0; + a++, b++; + } + printf("> found: %s = %s, rule: %s\n", p, r->a, r->b); + return 1; +} static int reduce(void) { + char c, *p = prog; + while((c = *p)) { + int i; + for(i = 0; i < rules_len; i++) { + Rule *r = &rules[i]; + match(p, r); + } + p++; + } return 1; } @@ -23,7 +44,7 @@ display(void) Rule *r = &rules[i]; printf("Rule #%d: %s -> %s\n", i, r->a, r->b); } - printf("Program: %s\n", program); + printf("Program: %s\n", prog); } static char *