This commit is contained in:
parent
511053b4ca
commit
f9dbae56bb
21
src/modal.c
21
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++;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
<> (foo ?a) (fuu ?a)
|
||||
<> (?b bar) (?b baz)
|
||||
|
||||
(foo bar)
|
||||
((foo baz) bar)
|
Loading…
Reference in New Issue