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 Rule rules[0x100];
|
||||||
static char dict[0x8000], *next = dict;
|
static char dict[0x8000], *next = dict;
|
||||||
static char prog[0x1000], *prog_ = prog;
|
static char prog[0x1000], *prog_ = prog;
|
||||||
|
|
||||||
static char *regs[0x100];
|
static char *regs[0x100];
|
||||||
|
|
||||||
static void
|
|
||||||
bind(int id, char *addr)
|
|
||||||
{
|
|
||||||
printf("bind register %02x -> %s\n", id, addr);
|
|
||||||
regs[id] = addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
walk(char *s)
|
walk(char *s)
|
||||||
{
|
{
|
||||||
|
int depth = 0;
|
||||||
char c;
|
char c;
|
||||||
while((c = *s++))
|
while((c = *s++)) {
|
||||||
if(*s == ')' || *s == ' ') break;
|
if(c == '(') depth++;
|
||||||
return s;
|
if(c == ')') --depth;
|
||||||
|
if(c == ' ' && !depth)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return s - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -32,7 +29,7 @@ match(char *p, Rule *r)
|
||||||
{
|
{
|
||||||
char c, *a = r->a, *b = p;
|
char c, *a = r->a, *b = p;
|
||||||
while((c = *a)) {
|
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;
|
if(c != *b) return 0;
|
||||||
a++, b++;
|
a++, b++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
<> (foo ?a) (fuu ?a)
|
|
||||||
<> (?b bar) (?b baz)
|
<> (?b bar) (?b baz)
|
||||||
|
|
||||||
(foo bar)
|
((foo baz) bar)
|
Loading…
Reference in New Issue