1: #include "defs.h"
   2: #include <ctype.h>
   3: 
   4:     MSG BADSYM;
   5:     MSG BADVAR;
   6:     MSG BADKET;
   7:     MSG BADSYN;
   8:     MSG NOCFN;
   9:     MSG NOADR;
  10:     MSG BADLOC;
  11: 
  12: extern  struct  SYMbol  *symbol, *cache_by_string();
  13:     int lastframe;
  14:     int kernel;
  15:     int savlastf;
  16:     long    savframe;
  17:     char    svlastov;
  18:     int savpc;
  19:     int callpc;
  20:     char    *lp;
  21:     int octal;
  22:     char    *errflg;
  23:     long    localval;
  24:     static  char    isymbol[MAXSYMLEN + 2];
  25:     char    lastc;
  26:     u_int   *uar0;
  27:     u_int   corhdr[];
  28:     char    curov, startov, lastsymov;
  29:     int overlay;
  30:     long    dot;
  31:     long    ditto;
  32:     int dotinc;
  33:     long    var[];
  34:     long    expv;
  35: 
  36: expr(a)
  37: {   /* term | term dyadic expr |  */
  38:     int     rc;
  39:     long        lhs;
  40: 
  41:     lastsymov = 0;
  42:     rdc(); lp--; rc=term(a);
  43: 
  44:     WHILE rc
  45:     DO  lhs = expv;
  46: 
  47:         switch (readchar()) {
  48: 
  49:             case '+':
  50:             term(a|1); expv += lhs; break;
  51: 
  52:             case '-':
  53:             term(a|1); expv = lhs - expv; break;
  54: 
  55:             case '#':
  56:             term(a|1); expv = round(lhs,expv); break;
  57: 
  58:             case '*':
  59:             term(a|1); expv *= lhs; break;
  60: 
  61:             case '%':
  62:             term(a|1); expv = lhs/expv; break;
  63: 
  64:             case '&':
  65:             term(a|1); expv &= lhs; break;
  66: 
  67:             case '|':
  68:             term(a|1); expv |= lhs; break;
  69: 
  70:             case ')':
  71:             IF (a&2)==0 THEN error(BADKET); FI
  72: 
  73:             default:
  74:             lp--;
  75:             return(rc);
  76:         }
  77:     OD
  78:     return(rc);
  79: }
  80: 
  81: term(a)
  82: {   /* item | monadic item | (expr) | */
  83: 
  84:     switch (readchar()) {
  85: 
  86:             case '*':
  87:             term(a|1); expv=chkget(expv,DSP); return(1);
  88: 
  89:             case '@':
  90:             term(a|1); expv=chkget(expv,ISP); return(1);
  91: 
  92:             case '-':
  93:             term(a|1); expv = -expv; return(1);
  94: 
  95:             case '~':
  96:             term(a|1); expv = ~expv; return(1);
  97: 
  98:             case '(':
  99:             expr(2);
 100:             IF *lp!=')'
 101:             THEN    error(BADSYN);
 102:             ELSE    lp++; return(1);
 103:             FI
 104: 
 105:             default:
 106:             lp--;
 107:             return(item(a));
 108:     }
 109: }
 110: 
 111: item(a)
 112: {   /* name [ . local ] | number | . | ^ | <var | <register | 'x | | */
 113:     int     base, d, frpt, regptr;
 114:     char        savc;
 115:     char        hex;
 116:     long        frame;
 117:     union {float r; long i;} real;
 118:     register struct SYMbol  *symp;
 119:     char        savov;
 120: 
 121:     hex=FALSE;
 122: 
 123:     readchar();
 124:     IF symchar(0)
 125:     THEN    readsym();
 126:         IF lastc=='.'
 127:         THEN    frame=(kernel?corhdr[KR5]:uar0[R5])&EVEN;
 128:             lastframe=0; callpc=kernel?(-2):uar0[PC];
 129:             if (overlay){
 130:                 savov = curov;
 131:                 setovmap(startov);
 132:             }
 133:             WHILE errflg==0
 134:             DO  savpc=callpc;
 135:                 findroutine(frame);
 136:                 if  (eqsym(cache_sym(symbol), isymbol,'~'))
 137:                     break;
 138:                 lastframe=frame;
 139:                 frame=get(frame,DSP)&EVEN;
 140:                 IF frame==0
 141:                 THEN error(NOCFN);
 142:                 FI
 143:             OD
 144:             savlastf=lastframe; savframe=frame;
 145:             svlastov = curov;
 146:             readchar();
 147:             IF symchar(0)
 148:             THEN    chkloc(expv=frame);
 149:             FI
 150:             if (overlay)
 151:                 setovmap(savov);
 152:         ELIF (symp=lookupsym(isymbol))==0 THEN error(BADSYM);
 153:         ELSE expv = symp->value; lastsymov=symp->ovno;
 154:         FI
 155:         lp--;
 156: 
 157: 
 158:     ELIF isdigit(lastc) ORF (hex=TRUE, lastc=='#' ANDF isxdigit(readchar()))
 159:     THEN    expv = 0;
 160:         base = (lastc == '0' ORF octal ? 8 : (hex ? 16 : 10));
 161:         WHILE (hex ? isxdigit(lastc) : isdigit(lastc))
 162:         DO  expv *= base;
 163:             IF (d=convdig(lastc))>=base THEN error(BADSYN); FI
 164:             expv += d; readchar();
 165:             IF expv==0 ANDF (lastc=='x' ORF lastc=='X')
 166:             THEN hex=TRUE; base=16; readchar();
 167:             FI
 168:         OD
 169:         IF lastc=='.' ANDF (base==10 ORF expv==0) ANDF !hex
 170:         THEN    real.r=expv; frpt=0; base=10;
 171:             WHILE isdigit(readchar())
 172:             DO  real.r *= base; frpt++;
 173:                 real.r += lastc-'0';
 174:             OD
 175:             WHILE frpt--
 176:             DO  real.r /= base; OD
 177:             expv = real.i;
 178:         FI
 179:         lp--;
 180: 
 181:     ELIF lastc=='.'
 182:     THEN    readchar();
 183:         IF symchar(0)
 184:         THEN    savov = curov;
 185:             curov = svlastov;
 186:             lastframe=savlastf; callpc=savpc; findroutine(savframe);
 187:             chkloc(savframe);
 188:             if(overlay)
 189:                 setovmap(savov);
 190:         ELSE    expv=dot;
 191:         FI
 192:         lp--;
 193: 
 194:     ELIF lastc=='"'
 195:     THEN    expv=ditto;
 196: 
 197:     ELIF lastc=='+'
 198:     THEN    expv=inkdot(dotinc);
 199: 
 200:     ELIF lastc=='^'
 201:     THEN    expv=inkdot(-dotinc);
 202: 
 203:     ELIF lastc=='<'
 204:     THEN    savc=rdc();
 205:         IF (regptr=getreg(savc)) != NOREG
 206:         THEN    expv=uar0[regptr];
 207:         ELIF (base=varchk(savc)) != -1
 208:         THEN    expv=var[base];
 209:         ELSE    error(BADVAR);
 210:         FI
 211: 
 212:     ELIF lastc=='\''
 213:     THEN    d=4; expv=0;
 214:         WHILE quotchar()
 215:         DO  IF d--
 216:             THEN IF d==1 THEN expv <<=16; FI
 217:              expv |= ((d&1)?lastc:lastc<<8);
 218:             ELSE error(BADSYN);
 219:             FI
 220:         OD
 221: 
 222:     ELIF a
 223:     THEN    error(NOADR);
 224:     ELSE    lp--; return(0);
 225:     FI
 226:     return(1);
 227: }
 228: 
 229: /* service routines for expression reading */
 230: 
 231: readsym()
 232: {
 233:     register char   *p;
 234: 
 235:     p = isymbol;
 236:     REP IF p < &isymbol[MAXSYMLEN]
 237:         THEN *p++ = lastc;
 238:         FI
 239:         readchar();
 240:     PER symchar(1) DONE
 241:     *p++ = 0;
 242: }
 243: 
 244: struct SYMbol *
 245: lookupsym(symstr)
 246:     char    *symstr;
 247: {
 248:     register struct SYMbol *symp, *sc;
 249: 
 250:     symset();
 251:     while   (symp = symget())
 252:         {
 253:         if  (overlay && (symp->type == ISYM))
 254:             {
 255:             if  (sc = cache_by_string(symstr, 1))
 256:                 return(sc);
 257:             if  (eqsym(no_cache_sym(symp), symstr,'~'))
 258:                 break;
 259:             }
 260:         else
 261:             {
 262:             if  (sc = cache_by_string(symstr, 0))
 263:                 return(sc);
 264:             if  (eqsym(no_cache_sym(symp), symstr,'_'))
 265:                 break;
 266:             }
 267:         }
 268: /*
 269:  * We did not enter anything into the cache (no sense inserting hundreds
 270:  * of symbols which didn't match) while examining the (entire) symbol table.
 271:  * Now that we have a match put it into the cache (doing a lookup on it is
 272:  * the easiest way).
 273: */
 274:     if  (symp)
 275:         (void)cache_sym(symp);
 276:     return(symp);
 277: }
 278: 
 279: convdig(c)
 280: char c;
 281: {
 282:     IF isdigit(c)
 283:     THEN    return(c-'0');
 284:     ELIF isxdigit(c)
 285:     THEN    return(c-'a'+10);
 286:     ELSE    return(17);
 287:     FI
 288: }
 289: 
 290: symchar(dig)
 291: {
 292:     IF lastc=='\\' THEN readchar(); return(TRUE); FI
 293:     return( isalpha(lastc) ORF lastc=='_' ORF dig ANDF isdigit(lastc) );
 294: }
 295: 
 296: varchk(name)
 297: {
 298:     IF isdigit(name) THEN return(name-'0'); FI
 299:     IF isalpha(name) THEN return((name&037)-1+10); FI
 300:     return(-1);
 301: }
 302: 
 303: chkloc(frame)
 304: long        frame;
 305: {
 306:     readsym();
 307:     REP IF localsym(frame)==0 THEN error(BADLOC); FI
 308:         expv=localval;
 309:     PER !eqsym(cache_sym(symbol), isymbol,'~') DONE
 310: }
 311: 
 312: eqsym(s1, s2, c)
 313: register char *s1, *s2;
 314:     char    c;
 315:     {
 316: 
 317:     if  (!strcmp(s1, s2))
 318:         return(TRUE);
 319:     else if (*s1++ == c)
 320:         return(!strcmp(s1, s2));
 321:     return(FALSE);
 322:     }

Defined functions

chkloc defined in line 303; used 2 times
convdig defined in line 279; used 1 times
eqsym defined in line 312; used 5 times
expr defined in line 36; used 9 times
item defined in line 111; used 1 times
lookupsym defined in line 244; used 2 times
readsym defined in line 231; used 2 times
symchar defined in line 290; used 4 times
term defined in line 81; used 12 times
varchk defined in line 296; used 2 times

Defined variables

BADKET defined in line 6; used 1 times
  • in line 71
BADLOC defined in line 10; used 1 times
BADSYM defined in line 4; used 1 times
BADSYN defined in line 7; used 3 times
BADVAR defined in line 5; used 1 times
NOADR defined in line 9; used 1 times
NOCFN defined in line 8; used 1 times
callpc defined in line 19; used 3 times
corhdr defined in line 27; used 1 times
curov defined in line 28; used 4 times
ditto defined in line 31; used 1 times
dot defined in line 30; used 1 times
dotinc defined in line 32; used 2 times
errflg defined in line 22; used 1 times
expv defined in line 34; used 38 times
isymbol defined in line 24; used 5 times
kernel defined in line 14; used 2 times
lastc defined in line 25; used 24 times
lastframe defined in line 13; used 4 times
lastsymov defined in line 28; used 2 times
localval defined in line 23; used 1 times
lp defined in line 20; used 9 times
octal defined in line 21; used 1 times
overlay defined in line 29; used 4 times
savframe defined in line 16; used 3 times
savlastf defined in line 15; used 2 times
savpc defined in line 18; used 2 times
startov defined in line 28; used 1 times
svlastov defined in line 17; used 2 times
uar0 defined in line 26; used 3 times
var defined in line 33; used 1 times
Last modified: 1994-01-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1513
Valid CSS Valid XHTML 1.0 Strict