Progress in merging parsers

This commit is contained in:
Devine Lu Linvega 2024-04-24 13:45:08 -07:00
parent 23ec4856e0
commit bcbfe02783
1 changed files with 7 additions and 8 deletions

View File

@ -177,13 +177,11 @@ find_register(Rule *r, char reg)
}
static char *
compile_rule(Rule *r, char *src)
compile_rule(Rule *r, int id, char *src)
{
int i;
char c, *s;
r->id = id, r->ptr = 0;
r->a = dict_, src = parse_frag(src);
r->b = dict_, src = parse_frag(src);
r->ptr = 0;
s = r->a;
while((c = *s++)) { /* left */
if(c == '?') {
@ -193,6 +191,7 @@ compile_rule(Rule *r, char *src)
*s = '0' + reg;
}
}
r->b = dict_, src = parse_frag(src);
s = r->b;
while((c = *s++)) { /* right */
if(c == '?') {
@ -213,15 +212,15 @@ rewrite(void)
if(spacer(last)) {
Rule *r = NULL;
if(c == '<' && s[1] == '>') { /* rule */
r = rules_++, r->id = rules_ - rules - 1;
s = compile_rule(r, s + 2);
r = rules_++;
s = compile_rule(r,rules_ - rules - 1, s + 2);
while(*s == ' ') s++;
return write_rule(r, s, 1);
}
if(c == '?' && s[1] == '(') { /* lambda */
cap = walk(s + 1);
r = &lambda, r->id = -1;
compile_rule(r, s + 2);
r = &lambda;
compile_rule(r, -1, s + 2);
s = cap;
while(*s == ' ') s++;
return apply_rule(&lambda, s);