Annotation of researchv9/cmd/lex/parser.y, revision 1.1.1.1

1.1       root        1: %token CHAR CCL NCCL STR DELIM SCON ITER NEWE NULLS
                      2: %left SCON '/' NEWE
                      3: %left '|'
                      4: %left '$' '^'
                      5: %left CHAR CCL NCCL '(' '.' STR NULLS
                      6: %left ITER
                      7: %left CAT
                      8: %left '*' '+' '?'
                      9: 
                     10: %{
                     11: #define YYSTYPE union _yystype_
                     12: union _yystype_
                     13: {
                     14:        int     i;
                     15:        char    *cp;
                     16: };
                     17: # include "ldefs.c"
                     18: %}
                     19: %%
                     20: %{
                     21: int i;
                     22: int j,k;
                     23: int g;
                     24: char *p;
                     25: %}
                     26: acc    :       lexinput
                     27:        ={      
                     28: # ifdef DEBUG
                     29:                if(debug) sect2dump();
                     30: # endif
                     31:        }
                     32:        ;
                     33: lexinput:      defns delim prods end
                     34:        |       defns delim end
                     35:        ={
                     36:                if(!funcflag)phead2();
                     37:                funcflag = TRUE;
                     38:        }
                     39:        | error
                     40:        ={
                     41: # ifdef DEBUG
                     42:                if(debug) {
                     43:                        sect1dump();
                     44:                        sect2dump();
                     45:                        }
                     46: # endif
                     47:                }
                     48:        ;
                     49: end:           delim | ;
                     50: defns: defns STR STR
                     51:        ={      scopy($2,dp);
                     52:                def[dptr] = dp;
                     53:                dp += slength($2) + 1;
                     54:                scopy($3,dp);
                     55:                subs[dptr++] = dp;
                     56:                if(dptr >= DEFSIZE)
                     57:                        error("Too many definitions");
                     58:                dp += slength($3) + 1;
                     59:                if(dp >= dchar+DEFCHAR)
                     60:                        error("Definitions too long");
                     61:                subs[dptr]=def[dptr]=0; /* for lookup - require ending null */
                     62:        }
                     63:        |
                     64:        ;
                     65: delim: DELIM
                     66:        ={
                     67: # ifdef DEBUG
                     68:                if(sect == DEFSECTION && debug) sect1dump();
                     69: # endif
                     70:                sect++;
                     71:                }
                     72:        ;
                     73: prods: prods pr
                     74:        ={      $$.i = mn2(RNEWE,$1.i,$2.i);
                     75:                }
                     76:        |       pr
                     77:        ={      $$.i = $1.i;}
                     78:        ;
                     79: pr:    r NEWE
                     80:        ={
                     81:                if(divflg == TRUE)
                     82:                        i = mn1(S1FINAL,casecount);
                     83:                else i = mn1(FINAL,casecount);
                     84:                $$.i = mn2(RCAT,$1.i,i);
                     85:                divflg = FALSE;
                     86:                casecount++;
                     87:                }
                     88:        | error NEWE
                     89:        ={
                     90: # ifdef DEBUG
                     91:                if(debug) sect2dump();
                     92: # endif
                     93:                }
                     94: r:     CHAR
                     95:        ={      $$.i = mn0($1.i); }
                     96:        | STR
                     97:        ={
                     98:                p = $1.cp;
                     99:                i = mn0(*p++);
                    100:                while(*p)
                    101:                        i = mn2(RSTR,i,*p++);
                    102:                $$.i = i;
                    103:                }
                    104:        | '.'
                    105:        ={      symbol['\n'] = 0;
                    106:                if(psave == FALSE){
                    107:                        p = ccptr;
                    108:                        psave = ccptr;
                    109:                        for(i=1;i<'\n';i++){
                    110:                                symbol[i] = 1;
                    111:                                *ccptr++ = i;
                    112:                                }
                    113:                        for(i='\n'+1;i<NCH;i++){
                    114:                                symbol[i] = 1;
                    115:                                *ccptr++ = i;
                    116:                                }
                    117:                        *ccptr++ = 0;
                    118:                        if(ccptr > ccl+CCLSIZE)
                    119:                                error("Too many large character classes");
                    120:                        }
                    121:                else
                    122:                        p = psave;
                    123:                $$.i = mn1(RCCL,p);
                    124:                cclinter(1);
                    125:                }
                    126:        | CCL
                    127:        ={      $$.i = mn1(RCCL,$1.i); }
                    128:        | NCCL
                    129:        ={      $$.i = mn1(RNCCL,$1.i); }
                    130:        | r '*'
                    131:        ={      $$.i = mn1(STAR,$1.i); }
                    132:        | r '+'
                    133:        ={      $$.i = mn1(PLUS,$1.i); }
                    134:        | r '?'
                    135:        ={      $$.i = mn1(QUEST,$1.i); }
                    136:        | r '|' r
                    137:        ={      $$.i = mn2(BAR,$1.i,$3.i); }
                    138:        | r r %prec CAT
                    139:        ={      $$.i = mn2(RCAT,$1.i,$2.i); }
                    140:        | r '/' r
                    141:        ={      if(!divflg){
                    142:                        j = mn1(S2FINAL,-casecount);
                    143:                        i = mn2(RCAT,$1.i,j);
                    144:                        $$.i = mn2(DIV,i,$3.i);
                    145:                        }
                    146:                else {
                    147:                        $$.i = mn2(RCAT,$1.i,$3.i);
                    148:                        warning("Extra slash removed");
                    149:                        }
                    150:                divflg = TRUE;
                    151:                }
                    152:        | r ITER ',' ITER '}'
                    153:        ={      if($2.i > $4.i){
                    154:                        i = $2.i;
                    155:                        $2.i = $4.i;
                    156:                        $4.i = i;
                    157:                        }
                    158:                if($4.i <= 0)
                    159:                        warning("Iteration range must be positive");
                    160:                else {
                    161:                        j = $1.i;
                    162:                        for(k = 2; k<=$2.i;k++)
                    163:                                j = mn2(RCAT,j,dupl($1.i));
                    164:                        for(i = $2.i+1; i<=$4.i; i++){
                    165:                                g = dupl($1.i);
                    166:                                for(k=2;k<=i;k++)
                    167:                                        g = mn2(RCAT,g,dupl($1.i));
                    168:                                j = mn2(BAR,j,g);
                    169:                                }
                    170:                        $$.i = j;
                    171:                        }
                    172:        }
                    173:        | r ITER '}'
                    174:        ={
                    175:                if($2.i < 0)warning("Can't have negative iteration");
                    176:                else if($2.i == 0) $$.i = mn0(RNULLS);
                    177:                else {
                    178:                        j = $1.i;
                    179:                        for(k=2;k<=$2.i;k++)
                    180:                                j = mn2(RCAT,j,dupl($1.i));
                    181:                        $$.i = j;
                    182:                        }
                    183:                }
                    184:        | r ITER ',' '}'
                    185:        ={
                    186:                                /* from n to infinity */
                    187:                if($2.i < 0)warning("Can't have negative iteration");
                    188:                else if($2.i == 0) $$.i = mn1(STAR,$1.i);
                    189:                else if($2.i == 1)$$.i = mn1(PLUS,$1.i);
                    190:                else {          /* >= 2 iterations minimum */
                    191:                        j = $1.i;
                    192:                        for(k=2;k<$2.i;k++)
                    193:                                j = mn2(RCAT,j,dupl($1.i));
                    194:                        k = mn1(PLUS,dupl($1.i));
                    195:                        $$.i = mn2(RCAT,j,k);
                    196:                        }
                    197:                }
                    198:        | SCON r
                    199:        ={      $$.i = mn2(RSCON,$2.i,$1.i); }
                    200:        | '^' r
                    201:        ={      $$.i = mn1(CARAT,$2.i); }
                    202:        | r '$'
                    203:        ={      i = mn0('\n');
                    204:                if(!divflg){
                    205:                        j = mn1(S2FINAL,-casecount);
                    206:                        k = mn2(RCAT,$1.i,j);
                    207:                        $$.i = mn2(DIV,k,i);
                    208:                        }
                    209:                else $$.i = mn2(RCAT,$1.i,i);
                    210:                divflg = TRUE;
                    211:                }
                    212:        | '(' r ')'
                    213:        ={      $$.i = $2.i; }
                    214:        |       NULLS
                    215:        ={      $$.i = mn0(RNULLS); }
                    216:        ;
                    217: %%
                    218: yylex(){
                    219:        register char *p;
                    220:        register int c, i;
                    221:        char  *t, *xp;
                    222:        int n, j, k, x;
                    223:        static int sectbegin;
                    224:        static char token[TOKENSIZE];
                    225:        static int iter;
                    226: 
                    227: # ifdef DEBUG
                    228:        yylval.i = 0;
                    229: # endif
                    230: 
                    231:        if(sect == DEFSECTION) {                /* definitions section */
                    232:                while(!eof) {
                    233:                        if(prev == '\n'){               /* next char is at beginning of line */
                    234:                                getl(p=buf);
                    235:                                switch(*p){
                    236:                                case '%':
                    237:                                        switch(c= *(p+1)){
                    238:                                        case '%':
                    239:                                                lgate();
                    240:                                                if(!ratfor)fprintf(fout,"# ");
                    241:                                                fprintf(fout,"define YYNEWLINE %d\n",ctable['\n']);
                    242:                                                if(!ratfor)fprintf(fout,"yylex(){\nint nstr; extern int yyprevious;\n");
                    243:                                                sectbegin = TRUE;
                    244:                                                i = treesize*(sizeof(*name)+sizeof(*left)+
                    245:                                                        sizeof(*right)+sizeof(*nullstr)+sizeof(*parent))+ALITTLEEXTRA;
                    246:                                                c = (int)myalloc(i,1);
                    247:                                                if(c == 0)
                    248:                                                        error("Too little core for parse tree");
                    249:                                                p = (char *)c;
                    250:                                                cfree((char *)p,i,1);
                    251:                                                name = (int *)myalloc(treesize,sizeof(*name));
                    252:                                                left = (int *)myalloc(treesize,sizeof(*left));
                    253:                                                right = (int *)myalloc(treesize,sizeof(*right));
                    254:                                                nullstr = myalloc(treesize,sizeof(*nullstr));
                    255:                                                parent = (int *)myalloc(treesize,sizeof(*parent));
                    256:                                                if(name == 0 || left == 0 || right == 0 || parent == 0 || nullstr == 0)
                    257:                                                        error("Too little core for parse tree");
                    258:                                                return(freturn(DELIM));
                    259:                                        case 'p': case 'P':     /* has overridden number of positions */
                    260:                                                while(*p && !digit(*p))p++;
                    261:                                                maxpos = siconv(p);
                    262: # ifdef DEBUG
                    263:                                                if (debug) printf("positions (%%p) now %d\n",maxpos);
                    264: # endif
                    265:                                                if(report == 2)report = 1;
                    266:                                                continue;
                    267:                                        case 'n': case 'N':     /* has overridden number of states */
                    268:                                                while(*p && !digit(*p))p++;
                    269:                                                nstates = siconv(p);
                    270: # ifdef DEBUG
                    271:                                                if(debug)printf( " no. states (%%n) now %d\n",nstates);
                    272: # endif
                    273:                                                if(report == 2)report = 1;
                    274:                                                continue;
                    275:                                        case 'e': case 'E':             /* has overridden number of tree nodes */
                    276:                                                while(*p && !digit(*p))p++;
                    277:                                                treesize = siconv(p);
                    278: # ifdef DEBUG
                    279:                                                if (debug) printf("treesize (%%e) now %d\n",treesize);
                    280: # endif
                    281:                                                if(report == 2)report = 1;
                    282:                                                continue;
                    283:                                        case 'o': case 'O':
                    284:                                                while (*p && !digit(*p))p++;
                    285:                                                outsize = siconv(p);
                    286:                                                if (report ==2) report=1;
                    287:                                                continue;
                    288:                                        case 'a': case 'A':             /* has overridden number of transitions */
                    289:                                                while(*p && !digit(*p))p++;
                    290:                                                if(report == 2)report = 1;
                    291:                                                ntrans = siconv(p);
                    292: # ifdef DEBUG
                    293:                                                if (debug)printf("N. trans (%%a) now %d\n",ntrans);
                    294: # endif
                    295:                                                continue;
                    296:                                        case 'k': case 'K': /* overriden packed char classes */
                    297:                                                while (*p && !digit(*p))p++;
                    298:                                                if (report==2) report=1;
                    299:                                                cfree((char *)pchar, pchlen, sizeof(*pchar));
                    300:                                                pchlen = siconv(p);
                    301: # ifdef DEBUG
                    302:                                                if (debug) printf( "Size classes (%%k) now %d\n",pchlen);
                    303: # endif
                    304:                                                pchar=pcptr=myalloc(pchlen, sizeof(*pchar));
                    305:                                                continue;
                    306:                                        case 't': case 'T':     /* character set specifier */
                    307:                                                ZCH = atoi(p+2);
                    308:                                                if (ZCH < NCH) ZCH = NCH;
                    309:                                                if (ZCH > 2*NCH) error("ch table needs redeclaration");
                    310:                                                chset = TRUE;
                    311:                                                for(i = 0; i<ZCH; i++)
                    312:                                                        ctable[i] = 0;
                    313:                                                while(getl(p) && scomp(p,"%T") != 0 && scomp(p,"%t") != 0){
                    314:                                                        if((n = siconv(p)) <= 0 || n > ZCH){
                    315:                                                                warning("Character value %d out of range",n);
                    316:                                                                continue;
                    317:                                                                }
                    318:                                                        while(!space(*p) && *p) p++;
                    319:                                                        while(space(*p)) p++;
                    320:                                                        t = p;
                    321:                                                        while(*t){
                    322:                                                                c = ctrans(&t);
                    323:                                                                if(ctable[c]){
                    324:                                                                        if (printable(c))
                    325:                                                                                warning("Character '%c' used twice",c);
                    326:                                                                        else
                    327:                                                                                warning("Character %o used twice",c);
                    328:                                                                        }
                    329:                                                                else ctable[c] = n;
                    330:                                                                t++;
                    331:                                                                }
                    332:                                                        p = buf;
                    333:                                                        }
                    334:                                                {
                    335:                                                char chused[2*NCH]; int kr;
                    336:                                                for(i=0; i<ZCH; i++)
                    337:                                                        chused[i]=0;
                    338:                                                for(i=0; i<NCH; i++)
                    339:                                                        chused[ctable[i]]=1;
                    340:                                                for(kr=i=1; i<NCH; i++)
                    341:                                                        if (ctable[i]==0)
                    342:                                                                {
                    343:                                                                while (chused[kr] == 0)
                    344:                                                                        kr++;
                    345:                                                                ctable[i]=kr;
                    346:                                                                chused[kr]=1;
                    347:                                                                }
                    348:                                                }
                    349:                                                lgate();
                    350:                                                continue;
                    351:                                        case 'r': case 'R':
                    352:                                                c = 'r';
                    353:                                        case 'c': case 'C':
                    354:                                                if(lgatflg)
                    355:                                                        error("Too late for language specifier");
                    356:                                                ratfor = (c == 'r');
                    357:                                                continue;
                    358:                                        case '{':
                    359:                                                lgate();
                    360:                                                while(getl(p) && scomp(p,"%}") != 0)
                    361:                                                        fprintf(fout, "%s\n",p);
                    362:                                                if(p[0] == '%') continue;
                    363:                                                error("Premature eof");
                    364:                                        case 's': case 'S':             /* start conditions */
                    365:                                                lgate();
                    366:                                                while(*p && index(*p," \t,") < 0) p++;
                    367:                                                n = TRUE;
                    368:                                                while(n){
                    369:                                                        while(*p && index(*p," \t,") >= 0) p++;
                    370:                                                        t = p;
                    371:                                                        while(*p && index(*p," \t,") < 0)p++;
                    372:                                                        if(!*p) n = FALSE;
                    373:                                                        *p++ = 0;
                    374:                                                        if (*t == 0) continue;
                    375:                                                        i = sptr*2;
                    376:                                                        if(!ratfor)fprintf(fout,"# ");
                    377:                                                        fprintf(fout,"define %s %d\n",t,i);
                    378:                                                        scopy(t,sp);
                    379:                                                        sname[sptr++] = sp;
                    380:                                                        sname[sptr] = 0;        /* required by lookup */
                    381:                                                        if(sptr >= STARTSIZE)
                    382:                                                                error("Too many start conditions");
                    383:                                                        sp += slength(sp) + 1;
                    384:                                                        if(sp >= schar+STARTCHAR)
                    385:                                                                error("Start conditions too long");
                    386:                                                        }
                    387:                                                continue;
                    388:                                        default:
                    389:                                                warning("Invalid request %s",p);
                    390:                                                continue;
                    391:                                                }       /* end of switch after seeing '%' */
                    392:                                case ' ': case '\t':            /* must be code */
                    393:                                        lgate();
                    394:                                        fprintf(fout, "%s\n",p);
                    395:                                        continue;
                    396:                                default:                /* definition */
                    397:                                        while(*p && !space(*p)) p++;
                    398:                                        if(*p == 0)
                    399:                                                continue;
                    400:                                        prev = *p;
                    401:                                        *p = 0;
                    402:                                        bptr = p+1;
                    403:                                        yylval.cp = buf;
                    404:                                        if(digit(buf[0]))
                    405:                                                warning("Substitution strings may not begin with digits");
                    406:                                        return(freturn(STR));
                    407:                                        }
                    408:                                }
                    409:                        /* still sect 1, but prev != '\n' */
                    410:                        else {
                    411:                                p = bptr;
                    412:                                while(*p && space(*p)) p++;
                    413:                                if(*p == 0)
                    414:                                        warning("No translation given - null string assumed");
                    415:                                scopy(p,token);
                    416:                                yylval.cp = token;
                    417:                                prev = '\n';
                    418:                                return(freturn(STR));
                    419:                                }
                    420:                        }
                    421:                /* end of section one processing */
                    422:                }
                    423:        else if(sect == RULESECTION){           /* rules and actions */
                    424:                while(!eof){
                    425:                        switch(c=gch()){
                    426:                        case '\0':
                    427:                                return(freturn(0));
                    428:                        case '\n':
                    429:                                if(prev == '\n') continue;
                    430:                                x = NEWE;
                    431:                                break;
                    432:                        case ' ':
                    433:                        case '\t':
                    434:                                if(sectbegin == TRUE){
                    435:                                        cpyact();
                    436:                                        while((c=gch()) && c != '\n');
                    437:                                        continue;
                    438:                                        }
                    439:                                if(!funcflag)phead2();
                    440:                                funcflag = TRUE;
                    441:                                if(ratfor)fprintf(fout,"%d\n",30000+casecount);
                    442:                                else fprintf(fout,"case %d:\n",casecount);
                    443:                                if(cpyact()){
                    444:                                        if(ratfor)fprintf(fout,"goto 30997\n");
                    445:                                        else fprintf(fout,"break;\n");
                    446:                                        }
                    447:                                while((c=gch()) && c != '\n');
                    448:                                if(peek == ' ' || peek == '\t' || sectbegin == TRUE){
                    449:                                        warning("Executable statements should occur right after %%");
                    450:                                        continue;
                    451:                                        }
                    452:                                x = NEWE;
                    453:                                break;
                    454:                        case '%':
                    455:                                if(prev != '\n') goto character;
                    456:                                if(peek == '{'){        /* included code */
                    457:                                        getl(buf);
                    458:                                        while(!eof && getl(buf) && scomp("%}",buf) != 0)
                    459:                                                fprintf(fout,"%s\n",buf);
                    460:                                        continue;
                    461:                                        }
                    462:                                if(peek == '%'){
                    463:                                        c = gch();
                    464:                                        c = gch();
                    465:                                        x = DELIM;
                    466:                                        break;
                    467:                                        }
                    468:                                goto character;
                    469:                        case '|':
                    470:                                if(peek == ' ' || peek == '\t' || peek == '\n'){
                    471:                                        if(ratfor)fprintf(fout,"%d\n",30000+casecount++);
                    472:                                        else fprintf(fout,"case %d:\n",casecount++);
                    473:                                        continue;
                    474:                                        }
                    475:                                x = '|';
                    476:                                break;
                    477:                        case '$':
                    478:                                if(peek == '\n' || peek == ' ' || peek == '\t' || peek == '|' || peek == '/'){
                    479:                                        x = c;
                    480:                                        break;
                    481:                                        }
                    482:                                goto character;
                    483:                        case '^':
                    484:                                if(prev != '\n' && scon != TRUE) goto character;        /* valid only at line begin */
                    485:                                x = c;
                    486:                                break;
                    487:                        case '?':
                    488:                        case '+':
                    489:                        case '.':
                    490:                        case '*':
                    491:                        case '(':
                    492:                        case ')':
                    493:                        case ',':
                    494:                        case '/':
                    495:                                x = c;
                    496:                                break;
                    497:                        case '}':
                    498:                                iter = FALSE;
                    499:                                x = c;
                    500:                                break;
                    501:                        case '{':       /* either iteration or definition */
                    502:                                if(digit(c=gch())){     /* iteration */
                    503:                                        iter = TRUE;
                    504:                                ieval:
                    505:                                        i = 0;
                    506:                                        while(digit(c)){
                    507:                                                token[i++] = c;
                    508:                                                c = gch();
                    509:                                                }
                    510:                                        token[i] = 0;
                    511:                                        yylval.i = siconv(token);
                    512:                                        munput('c',c);
                    513:                                        x = ITER;
                    514:                                        break;
                    515:                                        }
                    516:                                else {          /* definition */
                    517:                                        i = 0;
                    518:                                        while(c && c!='}'){
                    519:                                                token[i++] = c;
                    520:                                                c = gch();
                    521:                                                }
                    522:                                        token[i] = 0;
                    523:                                        i = lookup(token,def);
                    524:                                        if(i < 0)
                    525:                                                warning("Definition %s not found",token);
                    526:                                        else
                    527:                                                munput('s',subs[i]);
                    528:                                        continue;
                    529:                                        }
                    530:                        case '<':               /* start condition ? */
                    531:                                if(prev != '\n')                /* not at line begin, not start */
                    532:                                        goto character;
                    533:                                t = slptr;
                    534:                                do {
                    535:                                        i = 0;
                    536:                                        c = gch();
                    537:                                        while(c != ',' && c && c != '>'){
                    538:                                                token[i++] = c;
                    539:                                                c = gch();
                    540:                                                }
                    541:                                        token[i] = 0;
                    542:                                        if(i == 0)
                    543:                                                goto character;
                    544:                                        i = lookup(token,sname);
                    545:                                        if(i < 0) {
                    546:                                                warning("Undefined start condition %s",token);
                    547:                                                continue;
                    548:                                                }
                    549:                                        *slptr++ = i+1;
                    550:                                        } while(c && c != '>');
                    551:                                *slptr++ = 0;
                    552:                                /* check if previous value re-usable */
                    553:                                for (xp=slist; xp<t; )
                    554:                                        {
                    555:                                        if (strcmp(xp, t)==0)
                    556:                                                break;
                    557:                                        while (*xp++);
                    558:                                        }
                    559:                                if (xp<t)
                    560:                                        {
                    561:                                        /* re-use previous pointer to string */
                    562:                                        slptr=t;
                    563:                                        t=xp;
                    564:                                        }
                    565:                                if(slptr > slist+STARTSIZE)             /* note not packed ! */
                    566:                                        error("Too many start conditions used");
                    567:                                yylval.cp = t;
                    568:                                x = SCON;
                    569:                                break;
                    570:                        case '"':
                    571:                                i = 0;
                    572:                                while((c=gch()) && c != '"' && c != '\n'){
                    573:                                        if(c == '\\') c = usescape(c=gch());
                    574:                                        token[i++] = c;
                    575:                                        if(i > TOKENSIZE){
                    576:                                                warning("String too long");
                    577:                                                i = TOKENSIZE-1;
                    578:                                                break;
                    579:                                                }
                    580:                                        }
                    581:                                if(c == '\n') {
                    582:                                        yyline--;
                    583:                                        warning("Non-terminated string");
                    584:                                        yyline++;
                    585:                                        }
                    586:                                token[i] = 0;
                    587:                                if(i == 0)x = NULLS;
                    588:                                else if(i == 1){
                    589:                                        yylval.i = token[0];
                    590:                                        x = CHAR;
                    591:                                        }
                    592:                                else {
                    593:                                        yylval.cp = token;
                    594:                                        x = STR;
                    595:                                        }
                    596:                                break;
                    597:                        case '[':
                    598:                                for(i=1;i<NCH;i++) symbol[i] = 0;
                    599:                                x = CCL;
                    600:                                if((c = gch()) == '^'){
                    601:                                        x = NCCL;
                    602:                                        c = gch();
                    603:                                        }
                    604:                                while(c != ']' && c){
                    605:                                        if(c == '\\') c = usescape(c=gch());
                    606:                                        symbol[c] = 1;
                    607:                                        j = c;
                    608:                                        if((c=gch()) == '-' && peek != ']'){            /* range specified */
                    609:                                                c = gch();
                    610:                                                if(c == '\\') c = usescape(c=gch());
                    611:                                                k = c;
                    612:                                                if(j > k) {
                    613:                                                        n = j;
                    614:                                                        j = k;
                    615:                                                        k = n;
                    616:                                                        }
                    617:                                                if(!(('A' <= j && k <= 'Z') ||
                    618:                                                     ('a' <= j && k <= 'z') ||
                    619:                                                     ('0' <= j && k <= '9')))
                    620:                                                        warning("Non-portable Character Class");
                    621:                                                for(n=j+1;n<=k;n++)
                    622:                                                        symbol[n] = 1;          /* implementation dependent */
                    623:                                                c = gch();
                    624:                                                }
                    625:                                        }
                    626:                                /* try to pack ccl's */
                    627:                                i = 0;
                    628:                                for(j=0;j<NCH;j++)
                    629:                                        if(symbol[j])token[i++] = j;
                    630:                                token[i] = 0;
                    631:                                p = ccptr;
                    632:                                if(optim){
                    633:                                        p = ccl;
                    634:                                        while(p <ccptr && scomp(token,p) != 0)p++;
                    635:                                        }
                    636:                                if(p < ccptr)   /* found it */
                    637:                                        yylval.cp = p;
                    638:                                else {
                    639:                                        yylval.cp = ccptr;
                    640:                                        scopy(token,ccptr);
                    641:                                        ccptr += slength(token) + 1;
                    642:                                        if(ccptr >= ccl+CCLSIZE)
                    643:                                                error("Too many large character classes");
                    644:                                        }
                    645:                                cclinter(x==CCL);
                    646:                                break;
                    647:                        case '\\':
                    648:                                c = usescape(c=gch());
                    649:                        default:
                    650:                        character:
                    651:                                if(iter){       /* second part of an iteration */
                    652:                                        iter = FALSE;
                    653:                                        if('0' <= c && c <= '9')
                    654:                                                goto ieval;
                    655:                                        }
                    656:                                if(alpha(peek)){
                    657:                                        i = 0;
                    658:                                        yylval.cp = token;
                    659:                                        token[i++] = c;
                    660:                                        while(alpha(peek))
                    661:                                                token[i++] = gch();
                    662:                                        if(peek == '?' || peek == '*' || peek == '+')
                    663:                                                munput('c',token[--i]);
                    664:                                        token[i] = 0;
                    665:                                        if(i == 1){
                    666:                                                yylval.i = token[0];
                    667:                                                x = CHAR;
                    668:                                                }
                    669:                                        else x = STR;
                    670:                                        }
                    671:                                else {
                    672:                                        yylval.i = c;
                    673:                                        x = CHAR;
                    674:                                        }
                    675:                                }
                    676:                        scon = FALSE;
                    677:                        if(x == SCON)scon = TRUE;
                    678:                        sectbegin = FALSE;
                    679:                        return(freturn(x));
                    680:                        }
                    681:                }
                    682:        /* section three */
                    683:        ptail();
                    684: # ifdef DEBUG
                    685:        if(debug)
                    686:                fprintf(fout,"\n/*this comes from section three - debug */\n");
                    687: # endif
                    688:        while(getl(buf) && !eof)
                    689:                fprintf(fout,"%s\n",buf);
                    690:        return(freturn(0));
                    691:        }
                    692: /* end of yylex */
                    693: # ifdef DEBUG
                    694: freturn(i)
                    695:   int i; {
                    696:        if(yydebug) {
                    697:                printf("now return ");
                    698:                if(i < NCH) allprint(i);
                    699:                else printf("%d",i);
                    700:                printf("   yylval = ");
                    701:                switch(i){
                    702:                        case STR: case CCL: case NCCL:
                    703:                                strpt(yylval.cp);
                    704:                                break;
                    705:                        case CHAR:
                    706:                                allprint(yylval.i);
                    707:                                break;
                    708:                        default:
                    709:                                printf("%d",yylval.i);
                    710:                                break;
                    711:                        }
                    712:                putchar('\n');
                    713:                }
                    714:        return(i);
                    715:        }
                    716: # endif

unix.superglobalmegacorp.com

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