Starting plode register

This commit is contained in:
Devine Lu Linvega 2024-04-07 09:08:58 -07:00
parent 84531bcfc3
commit 2831040581
2 changed files with 24 additions and 7 deletions

View File

@ -1,5 +1,4 @@
<> (?x dup) (?x ?x)
<> (?x ?y swap) (?y ?x)
<> ( ?x pop) ()
<> (plode ?*) (?*)
(plode hello)
(1 2 3) (4 5 6) swap pop dup

View File

@ -76,14 +76,32 @@ match(char *p, Rule *r)
return spacer(*b) ? b : NULL;
}
static char *
plode(char *s)
{
char c;
if(s[0] == '(') { /* implode */
} else { /* explode */
int i, j = 0;
while((c = *s++) && !spacer(c))
*outp_++ = '(', *outp_++ = c, j++;
for(i = 0; i < j; i++)
*outp_++ = ')';
}
return s;
}
static int
bind(char r, char *incoming)
commit(char r, char *incoming)
{
int depth = 0;
char c, *s = regs[(int)r];
if(r == ':' && incoming != NULL) s = incoming, queue++;
if(!s) return !fprintf(stderr, "?%c Empty\n", r);
if(s[0] == '(') {
if(r == '*')
s = plode(s);
else if(s[0] == '(') {
while((c = *s++)) {
if(c == '(') depth++;
*outp_++ = c;
@ -161,7 +179,7 @@ rewrite(char *incoming)
char cc, *b = r->b;
while((cc = *b++)) {
if(cc == '?')
bind(*b++, incoming);
commit(*b++, incoming);
else
*outp_++ = cc;
}