Annotation of 42BSD/usr.bin/y.tab.c, revision 1.1

1.1     ! root        1: # define CHAR 257
        !             2: # define DOT 258
        !             3: # define CCL 259
        !             4: # define NCCL 260
        !             5: # define OR 261
        !             6: # define CAT 262
        !             7: # define STAR 263
        !             8: # define PLUS 264
        !             9: # define QUEST 265
        !            10: 
        !            11: # line 16 "egrep.y"
        !            12: static char *sccsid = "@(#)egrep.y     4.3 (Berkeley) 3/13/83";
        !            13: #include <stdio.h>
        !            14: 
        !            15: #define MAXLIN 350
        !            16: #define MAXPOS 4000
        !            17: #define NCHARS 128
        !            18: #define NSTATES 128
        !            19: #define FINAL -1
        !            20: char gotofn[NSTATES][NCHARS];
        !            21: int state[NSTATES];
        !            22: char out[NSTATES];
        !            23: int line = 1;
        !            24: int name[MAXLIN];
        !            25: int left[MAXLIN];
        !            26: int right[MAXLIN];
        !            27: int parent[MAXLIN];
        !            28: int foll[MAXLIN];
        !            29: int positions[MAXPOS];
        !            30: char chars[MAXLIN];
        !            31: int nxtpos;
        !            32: int nxtchar = 0;
        !            33: int tmpstat[MAXLIN];
        !            34: int initstat[MAXLIN];
        !            35: int xstate;
        !            36: int count;
        !            37: int icount;
        !            38: char *input;
        !            39: FILE *exprfile;
        !            40: 
        !            41: long   lnum;
        !            42: int    bflag;
        !            43: int    cflag;
        !            44: int    fflag;
        !            45: int    lflag;
        !            46: int    nflag;
        !            47: int    hflag   = 1;
        !            48: int    sflag;
        !            49: int    vflag;
        !            50: int    retcode = 0;
        !            51: int    nfile;
        !            52: int    blkno;
        !            53: long   tln;
        !            54: int    nsucc;
        !            55: 
        !            56: int    f;
        !            57: char   *fname;
        !            58: #define yyclearin yychar = -1
        !            59: #define yyerrok yyerrflag = 0
        !            60: extern int yychar;
        !            61: extern short yyerrflag;
        !            62: #ifndef YYMAXDEPTH
        !            63: #define YYMAXDEPTH 150
        !            64: #endif
        !            65: #ifndef YYSTYPE
        !            66: #define YYSTYPE int
        !            67: #endif
        !            68: YYSTYPE yylval, yyval;
        !            69: # define YYERRCODE 256
        !            70: 
        !            71: # line 108 "egrep.y"
        !            72: 
        !            73: yyerror(s) {
        !            74:        fprintf(stderr, "egrep: %s\n", s);
        !            75:        exit(2);
        !            76: }
        !            77: 
        !            78: yylex() {
        !            79:        extern int yylval;
        !            80:        int cclcnt, x;
        !            81:        register char c, d;
        !            82:        switch(c = nextch()) {
        !            83:                case '$':
        !            84:                case '^': c = '\n';
        !            85:                        goto defchar;
        !            86:                case '|': return (OR);
        !            87:                case '*': return (STAR);
        !            88:                case '+': return (PLUS);
        !            89:                case '?': return (QUEST);
        !            90:                case '(': return (c);
        !            91:                case ')': return (c);
        !            92:                case '.': return (DOT);
        !            93:                case '\0': return (0);
        !            94:                case '\n': return (OR);
        !            95:                case '[': 
        !            96:                        x = CCL;
        !            97:                        cclcnt = 0;
        !            98:                        count = nxtchar++;
        !            99:                        if ((c = nextch()) == '^') {
        !           100:                                x = NCCL;
        !           101:                                c = nextch();
        !           102:                        }
        !           103:                        do {
        !           104:                                if (c == '\0') synerror();
        !           105:                                if (c == '-' && cclcnt > 0 && chars[nxtchar-1] != 0) {
        !           106:                                        if ((d = nextch()) != 0) {
        !           107:                                                c = chars[nxtchar-1];
        !           108:                                                while (c < d) {
        !           109:                                                        if (nxtchar >= MAXLIN) overflo();
        !           110:                                                        chars[nxtchar++] = ++c;
        !           111:                                                        cclcnt++;
        !           112:                                                }
        !           113:                                                continue;
        !           114:                                        }
        !           115:                                }
        !           116:                                if (nxtchar >= MAXLIN) overflo();
        !           117:                                chars[nxtchar++] = c;
        !           118:                                cclcnt++;
        !           119:                        } while ((c = nextch()) != ']');
        !           120:                        chars[count] = cclcnt;
        !           121:                        return (x);
        !           122:                case '\\':
        !           123:                        if ((c = nextch()) == '\0') synerror();
        !           124:                defchar:
        !           125:                default: yylval = c; return (CHAR);
        !           126:        }
        !           127: }
        !           128: nextch() {
        !           129:        register char c;
        !           130:        if (fflag) {
        !           131:                if ((c = getc(exprfile)) == EOF) {
        !           132:                        fclose(exprfile);
        !           133:                        return(0);
        !           134:                }
        !           135:        }
        !           136:        else c = *input++;
        !           137:        return(c);
        !           138: }
        !           139: 
        !           140: synerror() {
        !           141:        fprintf(stderr, "egrep: syntax error\n");
        !           142:        exit(2);
        !           143: }
        !           144: 
        !           145: enter(x) int x; {
        !           146:        if(line >= MAXLIN) overflo();
        !           147:        name[line] = x;
        !           148:        left[line] = 0;
        !           149:        right[line] = 0;
        !           150:        return(line++);
        !           151: }
        !           152: 
        !           153: cclenter(x) int x; {
        !           154:        register linno;
        !           155:        linno = enter(x);
        !           156:        right[linno] = count;
        !           157:        return (linno);
        !           158: }
        !           159: 
        !           160: node(x, l, r) {
        !           161:        if(line >= MAXLIN) overflo();
        !           162:        name[line] = x;
        !           163:        left[line] = l;
        !           164:        right[line] = r;
        !           165:        parent[l] = line;
        !           166:        parent[r] = line;
        !           167:        return(line++);
        !           168: }
        !           169: 
        !           170: unary(x, d) {
        !           171:        if(line >= MAXLIN) overflo();
        !           172:        name[line] = x;
        !           173:        left[line] = d;
        !           174:        right[line] = 0;
        !           175:        parent[d] = line;
        !           176:        return(line++);
        !           177: }
        !           178: overflo() {
        !           179:        fprintf(stderr, "egrep: regular expression too long\n");
        !           180:        exit(2);
        !           181: }
        !           182: 
        !           183: cfoll(v) {
        !           184:        register i;
        !           185:        if (left[v] == 0) {
        !           186:                count = 0;
        !           187:                for (i=1; i<=line; i++) tmpstat[i] = 0;
        !           188:                follow(v);
        !           189:                add(foll, v);
        !           190:        }
        !           191:        else if (right[v] == 0) cfoll(left[v]);
        !           192:        else {
        !           193:                cfoll(left[v]);
        !           194:                cfoll(right[v]);
        !           195:        }
        !           196: }
        !           197: cgotofn() {
        !           198:        register c, i, k;
        !           199:        int n, s;
        !           200:        char symbol[NCHARS];
        !           201:        int j, nc, pc, pos;
        !           202:        int curpos, num;
        !           203:        int number, newpos;
        !           204:        count = 0;
        !           205:        for (n=3; n<=line; n++) tmpstat[n] = 0;
        !           206:        if (cstate(line-1)==0) {
        !           207:                tmpstat[line] = 1;
        !           208:                count++;
        !           209:                out[0] = 1;
        !           210:        }
        !           211:        for (n=3; n<=line; n++) initstat[n] = tmpstat[n];
        !           212:        count--;                /*leave out position 1 */
        !           213:        icount = count;
        !           214:        tmpstat[1] = 0;
        !           215:        add(state, 0);
        !           216:        n = 0;
        !           217:        for (s=0; s<=n; s++)  {
        !           218:                if (out[s] == 1) continue;
        !           219:                for (i=0; i<NCHARS; i++) symbol[i] = 0;
        !           220:                num = positions[state[s]];
        !           221:                count = icount;
        !           222:                for (i=3; i<=line; i++) tmpstat[i] = initstat[i];
        !           223:                pos = state[s] + 1;
        !           224:                for (i=0; i<num; i++) {
        !           225:                        curpos = positions[pos];
        !           226:                        if ((c = name[curpos]) >= 0) {
        !           227:                                if (c < NCHARS) symbol[c] = 1;
        !           228:                                else if (c == DOT) {
        !           229:                                        for (k=0; k<NCHARS; k++)
        !           230:                                                if (k!='\n') symbol[k] = 1;
        !           231:                                }
        !           232:                                else if (c == CCL) {
        !           233:                                        nc = chars[right[curpos]];
        !           234:                                        pc = right[curpos] + 1;
        !           235:                                        for (k=0; k<nc; k++) symbol[chars[pc++]] = 1;
        !           236:                                }
        !           237:                                else if (c == NCCL) {
        !           238:                                        nc = chars[right[curpos]];
        !           239:                                        for (j = 0; j < NCHARS; j++) {
        !           240:                                                pc = right[curpos] + 1;
        !           241:                                                for (k = 0; k < nc; k++)
        !           242:                                                        if (j==chars[pc++]) goto cont;
        !           243:                                                if (j!='\n') symbol[j] = 1;
        !           244:                                                cont:;
        !           245:                                        }
        !           246:                                }
        !           247:                                else printf("something's funny\n");
        !           248:                        }
        !           249:                        pos++;
        !           250:                }
        !           251:                for (c=0; c<NCHARS; c++) {
        !           252:                        if (symbol[c] == 1) { /* nextstate(s,c) */
        !           253:                                count = icount;
        !           254:                                for (i=3; i <= line; i++) tmpstat[i] = initstat[i];
        !           255:                                pos = state[s] + 1;
        !           256:                                for (i=0; i<num; i++) {
        !           257:                                        curpos = positions[pos];
        !           258:                                        if ((k = name[curpos]) >= 0)
        !           259:                                                if (
        !           260:                                                        (k == c)
        !           261:                                                        | (k == DOT)
        !           262:                                                        | (k == CCL && member(c, right[curpos], 1))
        !           263:                                                        | (k == NCCL && member(c, right[curpos], 0))
        !           264:                                                ) {
        !           265:                                                        number = positions[foll[curpos]];
        !           266:                                                        newpos = foll[curpos] + 1;
        !           267:                                                        for (k=0; k<number; k++) {
        !           268:                                                                if (tmpstat[positions[newpos]] != 1) {
        !           269:                                                                        tmpstat[positions[newpos]] = 1;
        !           270:                                                                        count++;
        !           271:                                                                }
        !           272:                                                                newpos++;
        !           273:                                                        }
        !           274:                                                }
        !           275:                                        pos++;
        !           276:                                } /* end nextstate */
        !           277:                                if (notin(n)) {
        !           278:                                        if (n >= NSTATES) overflo();
        !           279:                                        add(state, ++n);
        !           280:                                        if (tmpstat[line] == 1) out[n] = 1;
        !           281:                                        gotofn[s][c] = n;
        !           282:                                }
        !           283:                                else {
        !           284:                                        gotofn[s][c] = xstate;
        !           285:                                }
        !           286:                        }
        !           287:                }
        !           288:        }
        !           289: }
        !           290: 
        !           291: cstate(v) {
        !           292:        register b;
        !           293:        if (left[v] == 0) {
        !           294:                if (tmpstat[v] != 1) {
        !           295:                        tmpstat[v] = 1;
        !           296:                        count++;
        !           297:                }
        !           298:                return(1);
        !           299:        }
        !           300:        else if (right[v] == 0) {
        !           301:                if (cstate(left[v]) == 0) return (0);
        !           302:                else if (name[v] == PLUS) return (1);
        !           303:                else return (0);
        !           304:        }
        !           305:        else if (name[v] == CAT) {
        !           306:                if (cstate(left[v]) == 0 && cstate(right[v]) == 0) return (0);
        !           307:                else return (1);
        !           308:        }
        !           309:        else { /* name[v] == OR */
        !           310:                b = cstate(right[v]);
        !           311:                if (cstate(left[v]) == 0 || b == 0) return (0);
        !           312:                else return (1);
        !           313:        }
        !           314: }
        !           315: 
        !           316: 
        !           317: member(symb, set, torf) {
        !           318:        register i, num, pos;
        !           319:        num = chars[set];
        !           320:        pos = set + 1;
        !           321:        for (i=0; i<num; i++)
        !           322:                if (symb == chars[pos++]) return (torf);
        !           323:        return (!torf);
        !           324: }
        !           325: 
        !           326: notin(n) {
        !           327:        register i, j, pos;
        !           328:        for (i=0; i<=n; i++) {
        !           329:                if (positions[state[i]] == count) {
        !           330:                        pos = state[i] + 1;
        !           331:                        for (j=0; j < count; j++)
        !           332:                                if (tmpstat[positions[pos++]] != 1) goto nxt;
        !           333:                        xstate = i;
        !           334:                        return (0);
        !           335:                }
        !           336:                nxt: ;
        !           337:        }
        !           338:        return (1);
        !           339: }
        !           340: 
        !           341: add(array, n) int *array; {
        !           342:        register i;
        !           343:        if (nxtpos + count > MAXPOS) overflo();
        !           344:        array[n] = nxtpos;
        !           345:        positions[nxtpos++] = count;
        !           346:        for (i=3; i <= line; i++) {
        !           347:                if (tmpstat[i] == 1) {
        !           348:                        positions[nxtpos++] = i;
        !           349:                }
        !           350:        }
        !           351: }
        !           352: 
        !           353: follow(v) int v; {
        !           354:        int p;
        !           355:        if (v == line) return;
        !           356:        p = parent[v];
        !           357:        switch(name[p]) {
        !           358:                case STAR:
        !           359:                case PLUS:      cstate(v);
        !           360:                                follow(p);
        !           361:                                return;
        !           362: 
        !           363:                case OR:
        !           364:                case QUEST:     follow(p);
        !           365:                                return;
        !           366: 
        !           367:                case CAT:       if (v == left[p]) {
        !           368:                                        if (cstate(right[p]) == 0) {
        !           369:                                                follow(p);
        !           370:                                                return;
        !           371:                                        }
        !           372:                                }
        !           373:                                else follow(p);
        !           374:                                return;
        !           375:                case FINAL:     if (tmpstat[line] != 1) {
        !           376:                                        tmpstat[line] = 1;
        !           377:                                        count++;
        !           378:                                }
        !           379:                                return;
        !           380:        }
        !           381: }
        !           382: 
        !           383: 
        !           384: main(argc, argv)
        !           385: char **argv;
        !           386: {
        !           387:        while (--argc > 0 && (++argv)[0][0]=='-')
        !           388:                switch (argv[0][1]) {
        !           389: 
        !           390:                case 's':
        !           391:                        sflag++;
        !           392:                        continue;
        !           393: 
        !           394:                case 'h':
        !           395:                        hflag = 0;
        !           396:                        continue;
        !           397: 
        !           398:                case 'b':
        !           399:                        bflag++;
        !           400:                        continue;
        !           401: 
        !           402:                case 'c':
        !           403:                        cflag++;
        !           404:                        continue;
        !           405: 
        !           406:                case 'e':
        !           407:                        argc--;
        !           408:                        argv++;
        !           409:                        goto out;
        !           410: 
        !           411:                case 'f':
        !           412:                        fflag++;
        !           413:                        continue;
        !           414: 
        !           415:                case 'l':
        !           416:                        lflag++;
        !           417:                        continue;
        !           418: 
        !           419:                case 'n':
        !           420:                        nflag++;
        !           421:                        continue;
        !           422: 
        !           423:                case 'v':
        !           424:                        vflag++;
        !           425:                        continue;
        !           426: 
        !           427:                default:
        !           428:                        fprintf(stderr, "egrep: unknown flag\n");
        !           429:                        continue;
        !           430:                }
        !           431: out:
        !           432:        if (argc<=0)
        !           433:                exit(2);
        !           434:        if (fflag) {
        !           435:                fname = *argv;
        !           436:                exprfile = fopen(fname, "r");
        !           437:                if (exprfile == (FILE *)NULL) {
        !           438:                        fprintf(stderr, "egrep: can't open %s\n", fname);
        !           439:                        exit(2);
        !           440:                }
        !           441:        }
        !           442:        else input = *argv;
        !           443:        argc--;
        !           444:        argv++;
        !           445: 
        !           446:        yyparse();
        !           447: 
        !           448:        cfoll(line-1);
        !           449:        cgotofn();
        !           450:        nfile = argc;
        !           451:        if (argc<=0) {
        !           452:                if (lflag) exit(1);
        !           453:                execute(0);
        !           454:        }
        !           455:        else while (--argc >= 0) {
        !           456:                execute(*argv);
        !           457:                argv++;
        !           458:        }
        !           459:        exit(retcode != 0 ? retcode : nsucc == 0);
        !           460: }
        !           461: 
        !           462: execute(file)
        !           463: char *file;
        !           464: {
        !           465:        register char *p;
        !           466:        register cstat;
        !           467:        register ccount;
        !           468:        char buf[1024];
        !           469:        char *nlp;
        !           470:        int istat;
        !           471:        if (file) {
        !           472:                if ((f = open(file, 0)) < 0) {
        !           473:                        fprintf(stderr, "egrep: can't open %s\n", file);
        !           474:                        retcode = 2;
        !           475:                        return;
        !           476:                }
        !           477:        }
        !           478:        else f = 0;
        !           479:        ccount = 0;
        !           480:        lnum = 1;
        !           481:        tln = 0;
        !           482:        blkno = 0;
        !           483:        p = buf;
        !           484:        nlp = p;
        !           485:        if ((ccount = read(f,p,512))<=0) goto done;
        !           486:        istat = cstat = gotofn[0]['\n'];
        !           487:        if (out[cstat]) goto found;
        !           488:        for (;;) {
        !           489:                cstat = gotofn[cstat][*p&0377]; /* all input chars made positive */
        !           490:                if (out[cstat]) {
        !           491:                found:  for(;;) {
        !           492:                                if (*p++ == '\n') {
        !           493:                                        if (vflag == 0) {
        !           494:                                succeed:        nsucc = 1;
        !           495:                                                if (cflag) tln++;
        !           496:                                                else if (sflag)
        !           497:                                                        ;       /* ugh */
        !           498:                                                else if (lflag) {
        !           499:                                                        printf("%s\n", file);
        !           500:                                                        close(f);
        !           501:                                                        return;
        !           502:                                                }
        !           503:                                                else {
        !           504:                                                        if (nfile > 1 && hflag) printf("%s:", file);
        !           505:                                                        if (bflag) printf("%d:", blkno);
        !           506:                                                        if (nflag) printf("%ld:", lnum);
        !           507:                                                        if (p <= nlp) {
        !           508:                                                                while (nlp < &buf[1024]) putchar(*nlp++);
        !           509:                                                                nlp = buf;
        !           510:                                                        }
        !           511:                                                        while (nlp < p) putchar(*nlp++);
        !           512:                                                }
        !           513:                                        }
        !           514:                                        lnum++;
        !           515:                                        nlp = p;
        !           516:                                        if ((out[(cstat=istat)]) == 0) goto brk2;
        !           517:                                }
        !           518:                                cfound:
        !           519:                                if (--ccount <= 0) {
        !           520:                                        if (p <= &buf[512]) {
        !           521:                                                if ((ccount = read(f, p, 512)) <= 0) goto done;
        !           522:                                        }
        !           523:                                        else if (p == &buf[1024]) {
        !           524:                                                p = buf;
        !           525:                                                if ((ccount = read(f, p, 512)) <= 0) goto done;
        !           526:                                        }
        !           527:                                        else {
        !           528:                                                if ((ccount = read(f, p, &buf[1024]-p)) <= 0) goto done;
        !           529:                                        }
        !           530:                                        blkno++;
        !           531:                                }
        !           532:                        }
        !           533:                }
        !           534:                if (*p++ == '\n') {
        !           535:                        if (vflag) goto succeed;
        !           536:                        else {
        !           537:                                lnum++;
        !           538:                                nlp = p;
        !           539:                                if (out[(cstat=istat)]) goto cfound;
        !           540:                        }
        !           541:                }
        !           542:                brk2:
        !           543:                if (--ccount <= 0) {
        !           544:                        if (p <= &buf[512]) {
        !           545:                                if ((ccount = read(f, p, 512)) <= 0) break;
        !           546:                        }
        !           547:                        else if (p == &buf[1024]) {
        !           548:                                p = buf;
        !           549:                                if ((ccount = read(f, p, 512)) <= 0) break;
        !           550:                        }
        !           551:                        else {
        !           552:                                if ((ccount = read(f, p, &buf[1024] - p)) <= 0) break;
        !           553:                        }
        !           554:                        blkno++;
        !           555:                }
        !           556:        }
        !           557: done:  close(f);
        !           558:        if (cflag) {
        !           559:                if (nfile > 1)
        !           560:                        printf("%s:", file);
        !           561:                printf("%ld\n", tln);
        !           562:        }
        !           563: }
        !           564: short yyexca[] ={
        !           565: -1, 1,
        !           566:        0, -1,
        !           567:        -2, 0,
        !           568:        };
        !           569: # define YYNPROD 18
        !           570: # define YYLAST 261
        !           571: short yyact[]={
        !           572: 
        !           573:   10,  22,   4,  14,  11,   2,   1,   5,   0,   0,
        !           574:   10,  15,  16,  17,  18,   0,  19,  20,   3,   0,
        !           575:   10,   0,   0,  12,   0,  20,   0,  20,   0,   0,
        !           576:   10,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           577:   10,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           578:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           579:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           580:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           581:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           582:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           583:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           584:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           585:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           586:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           587:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           588:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           589:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           590:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           591:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           592:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           593:    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
        !           594:    0,   0,   0,   0,   0,   0,  11,   6,   7,   8,
        !           595:    9,  21,   0,  15,  16,  17,  11,   6,   7,   8,
        !           596:    9,  23,   0,  15,  16,  17,  11,   6,   7,   8,
        !           597:    9,  13,   0,  15,  16,  17,  11,   6,   7,   8,
        !           598:    9,   0,   0,  15,  16,  17,  11,   6,   7,   8,
        !           599:    9 };
        !           600: short yypact[]={
        !           601: 
        !           602: -259,-1000,-1000,   0,-1000, -20,-1000,-1000,-1000,-1000,
        !           603:    0,-1000,   0,   0,-252,-1000,-1000,-1000, -40, -30,
        !           604:  -10,   0,-1000,   0 };
        !           605: short yypgo[]={
        !           606: 
        !           607:    0,   6,   5,  18,   3 };
        !           608: short yyr1[]={
        !           609: 
        !           610:    0,   1,   2,   2,   2,   2,   3,   4,   4,   4,
        !           611:    4,   4,   4,   4,   4,   4,   4,   4 };
        !           612: short yyr2[]={
        !           613: 
        !           614:    0,   1,   2,   4,   3,   3,   0,   1,   1,   1,
        !           615:    1,   3,   2,   2,   2,   2,   3,   1 };
        !           616: short yychk[]={
        !           617: 
        !           618: -1000,  -1,  -2,  -3, 261,  -4, 257, 258, 259, 260,
        !           619:   40, 256,  -3, 261,  -4, 263, 264, 265,  -4,  -4,
        !           620:   -4, 261,  41, 261 };
        !           621: short yydef[]={
        !           622: 
        !           623:    6,  -2,   1,   0,   6,   2,   7,   8,   9,  10,
        !           624:    0,  17,   0,   5,  12,  13,  14,  15,   0,   4,
        !           625:   11,   0,  16,   3 };
        !           626: #ifndef lint
        !           627: static char yaccpar_sccsid[] = "@(#)yaccpar    4.1     (Berkeley)      2/11/83";
        !           628: #endif not lint
        !           629: 
        !           630: #
        !           631: # define YYFLAG -1000
        !           632: # define YYERROR goto yyerrlab
        !           633: # define YYACCEPT return(0)
        !           634: # define YYABORT return(1)
        !           635: 
        !           636: /*     parser for yacc output  */
        !           637: 
        !           638: #ifdef YYDEBUG
        !           639: int yydebug = 0; /* 1 for debugging */
        !           640: #endif
        !           641: YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
        !           642: int yychar = -1; /* current input token number */
        !           643: int yynerrs = 0;  /* number of errors */
        !           644: short yyerrflag = 0;  /* error recovery flag */
        !           645: 
        !           646: yyparse() {
        !           647: 
        !           648:        short yys[YYMAXDEPTH];
        !           649:        short yyj, yym;
        !           650:        register YYSTYPE *yypvt;
        !           651:        register short yystate, *yyps, yyn;
        !           652:        register YYSTYPE *yypv;
        !           653:        register short *yyxi;
        !           654: 
        !           655:        yystate = 0;
        !           656:        yychar = -1;
        !           657:        yynerrs = 0;
        !           658:        yyerrflag = 0;
        !           659:        yyps= &yys[-1];
        !           660:        yypv= &yyv[-1];
        !           661: 
        !           662:  yystack:    /* put a state and value onto the stack */
        !           663: 
        !           664: #ifdef YYDEBUG
        !           665:        if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
        !           666: #endif
        !           667:                if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
        !           668:                *yyps = yystate;
        !           669:                ++yypv;
        !           670:                *yypv = yyval;
        !           671: 
        !           672:  yynewstate:
        !           673: 
        !           674:        yyn = yypact[yystate];
        !           675: 
        !           676:        if( yyn<= YYFLAG ) goto yydefault; /* simple state */
        !           677: 
        !           678:        if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
        !           679:        if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
        !           680: 
        !           681:        if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
        !           682:                yychar = -1;
        !           683:                yyval = yylval;
        !           684:                yystate = yyn;
        !           685:                if( yyerrflag > 0 ) --yyerrflag;
        !           686:                goto yystack;
        !           687:                }
        !           688: 
        !           689:  yydefault:
        !           690:        /* default state action */
        !           691: 
        !           692:        if( (yyn=yydef[yystate]) == -2 ) {
        !           693:                if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
        !           694:                /* look through exception table */
        !           695: 
        !           696:                for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
        !           697: 
        !           698:                while( *(yyxi+=2) >= 0 ){
        !           699:                        if( *yyxi == yychar ) break;
        !           700:                        }
        !           701:                if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
        !           702:                }
        !           703: 
        !           704:        if( yyn == 0 ){ /* error */
        !           705:                /* error ... attempt to resume parsing */
        !           706: 
        !           707:                switch( yyerrflag ){
        !           708: 
        !           709:                case 0:   /* brand new error */
        !           710: 
        !           711:                        yyerror( "syntax error" );
        !           712:                yyerrlab:
        !           713:                        ++yynerrs;
        !           714: 
        !           715:                case 1:
        !           716:                case 2: /* incompletely recovered error ... try again */
        !           717: 
        !           718:                        yyerrflag = 3;
        !           719: 
        !           720:                        /* find a state where "error" is a legal shift action */
        !           721: 
        !           722:                        while ( yyps >= yys ) {
        !           723:                           yyn = yypact[*yyps] + YYERRCODE;
        !           724:                           if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
        !           725:                              yystate = yyact[yyn];  /* simulate a shift of "error" */
        !           726:                              goto yystack;
        !           727:                              }
        !           728:                           yyn = yypact[*yyps];
        !           729: 
        !           730:                           /* the current yyps has no shift onn "error", pop stack */
        !           731: 
        !           732: #ifdef YYDEBUG
        !           733:                           if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
        !           734: #endif
        !           735:                           --yyps;
        !           736:                           --yypv;
        !           737:                           }
        !           738: 
        !           739:                        /* there is no state on the stack with an error shift ... abort */
        !           740: 
        !           741:        yyabort:
        !           742:                        return(1);
        !           743: 
        !           744: 
        !           745:                case 3:  /* no shift yet; clobber input char */
        !           746: 
        !           747: #ifdef YYDEBUG
        !           748:                        if( yydebug ) printf( "error recovery discards char %d\n", yychar );
        !           749: #endif
        !           750: 
        !           751:                        if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
        !           752:                        yychar = -1;
        !           753:                        goto yynewstate;   /* try again in the same state */
        !           754: 
        !           755:                        }
        !           756: 
        !           757:                }
        !           758: 
        !           759:        /* reduction by production yyn */
        !           760: 
        !           761: #ifdef YYDEBUG
        !           762:                if( yydebug ) printf("reduce %d\n",yyn);
        !           763: #endif
        !           764:                yyps -= yyr2[yyn];
        !           765:                yypvt = yypv;
        !           766:                yypv -= yyr2[yyn];
        !           767:                yyval = yypv[1];
        !           768:                yym=yyn;
        !           769:                        /* consult goto table to find next state */
        !           770:                yyn = yyr1[yyn];
        !           771:                yyj = yypgo[yyn] + *yyps + 1;
        !           772:                if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
        !           773:                switch(yym){
        !           774:                        
        !           775: case 1:
        !           776: # line 66 "egrep.y"
        !           777: { unary(FINAL, yypvt[-0]);
        !           778:                  line--;
        !           779:                } break;
        !           780: case 2:
        !           781: # line 71 "egrep.y"
        !           782: { yyval = node(CAT, yypvt[-1], yypvt[-0]); } break;
        !           783: case 3:
        !           784: # line 73 "egrep.y"
        !           785: { yyval = node(CAT, yypvt[-2], yypvt[-1]); } break;
        !           786: case 4:
        !           787: # line 75 "egrep.y"
        !           788: { yyval = node(CAT, yypvt[-1], yypvt[-0]); } break;
        !           789: case 5:
        !           790: # line 77 "egrep.y"
        !           791: { yyval = node(CAT, yypvt[-2], yypvt[-1]); } break;
        !           792: case 6:
        !           793: # line 80 "egrep.y"
        !           794: { yyval = enter(DOT);
        !           795:                   yyval = unary(STAR, yyval); } break;
        !           796: case 7:
        !           797: # line 84 "egrep.y"
        !           798: { yyval = enter(yypvt[-0]); } break;
        !           799: case 8:
        !           800: # line 86 "egrep.y"
        !           801: { yyval = enter(DOT); } break;
        !           802: case 9:
        !           803: # line 88 "egrep.y"
        !           804: { yyval = cclenter(CCL); } break;
        !           805: case 10:
        !           806: # line 90 "egrep.y"
        !           807: { yyval = cclenter(NCCL); } break;
        !           808: case 11:
        !           809: # line 94 "egrep.y"
        !           810: { yyval = node(OR, yypvt[-2], yypvt[-0]); } break;
        !           811: case 12:
        !           812: # line 96 "egrep.y"
        !           813: { yyval = node(CAT, yypvt[-1], yypvt[-0]); } break;
        !           814: case 13:
        !           815: # line 98 "egrep.y"
        !           816: { yyval = unary(STAR, yypvt[-1]); } break;
        !           817: case 14:
        !           818: # line 100 "egrep.y"
        !           819: { yyval = unary(PLUS, yypvt[-1]); } break;
        !           820: case 15:
        !           821: # line 102 "egrep.y"
        !           822: { yyval = unary(QUEST, yypvt[-1]); } break;
        !           823: case 16:
        !           824: # line 104 "egrep.y"
        !           825: { yyval = yypvt[-1]; } break;
        !           826:                }
        !           827:                goto yystack;  /* stack new state and value */
        !           828: 
        !           829:        }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.