9 static char *
rcsid=
"@(#)$Id$";
22 #define MAXTOKENLENGTH 1024 23 #define MAXSTRINGLENGTH 16384 24 #define to_upper(c) (islower(c) ? ((c)-'a'+'A') : (c)) 25 #define to_lower(c) (isupper(c) ? ((c)-'A'+'a') : (c)) 27 #define syntaxtype(ch) ((enum ch_type)(current_syntax[thr_self()][ch])) 188 #if IRIX || Linux_ppc 192 #define Char signed char 203 while (syntaxtype((
char)ch)==
ch_white) {
205 if (ch==EOF)
return(EOF);}
206 if (ch ==
';' && (Spevalof(QREADTABLE)->c.rdtab.macro->c.vec.v[ch]
211 if (ch==EOF)
return(EOF); }
213 goto skipblank;}
return(ch); }
220 ch=
readch(f); ch=
skip(ctx, f,ch);
return(ch);}
233 if (obj->
c.
lab.
label==labid)
return(obj);
241 {
pointer unsol, *unsolp, result,newlab;
245 pointer_update(oblabels[
thr_self()]->c.lab.next,newlab);
249 pointer_update(newlab->
c.
lab.
value,result);
252 #if sun3 || (!alpha && system5) || sanyo 255 #if (WORD_SIZE == 64) 261 pointer_update(*unsolp,result); }
268 #if sun3 ||( !alpha && system5 ) || sanyo 269 labp->c.lab.unsolved=(
pointer)addr;
271 #if sun4 || vax || news || mips || alpha || Linux 283 {
register pointer obj,element;
286 if ((element=obj->
c.
lab.
value)==UNBOUND)
return(obj);
287 else return(element);}
298 {
register pointer result,element;
305 while ((ch!=
')') && (ch!=EOF) && (i<size)) {
307 element=
read1(ctx,f);
308 if (islabref(element)) {
310 else pointer_update(result->
c.
vec.
v[i],element);
314 while (i<size) {pointer_update(result->
c.
vec.
v[i],element);i++;}
316 while (ch!=
')' && ch!=EOF) ch=
nextch(ctx,f);
320 while ((ch!=
')') && (ch!=EOF)) {
322 element=
read1(ctx,f);
331 else pointer_update(result->
c.
vec.
v[i],element); }
345 while (ch!=
')' && ch!=EOF) {
362 {
register int i=0,x;
371 while (ch!=
')' && ch!=EOF) {
387 register pointer name, klass, elem, result;
399 if (isvecclass(klass)) {
405 else if (isclass(klass)) {
411 while (ch!=
')' && ch!=EOF) {
414 if (islabref(elem)) {
416 else result->
c.
obj.
iv[i++]=elem;
425 {
register pointer name, klass, slot, elem, result, varvec, *slotp;
440 while (ch!=
')' && ch!=EOF) {
447 if (islabref(elem)) {
449 else pointer_update(*slotp,elem); }
470 register
int subchar;
475 while (ch!=subchar && ch!=
'#' && ch!=EOF) ch=
readch(f);
476 if (ch==EOF)
return((
pointer)EOF);
479 if (ch==
'#') {
if (--val<0)
return(UNBOUND);}
482 if (ch==subchar) { ch=
readch(f); val++;}
490 {
register int i=0,j,c,p,q;
493 char ch,
buf[WORD_SIZE];
496 while (i<WORD_SIZE && isxdigit(ch)) { buf[i++] =
ch; ch=
readch(f);}
498 j = i*4 - (buf[0]<
'2' ? 3 :
501 if (j<WORD_SIZE-2) { sscanf(buf,
"%lx",&val);
return(
makeint(val));}
506 for (j=i-1; j>=0; j--) {
508 x=(c<=
'9')?(c-
'0'):(c-
'A'+10);
509 bv[p/(WORD_SIZE-1)] |= ((x << q) & MASK);
510 if (q>=(WORD_SIZE-4) && (x>>(WORD_SIZE-1-q)))
511 bv[p/(WORD_SIZE-1) + 1] = x>>(WORD_SIZE-1-q);
512 p +=4; q = (q+4) % (WORD_SIZE-1);
524 char buf[WORD_SIZE/2],
ch;
526 while (i<WORD_SIZE/2 && ch>=
'0' && ch<
'8') { buf[i++] =
ch; ch=
readch(f);}
528 sscanf(buf,
"%lo",&val);
548 token[i++]=to_upper(ch); ch=
readch(f);}
558 return(
eval(ctx,p));}
564 if (issymbol(expr))
return(
memq(expr,speval(FEATURES)));
566 if (ccar(expr)==QNOT) {
569 else if (ccar(expr)==QAND) {
571 while (iscons(expr)) {
574 else expr=ccdr(expr);}
576 else if (ccar(expr)==QOR) {
578 while (iscons(expr)) {
580 if (r!=
NIL)
return(
T);
581 else expr=ccdr(expr);}
588 {
register pointer flag,result;
599 {
register pointer flag,result;
610 {
register pointer element,result,obj;
613 element=
read1(ctx,f);
615 element=speval(element);
616 if (element==UNBOUND || !isclass(element))
error(
E_NOCLASS,element);
617 obj=
read1(ctx,f); val=ckintval(obj);
618 result=makepointer(val);
619 if (classof(result)!=element)
622 while (ch!=
'>' && ch!=EOF) ch=
readch(f);
631 register int i=0,subchar;
636 if (ch==EOF)
return(UNBOUND);
637 while (isdigit(ch)) {
638 val=val*10+ch-
'0'; ch=
nextch(ctx,f);
639 if (ch==EOF)
return(UNBOUND);}
640 subchar=to_upper(ch);
643 if (isint(macrofunc)) {
645 result=(*intmac)(ctx,f,val,subchar,token);}
656 {
int tleng = 0, lengmax=MAXSTRINGLENGTH;
657 byte buf[MAXSTRINGLENGTH], *token, *newtoken;
663 while ((ch!=terminator) && (ch!=EOF)) {
666 if (tleng >= lengmax) {
668 newtoken=(
byte *)malloc(lengmax*2);
669 memcpy(newtoken,token,tleng);
670 if (malloced==
TRUE) cfree(token);
672 token=newtoken; lengmax=lengmax*2;
677 if (malloced==
TRUE) cfree(token);
683 register
int leng,colon;
687 register int doublecolon=1;
697 if (doublecolon) colon--;
703 if (doublecolon)
return(
intern(ctx,&token[colon],leng-colon,pkg));
707 if (sym)
return(sym);
710 fprintf(stderr,
"%s ",token);
718 register
char *str,**ptr;
722 while (isspace(*str)) str++;
724 if (ch==
'+') str++;
else if (ch==
'-') { str++; sign= -1;}
726 while (
'0'<= *str && *str<(
'0'+base)) val=val*base+(*str++)-
'0';
730 if (
'0'<= *str && *str<=
'9') val=val*base+(*str++ -
'0');
731 else if (
'A'<= *str && *str<(
'A'+base-10)) val=val*base+(*str++ -
'A'+10);
732 else if (
'a'<= *str && *str<(
'a'+base-10)) val=val*base+(*str++ -
'a'+10);
743 int head,i,sign=1, k;
750 if (token[0]==
'+') { head=1;}
751 else if (token[0]==
'-') {head=1; sign= -1;}
755 for (i=head; i<len; i++) {
757 if (k>=
'0' && k<=
'9') k= k-
'0';
758 else if (k>=
'A' && k<=
'Z') k=k-
'A'+10;
759 else if (k>=
'a' && k<=
'z') k=k-
'a'+10;
760 else if (k==
'.')
continue;
767 ctx->lastalloc= vpop();
771 register
int ch,base;
772 {
if (ch<
'0')
return(
FALSE);
774 if (ch<
'0'+base)
return(
TRUE);
776 else if (ch<=
'9')
return(
TRUE);
777 else if (
'A'<=ch && ch<
'A'+base-10)
return(
TRUE);
790 while (ch!=delim_char && ch!=EOF) {
795 element=
read2(ctx,f,0,0,1,token, -1);}
796 else if (syntaxtype(ch)==
ch_white) {
803 if (element!=UNBOUND && element!=(
pointer)EOF) ckpush(element);
805 while ((element=vpop())!=STOPPER) {
806 temp=
cons(ctx,element,result);
830 do { ch=
readch(f);}
while (ch!=
'\n' && ch!=EOF);
845 if(u<v) {t=u; u=
v; v=t;}
846 while(v!=0){t=u %
v; u=
v; v=t;}
858 if (g!=0) { num /=
g; denom /=
g;}
860 if (denom==1)
return(
makeint(num));
867 int escaped,multiescaped,i;
878 extern double atof();
882 if (multiescaped)
goto step9;
886 if (ch==EOF)
goto step10;
887 if (ch<0) ch &= 0xff;
888 ctype=syntaxtype(ch);
894 else ch=to_upper(ch);
895 token[i++]=
ch;
goto step8;
897 token[i++]=
readch(ins); escaped=1;
goto step8;
913 ctype=syntaxtype(ch);
917 token[i++]=
ch;
goto step9;
919 ch=
readch(ins); token[i++]=
ch;
goto step9;
926 if (escaped)
return(
readsymbol(ctx,i,colon,token));
927 base=
intval(Spevalof(READBASE));
930 if ((token[j]==
'+') || (token[j]==
'-')) j++;
931 else if (token[j]==
'.' && token[j+1]==
'\0')
933 if (
is_digit(token[j],base) || token[j]==
'.') {
934 while (
is_digit(token[j],base)) j++;
935 if (token[j] ==
'.') {
936 if (++j==i)
return(
readint(ctx,token,i));
938 while (
is_digit(token[j],base)) j++;
939 c=to_upper(token[j]);
940 if (c==
'E' || c==
'D' || c==
'F' || c==
'L') {
942 if ((token[j]==
'+') || (token[j]==
'-')) j++;
943 while (
is_digit(token[j],base)) j++;
944 if (j==i) { token[c]=
'E';
return(
makeflt(atof(token)));}
946 else if (j==i)
return(
makeflt(atof(token)));
948 else if (token[j] ==
'/') {
950 if (++j==i)
return(
readsymbol(ctx,i,colon,token));
952 while (
is_digit(token[j],base)) j++;
953 if (j==i)
return(
readratio(ctx,token,slash));
955 else if (j==i)
return(
readint(ctx,token,i));
957 c=to_upper(token[j]);
958 if (c==
'E' || c==
'D' || c==
'F' || c==
'L') {
960 if ((token[j]==
'+') || (token[j]==
'-')) j++;
961 while (
is_digit(token[j],base)) j++;
962 if (j==i) { token[c]=
'E';
return(
makeflt(atof(token)));}
964 else if (j==i)
return(
makeflt(atof(token)));
965 else return(
readsymbol(ctx,i,colon,token));} }
972 register int firstch;
973 register pointer macrofunc,result;
978 char token[MAXTOKENLENGTH];
984 if (ch==EOF)
return((
pointer)EOF);
987 ctype=syntaxtype(ch);
994 if (isint(macrofunc)) {
996 result=(*intmac)(ctx,ins,
ch,token);}
998 vpush(ins); vpush(
makeint(ch));
1005 return(
read2(ctx,ins,1,0,1,token,colon));
1012 else ch=to_upper(ch);
1014 return(
read2(ctx,ins,0,0,1,token,colon));}}
1018 register
pointer f,recursivep;
1023 if (ch==EOF)
return((
pointer)EOF);
1024 while (ch==
')') ch=
nextch(ctx,f);
1026 if (recursivep==
NIL) {
1027 pointer_update(oblabels[
thr_self()]->c.lab.next,
NIL);
1029 pointer_update(oblabels[
thr_self()]->c.lab.next,
NIL);}
1030 else val=
read1(ctx,f);
1031 if (val==UNBOUND)
return(
NIL);
1068 pointer_update(Spevalof(QREADTABLE),rdtable);
1069 for (i=0; i<256; i++) {
enum ch_attr charattr[256]
enum ch_type chartype[256]
pointer makesymbol(context *, char *, int, pointer)
byte * current_syntax[MAXTHREAD]
static pointer read_cond_minus(context *ctx, pointer f)
static pointer read_sharp_hex(context *ctx, pointer f, eusinteger_t val, int subchar)
pointer intern(context *, char *, int, pointer)
pointer searchpkg(byte *, int)
int strtol(char *str, char **ptr, int base)
pointer cons(context *, pointer, pointer)
void initreader(context *ctx)
static pointer read1(context *, pointer)
static pointer readrparen(context *ctx, pointer f)
pointer normalize_bignum()
static int nextch(context *ctx, pointer f)
pointer reader(context *ctx, pointer f, pointer recursivep)
int is_digit(int ch, int base)
static pointer readvector(context *ctx, pointer f, int size)
pointer ufuncall(context *, pointer, pointer, pointer, struct bindframe *, int)
pointer read_delimited_list(context *ctx, pointer f, int delim_char, token)
static pointer readlabdef(context *ctx, pointer f, eusinteger_t labx)
static pointer read_uninterned_symbol(context *ctx, pointer f, eusinteger_t val, int subchar, token)
pointer makevector(pointer, int)
static pointer read_sharp_comment(context *ctx, pointer f, eusinteger_t val, int subchar)
static pointer readquote(context *ctx, pointer f)
static pointer read_sharp_eval(context *ctx, pointer f)
static pointer read2(context *, pointer, int, int, int, char *, int)
pointer makereadtable(context *)
static pointer eval_read_cond(context *ctx, pointer expr)
static void addunsolved(pointer labp, pointer *addr)
static pointer readobject(context *ctx, pointer s)
pointer * getobjv(pointer, pointer, pointer)
static pointer readcomment(context *ctx, pointer f)
static pointer readivector(context *ctx, pointer s)
static pointer readsymbol(context *ctx, int leng, int colon, token)
pointer error(enum errorcode ec,...) pointer error(va_alist) va_dcl
pointer oblabels[MAXTHREAD]
static pointer read_sharp_function(context *ctx, pointer f, eusinteger_t val, int subchar)
static pointer readfvector(context *ctx, pointer s)
pointer makestring(char *, int)
void complement_big(pointer x)
static pointer readlabref(context *ctx, pointer f, eusinteger_t val, int subchar)
int unreadch(pointer, int)
pointer makeobject(pointer)
static pointer findlabel(eusinteger_t labx)
static pointer readsharp(context *ctx, pointer f, Char ch, token)
static Char skip(context *ctx, pointer f, Char ch)
static char buf[CHAR_SIZE]
static pointer read_cond_plus(context *ctx, pointer f)
pointer eval(context *, pointer)
static pointer readlist(context *ctx, pointer f, char ch, token)
static pointer readstructure(context *ctx, pointer s)
static pointer read_sharp_octal(context *ctx, pointer f, eusinteger_t val, int subchar)
static pointer readratio(context *ctx, char *token, int slash)
static pointer read_sharp_char(context *ctx, pointer f, eusinteger_t val, int subchar)
static pointer readint(context *ctx, char *token, int len)
static pointer read_sharp_object(context *ctx, pointer f)
static pointer readstring(context *ctx, pointer f, int terminator)