1: #include "sno.h"
   2: 
   3: 
   4: compon() {
   5:     register struct node *a, *b;
   6:     register int c;
   7:     static next;
   8: 
   9:     if (next == 0)
  10:         schar = getc(); else
  11:         next = 0;
  12:     if (schar == 0) {
  13:         (a=alloc())->typ = 0;
  14:         return(a);
  15:     }
  16:     switch (class(schar->ch)) {
  17: 
  18:     case 1:
  19:         schar->typ = 5;
  20:         return(schar);
  21: 
  22:     case 2:
  23:         schar->typ = 16;
  24:         return(schar);
  25: 
  26:     case 3:
  27:         a = schar;
  28:         for(;;) {
  29:             schar = getc();
  30:             if (schar == 0) {
  31:                 a->typ = 0;
  32:                 return(a);
  33:             }
  34:             if (class(schar->ch) != 3)
  35:                 break;
  36:             free(schar);
  37:         }
  38:         next = 1;
  39:         a->typ = 7;
  40:         return(a);
  41: 
  42:     case 4:
  43:         schar->typ = 8;
  44:         return(schar);
  45: 
  46:     case 5:
  47:         schar->typ = 9;
  48:         return(schar);
  49: 
  50:     case 6:
  51:         a = schar;
  52:         schar = getc();
  53:         if (class(schar->ch) == 3)
  54:             a->typ = 10; else
  55:             a->typ = 1;
  56:         next = 1;
  57:         return(a);
  58: 
  59:     case 7:
  60:         a = schar;
  61:         schar = getc();
  62:         if (class(schar->ch) == 3)
  63:             a->typ = 11; else
  64:             a->typ = 2;
  65:         next = 1;
  66:         return(a);
  67: 
  68:     case 8:
  69:         schar->typ = 12;
  70:         return(schar);
  71: 
  72:     case 9:
  73:         c = schar->ch;
  74:         a = getc();
  75:         if(a == 0)
  76:             goto lerr;
  77:         b = schar;
  78:         if(a->ch == c) {
  79:             free(schar);
  80:             a->typ = 15;
  81:             a->p1 = 0;
  82:             return(a);
  83:         }
  84:         b->p1 = a;
  85:         for(;;) {
  86:             schar = getc();
  87:             if (schar == 0)
  88:             lerr:
  89:                 writes("illegal literal string");
  90:             if(schar->ch == c)
  91:                 break;
  92:             a->p1 = schar;
  93:             a = schar;
  94:         }
  95:         b->p2 = a;
  96:         schar->typ = 15;
  97:         schar->p1 = b;
  98:         return(schar);
  99: 
 100:     case 10:
 101:         schar->typ = 3;
 102:         return(schar);
 103: 
 104:     case 11:
 105:         schar->typ = 4;
 106:         return(schar);
 107: 
 108:     }
 109:     b = alloc();
 110:     b->p1 = a = schar;
 111:     schar = getc();
 112:     while(schar!=0 & !class(schar->ch)) {
 113:         a->p1 = schar;
 114:         a = schar;
 115:         schar = getc();
 116:     }
 117:     b->p2 = a;
 118:     next = 1;
 119:     a = look(b);
 120:     delete(b);
 121:     b = alloc();
 122:     b->typ = 14;
 123:     b->p1 = a;
 124:     return(b);
 125: }
 126: 
 127: nscomp()
 128: {
 129:     register struct node *c;
 130: 
 131:     while((c=compon())->typ == 7)
 132:         free(c);
 133:     return(c);
 134: }
 135: 
 136: push(stack) {
 137:     register struct node *a;
 138: 
 139:     (a=alloc())->p2 = stack;
 140:     return(a);
 141: }
 142: 
 143: pop(stack)
 144: struct node *stack;
 145: {
 146:     register struct node *a, *s;
 147: 
 148:     s = stack;
 149:     if (s == 0)
 150:         writes("pop");
 151:     a = s->p2;
 152:     free(s);
 153:     return(a);
 154: }
 155: 
 156: expr(start, eof, e)
 157: struct node *e;
 158: {
 159:     register struct node *stack, *list, *comp;
 160:     int operand, op, space, op1;
 161:     struct node *a, *b, *c;
 162:     int d;
 163: 
 164:     list = alloc();
 165:     e->p2 = list;
 166:     stack = push(0);
 167:     stack->typ = eof;
 168:     operand = 0;
 169:     space = start;
 170: l1:
 171:     if (space) {
 172:         comp = space;
 173:         space = 0;
 174:     } else
 175:         comp = compon();
 176: 
 177: l3:
 178:     op = comp->typ;
 179:     switch (op) {
 180: 
 181:     case 7:
 182:         space = 1;
 183:         free(comp);
 184:         comp = compon();
 185:         goto l3;
 186: 
 187:     case 10:
 188:         if (space == 0) {
 189:             comp->typ = 1;
 190:             goto l3;
 191:         }
 192: 
 193:     case 11:
 194:         if (space == 0) {
 195:             comp->typ = 2;
 196:             goto l3;
 197:         }
 198: 
 199:     case 8:
 200:     case 9:
 201:         if (operand == 0)
 202:             writes("no operand preceding operator");
 203:         operand = 0;
 204:         goto l5;
 205: 
 206:     case 14:
 207:     case 15:
 208:         if (operand == 0) {
 209:             operand = 1;
 210:             goto l5;
 211:         }
 212:         if (space == 0)
 213:             goto l7;
 214:         goto l4;
 215: 
 216:     case 12:
 217:         if (operand == 0)
 218:             goto l5;
 219:         if (space)
 220:             goto l4;
 221:     l7:
 222:         writes("illegal juxtaposition of operands");
 223: 
 224:     case 16:
 225:         if (operand == 0)
 226:             goto l5;
 227:         if (space)
 228:             goto l4;
 229:         b = compon();
 230:         op = comp->typ = 13;
 231:         if (b->typ == 5) {
 232:             comp->p1 = 0;
 233:             goto l10;
 234:         }
 235:         comp->p1 = a = alloc();
 236:         b = expr(b, 6, a);
 237:         while((d=b->typ) == 4) {
 238:             a->p1 = b;
 239:             a = b;
 240:             b = expr(0, 6, a);
 241:         }
 242:         if (d != 5)
 243:             writes("error in function");
 244:         a->p1 = 0;
 245:     l10:
 246:         free(b);
 247:         goto l6;
 248: 
 249:     l4:
 250:         space = comp;
 251:         op = 7;
 252:         operand = 0;
 253:         goto l6;
 254:     }
 255:     if (operand==0)
 256:         writes("no operand at end of expression");
 257: l5:
 258:     space = 0;
 259: l6:
 260:     op1 = stack->typ;
 261:     if (op > op1) {
 262:         stack = push(stack);
 263:         if (op == 16)
 264:             op = 6;
 265:         stack->typ = op;
 266:         stack->p1 = comp;
 267:         goto l1;
 268:     }
 269:     c = stack->p1;
 270:     stack = pop(stack);
 271:     if (stack == 0) {
 272:         list->typ = 0;
 273:         return(comp);
 274:     }
 275:     if (op1 == 6) {
 276:         if (op != 5)
 277:             writes("too many ('s");
 278:         goto l1;
 279:     }
 280:     if (op1 == 7)
 281:         c = alloc();
 282:     list->typ = op1;
 283:     list->p2 = c->p1;
 284:     list->p1 = c;
 285:     list = c;
 286:     goto l6;
 287: }
 288: 
 289: match(start, m)
 290: struct node *m;
 291: {
 292:     register struct node *list, *comp, *term;
 293:     struct node *a;
 294:     int b, bal;
 295: 
 296:     term = bal = 0;
 297:     list = alloc();
 298:     m->p2 = list;
 299:     comp = start;
 300:     if (!comp)
 301:         comp = compon();
 302:     goto l2;
 303: 
 304: l3:
 305:     list->p1 = a = alloc();
 306:     list = a;
 307: l2:
 308:     switch (comp->typ) {
 309:     case 7:
 310:         free(comp);
 311:         comp = compon();
 312:         goto l2;
 313: 
 314:     case 12:
 315:     case 14:
 316:     case 15:
 317:     case 16:
 318:         term = 0;
 319:         comp = expr(comp, 6, list);
 320:         list->typ = 1;
 321:         goto l3;
 322: 
 323:     case 1:
 324:         free(comp);
 325:         comp = compon();
 326:         bal = 0;
 327:         if (comp->typ == 16) {
 328:             bal = 1;
 329:             free(comp);
 330:             comp = compon();
 331:         }
 332:         a = alloc();
 333:         b = comp->typ;
 334:         if (b == 2 | b == 5 | b == 10 | b == 1)
 335:             a->p1 = 0; else {
 336:             comp = expr(comp, 11, a);
 337:             a->p1 = a->p2;
 338:         }
 339:         if (comp->typ != 2) {
 340:             a->p2 = 0;
 341:         } else {
 342:             free(comp);
 343:             comp = expr(0, 6, a);
 344:         }
 345:         if (bal) {
 346:             if (comp->typ != 5)
 347:                 goto merr;
 348:             free(comp);
 349:             comp = compon();
 350:         }
 351:         b = comp->typ;
 352:         if (b != 1 & b != 10)
 353:             goto merr;
 354:         list->p2 = a;
 355:         list->typ = 2;
 356:         a->typ = bal;
 357:         free(comp);
 358:         comp = compon();
 359:         if(bal)
 360:             term = 0; else
 361:             term = list;
 362:         goto l3;
 363:     }
 364:     if(term)
 365:         term->typ = 3;
 366:     list->typ = 0;
 367:     return(comp);
 368: 
 369: merr:
 370:     writes("unrecognized component in match");
 371: }
 372: 
 373: compile() {
 374:     register struct node *b, *comp;
 375:     struct node *r, *l, *xs, *xf, *g;
 376:     register int a;
 377:     int m, t, as;
 378: 
 379:     m = l = as = xs = xf = t = 0;
 380:     comp = compon();
 381:     a = comp->typ;
 382:     if (a == 14) {
 383:         l = comp->p1;
 384:         free(comp);
 385:         comp = compon();
 386:         a = comp->typ;
 387:     }
 388:     if (a != 7)
 389:         writes("no space beginning statement");
 390:     free(comp);
 391:     if (l == lookdef)
 392:         goto def;
 393:     comp = expr(0, 11, r=alloc());
 394:     a = comp->typ;
 395:     if (a == 0)
 396:         goto asmble;
 397:     if (a == 2)
 398:         goto xfer;
 399:     if (a == 3)
 400:         goto assig;
 401:     m = alloc();
 402:     comp = match(comp, m);
 403:     a = comp->typ;
 404:     if (a == 0)
 405:         goto asmble;
 406:     if (a == 2)
 407:         goto xfer;
 408:     if (a == 3)
 409:         goto assig;
 410:     writes("unrecognized component in match");
 411: 
 412: assig:
 413:     free(comp);
 414:     comp = expr(0, 6, as=alloc());
 415:     a = comp->typ;
 416:     if (a == 0)
 417:         goto asmble;
 418:     if (a == 2)
 419:         goto xfer;
 420:     writes("unrecognized component in assignment");
 421: 
 422: xfer:
 423:     free(comp);
 424:     comp = compon();
 425:     a = comp->typ;
 426:     if (a == 16)
 427:         goto xboth;
 428:     if (a == 0) {
 429:         if (xs!=0 | xf!=0)
 430:             goto asmble;
 431:         goto xerr;
 432:     }
 433:     if (a != 14)
 434:         goto xerr;
 435:     b = comp->p1;
 436:     free(comp);
 437:     if (b == looks)
 438:         goto xsuc;
 439:     if (b == lookf)
 440:         goto xfail;
 441: 
 442: xerr:
 443:     writes("unrecognized component in goto");
 444: 
 445: xboth:
 446:     free(comp);
 447:     xs = alloc();
 448:     xf = alloc();
 449:     comp = expr(0, 6, xs);
 450:     if (comp->typ != 5)
 451:         goto xerr;
 452:     xf->p2 = xs->p2;
 453:     comp = compon();
 454:     if (comp->typ != 0)
 455:         goto xerr;
 456:     goto asmble;
 457: 
 458: xsuc:
 459:     if(xs)
 460:         goto xerr;
 461:     comp = compon();
 462:     if (comp->typ != 16)
 463:         goto xerr;
 464:     comp = expr(0, 6, xs=alloc());
 465:     if (comp->typ != 5)
 466:         goto xerr;
 467:     goto xfer;
 468: 
 469: xfail:
 470:     if (xf)
 471:         goto xerr;
 472:     comp = compon();
 473:     if (comp->typ != 16)
 474:         goto xerr;
 475:     comp = expr(0, 6, xf=alloc());
 476:     if (comp->typ != 5)
 477:         goto xerr;
 478:     goto xfer;
 479: 
 480: asmble:
 481:     if(l) {
 482:         if (l->typ)
 483:             writes("name doubly defined");
 484:         l->p2 = comp;
 485:         l->typ = 2; /* type label;*/
 486:     }
 487:     comp->p2 = r;
 488:     if (m) {
 489:         t++;
 490:         r->p1 = m;
 491:         r = m;
 492:     }
 493:     if (as) {
 494:         t =+ 2;
 495:         r->p1 = as;
 496:         r = as;
 497:     }
 498:     (g=alloc())->p1 = 0;
 499:     if (xs) {
 500:         g->p1 = xs->p2;
 501:         free(xs);
 502:     }
 503:     g->p2 = 0;
 504:     if (xf) {
 505:         g->p2 = xf->p2;
 506:         free(xf);
 507:     }
 508:     r->p1 = g;
 509:     comp->typ = t;
 510:     comp->ch = lc;
 511:     return(comp);
 512: 
 513: def:
 514:     r = nscomp();
 515:     if (r->typ != 14)
 516:         goto derr;
 517:     l = r->p1;
 518:     if (l->typ)
 519:         writes("name doubly defined");
 520:     l->typ = 5; /*type function;*/
 521:     a = r;
 522:     l->p2 = a;
 523:     r = nscomp();
 524:     l = r;
 525:     a->p1 = l;
 526:     if (r->typ == 0)
 527:         goto d4;
 528:     if (r->typ != 16)
 529:         goto derr;
 530: 
 531: d2:
 532:     r = nscomp();
 533:     if (r->typ != 14)
 534:         goto derr;
 535:     a->p2 = r;
 536:     r->typ = 0;
 537:     a = r;
 538:     r = nscomp();
 539:     if (r->typ == 4) {
 540:         free(r);
 541:         goto d2;
 542:     }
 543:     if (r->typ != 5)
 544:         goto derr;
 545:     free(r);
 546:     if ((r=compon())->typ != 0)
 547:         goto derr;
 548:     free(r);
 549: 
 550: d4:
 551:     r = compile();
 552:     a->p2 = 0;
 553:     l->p1 = r;
 554:     l->p2 = 0;
 555:     return(r);
 556: 
 557: derr:
 558:     writes("illegal component in define");
 559: }

Defined functions

compile defined in line 373; used 4 times
compon defined in line 4; used 17 times
expr defined in line 156; used 10 times
match defined in line 289; used 1 times
nscomp defined in line 127; used 4 times
pop defined in line 143; used 3 times
push defined in line 136; used 3 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 799
Valid CSS Valid XHTML 1.0 Strict