Starting plode register
This commit is contained in:
parent
84531bcfc3
commit
2831040581
|
@ -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
|
||||
|
|
24
src/modal.c
24
src/modal.c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue