home *** CD-ROM | disk | FTP | other *** search
- (*******************************************************)
- (* LISPIO.INC *)
- (* Include-Modul des LittleLisp-Systems *)
- (* (C) 1988 Reinhard Häring & TOOLBOX *)
- (*******************************************************)
-
- FUNCTION clean(x:lstring):lstring;
- VAR i:INTEGER;
- xs,xss:lstring;
- BEGIN
- IF x='' THEN clean:=x ELSE BEGIN
- i:=0; xs:=x;
- REPEAT i:=i+1; IF NOT (x[i]=' ') THEN
- BEGIN xs:=Copy(x,i,Length(x)); i:=MaxInt; END;
- UNTIL i>=Length(x);
- i:=Length(xs)+1; xss:=xs;
- REPEAT i:=i-1; IF NOT (xs[i]=' ') THEN
- BEGIN xss:=Copy(xs,1,i); i:=-1; END;
- UNTIL i<=1;
- clean:=xss;
- END;
- END;
-
- FUNCTION inlist(xs:lstring):objp;
- FUNCTION atom_string(x:lstring):BOOLEAN;
- VAR i:INTEGER;
- BEGIN
- i:=1;
- IF (Ord(x[1])>=Ord('0')) AND (Ord(x[1])<=Ord('9'))
- THEN atom_string:=FALSE
- ELSE BEGIN
- atom_string:=TRUE;
- REPEAT
- IF Ord(x[i])>32 THEN i:=i+1 ELSE
- BEGIN i:=MaxInt; atom_string:=FALSE; END;
- UNTIL i>Length(x);
- END;
- END; {atom_string}
- FUNCTION number_string(x:lstring):BOOLEAN;
- VAR i:INTEGER; r:INTEGER;
- BEGIN
- Val(x,r,i);
- number_string:=i=0;
- END;
- FUNCTION stringp(x:lstring):BOOLEAN;
- BEGIN
- stringp:=(x[1]='"') AND (x[Length(x)]='"');
- END;
- FUNCTION listp(x:lstring):BOOLEAN;
- BEGIN
- listp:=(x[1]='(') AND (x[Length(x)]=')');
- END;
- PROCEDURE list_convert(x:lstring; VAR p:pair);
- VAR head,tail:objp;
- content:lstring;
- hs,ts,ts1,ts2,ts3:lstring;
- PROCEDURE donix; BEGIN END;
- FUNCTION space_pos(x:lstring):INTEGER;
- VAR i,kl:INTEGER; stringp:BOOLEAN;
- BEGIN
- kl:=0; i:=0; space_pos:=-1; stringp:=FALSE;
- REPEAT
- i:=i+1;
- CASE x[i] OF
- '"': stringp:=NOT stringp;
- ' ': IF (NOT stringp) AND (kl=0) THEN
- BEGIN space_pos:=i; i:=MaxInt; END;
- '(': IF NOT stringp THEN kl:=kl+1;
- ')': IF NOT stringp THEN kl:=kl-1;
- ELSE donix;
- END;
- UNTIL i>=Length(x);
- END;
- FUNCTION head_string(x:lstring):lstring;
- VAR i:INTEGER;
- BEGIN
- i:=space_pos(x);
- IF i=-1 THEN head_string:=x
- ELSE head_string:=clean(Copy(x,1,i-1))
- END;
- FUNCTION tail_string(x:lstring):lstring;
- VAR i:INTEGER;
- BEGIN
- i:=space_pos(x);
- IF i=-1 THEN tail_string:=''
- ELSE tail_string:=clean(Copy(x,i+1,Length(x)));
- END;
- BEGIN
- content:=clean(Copy(x,2,Length(x)-2));
- hs:=head_string(content);
- ts1:=tail_string(content); ts:='('+ts1+')';
- ts2:=clean(ts1);
- ts3:=Copy(ts2,2,255);
- IF NOT (ts2[1]='.') THEN BEGIN
- New(head); New(tail); head:=inlist(hs);
- tail:=inlist(ts);
- p.car:=head; p.cdr:=tail;
- END ELSE BEGIN
- New(head); New(tail); head:=inlist(hs);
- tail:=inlist(ts3);
- p.car:=head; p.cdr:=tail;
- END;
- END;
- VAR cl:lstring;
- i,p:INTEGER;
- o:objp;
- BEGIN
- cl:=clean(xs);
- IF (cl='') OR (cl='()') THEN BEGIN
- New(o); o^.typ:=-1; inlist:=o;
- END
- ELSE BEGIN
- IF Ord(cl[1])=39 THEN
- inlist:=inlist('(quote '+Copy(cl,2,255)+')');
- IF number_string(cl) THEN BEGIN
- Val(cl,i,p);
- New(o); o^.typ:=0; o^.i:=i; inlist:=o;
- END;
- IF atom_string(cl) THEN
- IF Ord(cl[1])=39 THEN
- inlist:=inlist('(quote '+Copy(cl,2,255)+')')
- ELSE BEGIN
- New(o); New(o^.a); o^.a^:=cl;
- o^.typ:=2; inlist:=o;
- END;
- IF stringp(cl) THEN BEGIN
- New(o); New(o^.s);
- o^.s^:=Copy(cl,2,Length(cl)-2);
- o^.typ:=1; inlist:=o;
- END;
- IF listp(cl) THEN BEGIN
- New(o); o^.typ:=3;
- list_convert(cl,o^.o); inlist:=o;
- END;
- END;
- END;
-
- FUNCTION outlist1(x1:objp;t:INTEGER):lstring;
- VAR x:obj; s:lstring; LABEL 99;
- BEGIN
- IF t>maxdepth THEN BEGIN
- outlist1:='...';
- GOTO 99;
- END;
- IF NOT(x1=NIL) THEN BEGIN
- x:=x1^;
- CASE x.typ OF
- -1:outlist1:='()';
- 0:BEGIN Str(x.i,s); outlist1:=s; END;
- 1:outlist1:='"'+x.s^+'"';
- 2:outlist1:=x.a^;
- 3:IF list_format THEN
- IF (x.o.cdr^.typ=3) OR (x.o.cdr^.typ=-1) THEN
- outlist1:='('+outlist1(x.o.car,t+1)+' '+
- Copy(outlist1(x.o.cdr,t+1),2,255)
- ELSE outlist1:='('+outlist1(x.o.car,t+1)+' . '+
- outlist1(x.o.cdr,t+1)+')'
- ELSE outlist1:='('+outlist1(x.o.car,t+1)+' . '
- +outlist1(x.o.cdr,t+1)+')';
- ELSE outlist1:='()';
- END; END; 99:END;
-
- FUNCTION outlist(x:objp):lstring;
- BEGIN outlist:=outlist1(x,1); END;
-