Starting plode register
This commit is contained in:
parent
84531bcfc3
commit
2831040581
|
@ -1,5 +1,4 @@
|
||||||
<> (?x dup) (?x ?x)
|
<> (plode ?*) (?*)
|
||||||
<> (?x ?y swap) (?y ?x)
|
|
||||||
<> ( ?x pop) ()
|
(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;
|
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
|
static int
|
||||||
bind(char r, char *incoming)
|
commit(char r, char *incoming)
|
||||||
{
|
{
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
char c, *s = regs[(int)r];
|
char c, *s = regs[(int)r];
|
||||||
if(r == ':' && incoming != NULL) s = incoming, queue++;
|
if(r == ':' && incoming != NULL) s = incoming, queue++;
|
||||||
if(!s) return !fprintf(stderr, "?%c Empty\n", r);
|
if(!s) return !fprintf(stderr, "?%c Empty\n", r);
|
||||||
if(s[0] == '(') {
|
if(r == '*')
|
||||||
|
s = plode(s);
|
||||||
|
else if(s[0] == '(') {
|
||||||
while((c = *s++)) {
|
while((c = *s++)) {
|
||||||
if(c == '(') depth++;
|
if(c == '(') depth++;
|
||||||
*outp_++ = c;
|
*outp_++ = c;
|
||||||
|
@ -161,7 +179,7 @@ rewrite(char *incoming)
|
||||||
char cc, *b = r->b;
|
char cc, *b = r->b;
|
||||||
while((cc = *b++)) {
|
while((cc = *b++)) {
|
||||||
if(cc == '?')
|
if(cc == '?')
|
||||||
bind(*b++, incoming);
|
commit(*b++, incoming);
|
||||||
else
|
else
|
||||||
*outp_++ = cc;
|
*outp_++ = cc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue