txlyre 2 هفته پیش
والد
کامیت
d824dae14c
2فایلهای تغییر یافته به همراه25 افزوده شده و 11 حذف شده
  1. 23 9
      jk.c
  2. 2 2
      readme.md

+ 23 - 9
jk.c

@@ -559,7 +559,8 @@ struct _Nt{enum Ntag_t{N_STRAND,N_LITERAL,N_INDEX1,N_INDEX2,N_FUN,N_MONAD,N_DYAD
   Ar*l;
   Nt*a;
   Nt*b;
-  Nt*c;};
+  Nt*c;
+  Z dp;};
 S Nshow(Nt*n){SW(n->tag){CS N_STRAND:{Bt*buf=Bnew();
       for(Z i=0;i<n->l->length;i++){if(i!=0)BappendS(buf,",:");
         S s=Nshow(n->l->data[i]);
@@ -744,9 +745,13 @@ Vt*Swalk(St*st,Nt*node){if(!node)R st->nil;
     R Vnv(nv);}
   CS N_MONAD:R apM(st,Swalk(st,node->a),Swalk(st,node->b));
   CS N_DYAD:R apD(st,Swalk(st,node->a),Swalk(st,node->b),Swalk(st,node->c));
-  CS N_ADV:{Vt*v=Swalk(st,node->a);R Vnv(node->av->adverb(st,v));}
+  CS N_ADV:{Vt*v=Swalk(st,node->a);
+    vt*nv=node->av->adverb(st,v);
+    if(node->dp<2)nv->mark=T;R Vnv(nv);}
   CS N_CONJ:{Vt*v1=Swalk(st,node->a);
-    Vt*v2=Swalk(st,node->b);R Vnv(node->av->conjunction(st,v1,v2));}
+    Vt*v2=Swalk(st,node->b);
+    vt*nv=node->av->conjunction(st,v1,v2);
+    if(node->dp<2)nv->mark=T;R Vnv(nv);}
   CS N_PARTIAL_CONJ:{vt*nv=vnew();
     Vt*a=Swalk(st,node->a);
     S r=Vshow(a);
@@ -761,7 +766,8 @@ Vt*Swalk(St*st,Nt*node){if(!node)R st->nil;
     nv->rank[1]=0;
     nv->rank[2]=0;
     nv->monad=_partial_conjunction;
-    nv->dyad=N;R Vnv(nv);}
+    nv->dyad=N;
+    if(node->dp<2)nv->mark=T;R Vnv(nv);}
   CS N_FORK:{Vt*_f=Swalk(st,node->a);
     if(_f->tag!=VERB)R st->udf;
     Vt*_g=Swalk(st,node->b);
@@ -783,7 +789,8 @@ Vt*Swalk(St*st,Nt*node){if(!node)R st->nil;
     nv->rank[1]=0;
     nv->rank[2]=0;
     nv->monad=_fork_m;
-    nv->dyad=_fork_d;R Vnv(nv);}
+    nv->dyad=_fork_d;
+    if(node->dp<2)nv->mark=T;R Vnv(nv);}
   CS N_HOOK:{Vt*_f=Swalk(st,node->a);
     if(_f->tag!=VERB)R st->udf;
     Vt*_g=Swalk(st,node->b);
@@ -801,7 +808,8 @@ Vt*Swalk(St*st,Nt*node){if(!node)R st->nil;
     nv->rank[1]=0;
     nv->rank[2]=0;
     nv->monad=_hook_m;
-    nv->dyad=_hook_d;R Vnv(nv);}
+    nv->dyad=_hook_d;
+    if(node->dp<2)nv->mark=T;R Vnv(nv);}
   CS N_BOND:{Vt*_f=Swalk(st,node->a);
     if(_f->tag!=VERB)R st->udf;
     Vt*g=Swalk(st,node->b);
@@ -819,7 +827,8 @@ Vt*Swalk(St*st,Nt*node){if(!node)R st->nil;
     nv->rank[1]=0;
     nv->rank[2]=0;
     nv->monad=_bond_m;
-    nv->dyad=_bond_d;R Vnv(nv);}
+    nv->dyad=_bond_d;
+    if(node->dp<2)nv->mark=T;R Vnv(nv);}
   CS N_OVER:{Vt*f=Swalk(st,node->a);
     Vt*_g=Swalk(st,node->b);
     if(_g->tag!=VERB)R st->udf;
@@ -841,7 +850,8 @@ Vt*Swalk(St*st,Nt*node){if(!node)R st->nil;
     nv->rank[1]=0;
     nv->rank[2]=0;
     nv->monad=_over_m;
-    nv->dyad=_over_d;R Vnv(nv);}
+    nv->dyad=_over_d;
+    if(node->dp<2)nv->mark=T;R Vnv(nv);}
   CS N_BIND:{Vt*l=node->a->v;
     Nt*b=node->b;
     UI argc=0;
@@ -2291,7 +2301,8 @@ Nt*Nn3(enum Ntag_t tag,Nt*a,Nt*b,Nt*c){Nt*node=ma(SO(Nt));
 typedef struct{Lt*lexer;
   St*st;
   Z pos;
-  Z end;}Pt;
+  Z end;
+  Z dp;}Pt;
 Pt*Pnew(St*state){Pt*parser=ma(SO(Pt));
   parser->st=state;R parser;}
 V Perror(Pt*parser,S s){fatal(s);}
@@ -2344,7 +2355,10 @@ Nt*PPatom(Pt*parser){Tkt*tok=Plook(parser,0);
   CS T_LPAR:Peat(parser);
     tok=Plook(parser,0);
     if(tok&&tok->tag==T_RPAR){node=Nnl(parser->st->unit);BR;}
+    parser->dp++;
     node=PPexpr(parser);
+    node->dp=parser->dp;
+    parser->dp--;
     tok=Plook(parser,0);
     if(!tok||tok->tag!=T_RPAR)Perror(parser,"unmatched");BR;
   CS T_PUNCT:node=PPverb(parser);

+ 2 - 2
readme.md

@@ -262,8 +262,8 @@ $: dyadic  implode       join y inserting x between
 
 p. monadic print         print x
 P. monadic println       print x and a \n
-s. monadic selfref1      monadic reference to current function or rhs of bind
-s. dyadic  selfref2      dyadic reference to current function or rhs of bind
+s. monadic selfref1      monadic reference to current function or rhs of bind or top-most train
+s. dyadic  selfref2      dyadic reference to current function or rhs of bind or top-most train
 F. monadic read          read file (x=0 to read stdin)
 F. dyadic  write         write file (y=0 to write to stderr)
 t. monadic type          type of x, array=0, verb=1, symbol=2, number=3, char=4, nil=5, udf=6