diff --git a/src/modal.c b/src/modal.c index fdde5ac..6413661 100644 --- a/src/modal.c +++ b/src/modal.c @@ -8,23 +8,20 @@ static int rules_len; static Rule rules[0x100]; static char dict[0x8000], *next = dict; static char prog[0x1000], *prog_ = prog; - static char *regs[0x100]; -static void -bind(int id, char *addr) -{ - printf("bind register %02x -> %s\n", id, addr); - regs[id] = addr; -} - static char * walk(char *s) { + int depth = 0; char c; - while((c = *s++)) - if(*s == ')' || *s == ' ') break; - return s; + while((c = *s++)) { + if(c == '(') depth++; + if(c == ')') --depth; + if(c == ' ' && !depth) + break; + } + return s - 1; } static int @@ -32,7 +29,7 @@ match(char *p, Rule *r) { char c, *a = r->a, *b = p; while((c = *a)) { - if(c == '?') bind(*(++a), b), a++, b = walk(b), c = *b; + if(c == '?') regs[(int)*(++a)] = b, a++, b = walk(b), c = *b; if(c != *b) return 0; a++, b++; } diff --git a/test.modal b/test.modal index cd62372..05359ed 100644 --- a/test.modal +++ b/test.modal @@ -1,4 +1,3 @@ -<> (foo ?a) (fuu ?a) <> (?b bar) (?b baz) -(foo bar) \ No newline at end of file +((foo baz) bar) \ No newline at end of file