Basic match
This commit is contained in:
parent
22229bdbb9
commit
f65e5634ff
25
src/modal.c
25
src/modal.c
|
@ -7,11 +7,32 @@ typedef struct {
|
||||||
static int rules_len;
|
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 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
|
static int
|
||||||
reduce(void)
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +44,7 @@ display(void)
|
||||||
Rule *r = &rules[i];
|
Rule *r = &rules[i];
|
||||||
printf("Rule #%d: %s -> %s\n", i, r->a, r->b);
|
printf("Rule #%d: %s -> %s\n", i, r->a, r->b);
|
||||||
}
|
}
|
||||||
printf("Program: %s\n", program);
|
printf("Program: %s\n", prog);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
|
Loading…
Reference in New Issue