home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_05 / 8n05128a < prev    next >
Text File  |  1990-04-18  |  2KB  |  50 lines

  1.  
  2.  
  3. ------------------listing 3----------------
  4. #define d define
  5. #d a include
  6. #a <stdio.h>
  7. #a <string.h>
  8. #a <ctype.h>
  9. #d p char*
  10. #d P ,(p)
  11. #d T(E) !strcmp(E,"()")
  12. #d U return
  13. #d W while
  14. #d X sbrk(199)
  15. #d z atof
  16. #d e isspace
  17. #d D A(_)
  18. #d E S(C(_))
  19. #d B(y) p y(_)p _;{
  20. #d G(y,V) B(y)p i;U sprintf(i=X,"%lf",z(E)V z(S(C(D)))),i;}
  21.  
  22.             p sbrk(),*S(),*j(),*O,*H;K,Y,M=14;double
  23.           z();Q(_)p _;{int V=0;W(e(*_))_++;H=_;W(V|!(e
  24.         (*H)|*H==')'||(*H=='('&&H-_)))V+=(*H=='(')-(*H==
  25.       ')'),H++;U H-_;}B(C)U _++,Y=Q(_),_=strncpy(X,_,Y),_[
  26.     Y]=0,_;}B(A)_++,_+=Q(_);W(e(*_))_++;U O=X,*O='(',strcpy(
  27.   O+1,_),O;}B(Z)U _;}B(c)U C(E);}B(q)U A(E);}B(t)p i=E;U H=S(C
  28. (D)),sprintf(O=X,T(H                     )?"(%s)":"(%s %s",i,H+1)
  29.  
  30.              ,O;}B(F)U S(C(A(T(E)?D:_)));}L(i,s)p
  31.  
  32. i,*s;{U isdigit(*i)             ?         z(i)!=z(s):strcmp(i,s);}
  33.   B(b)U L(E,S(C(D)))?"()":"t";}B(R)U E;}B(o)U z(E)<z(S(C(D)))?
  34.     "t":"()";}G(f,+)G(g,-)G(h,*)p r[4][2]={"function"   P R,
  35.       "quote"P C,"lambda"P Z,"defun"P j};B(j)U r[M][1]=D,*
  36.         r[M++]=C(_);}p not[99][2]={"if"P F,"equal"P b,"<"
  37.           P o,"+"P f,"-"P g,"*"P h,"car"P c,"cdr"P q,
  38.             "cons"P t,"t","t"};B(S)int Li,s;p u;if(
  39.               isdigit(*_)|T(_))U _;for(Y=M;Y--;)
  40.                 if(!strcmp(_,*r[Y]))U r[Y][1]
  41.               ;u=E,_=D;if(*u-'(')U(*((p(*)())u)
  42.             )(_);s=Li=M;W(!T(_))r[M][1]=E,*r[M++]
  43.         ="",_=D;O=C(u);W(!T(O))*r[Li++]=C(O),O=A(O);U O=S
  44.     (C(A(u))),M=s,O;}main(){H=O=X,Y=0;W(Y|!e(K=getchar()))K==
  45.     EOF?exit(0):0,Y+=(K=='(')-(K==')'),*H++=K;*H=0,puts(S(O))
  46.                                 ,
  47.                 main();{printf("XLISP 4.0\n");}}
  48. -----------end of listing 3--------
  49.  
  50.