Annotation of 43BSDReno/pgrm/lex/yylex.c, revision 1.1.1.1

1.1       root        1: /* yylex - scanner front-end for flex */
                      2: 
                      3: /*-
                      4:  * Copyright (c) 1990 The Regents of the University of California.
                      5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to Berkeley by
                      8:  * Vern Paxson.
                      9:  * 
                     10:  * The United States Government has rights in this work pursuant
                     11:  * to contract no. DE-AC03-76SF00098 between the United States
                     12:  * Department of Energy and the University of California.
                     13:  *
                     14:  * Redistribution and use in source and binary forms are permitted provided
                     15:  * that: (1) source distributions retain this entire copyright notice and
                     16:  * comment, and (2) distributions including binaries display the following
                     17:  * acknowledgement:  ``This product includes software developed by the
                     18:  * University of California, Berkeley and its contributors'' in the
                     19:  * documentation or other materials provided with the distribution and in
                     20:  * all advertising materials mentioning features or use of this software.
                     21:  * Neither the name of the University nor the names of its contributors may
                     22:  * be used to endorse or promote products derived from this software without
                     23:  * specific prior written permission.
                     24:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     25:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     26:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     27:  */
                     28: 
                     29: #ifndef lint
                     30: static char sccsid[] = "@(#)yylex.c    5.2 (Berkeley) 6/18/90";
                     31: #endif /* not lint */
                     32: 
                     33: #include <ctype.h>
                     34: #include "flexdef.h"
                     35: #include "parse.h"
                     36: 
                     37: 
                     38: /* ANSI C does not guarantee that isascii() is defined */
                     39: #ifndef isascii
                     40: #define isascii(c) ((c) <= 0177)
                     41: #endif
                     42: 
                     43: 
                     44: /* yylex - scan for a regular expression token
                     45:  *
                     46:  * synopsis
                     47:  *
                     48:  *   token = yylex();
                     49:  *
                     50:  *     token - return token found
                     51:  */
                     52: 
                     53: int yylex()
                     54: 
                     55:     {
                     56:     int toktype;
                     57:     static int beglin = false;
                     58: 
                     59:     if ( eofseen )
                     60:        toktype = EOF;
                     61:     else
                     62:        toktype = flexscan();
                     63: 
                     64:     if ( toktype == EOF || toktype == 0 )
                     65:        {
                     66:        eofseen = 1;
                     67: 
                     68:        if ( sectnum == 1 )
                     69:            {
                     70:            synerr( "premature EOF" );
                     71:            sectnum = 2;
                     72:            toktype = SECTEND;
                     73:            }
                     74: 
                     75:        else if ( sectnum == 2 )
                     76:            {
                     77:            sectnum = 3;
                     78:            toktype = 0;
                     79:            }
                     80: 
                     81:        else
                     82:            toktype = 0;
                     83:        }
                     84: 
                     85:     if ( trace )
                     86:        {
                     87:        if ( beglin )
                     88:            {
                     89:            fprintf( stderr, "%d\t", num_rules + 1 );
                     90:            beglin = 0;
                     91:            }
                     92: 
                     93:        switch ( toktype )
                     94:            {
                     95:            case '<':
                     96:            case '>':
                     97:            case '^':
                     98:            case '$':
                     99:            case '"':
                    100:            case '[':
                    101:            case ']':
                    102:            case '{':
                    103:            case '}':
                    104:            case '|':
                    105:            case '(':
                    106:            case ')':
                    107:            case '-':
                    108:            case '/':
                    109:            case '\\':
                    110:            case '?':
                    111:            case '.':
                    112:            case '*':
                    113:            case '+':
                    114:            case ',':
                    115:                (void) putc( toktype, stderr );
                    116:                break;
                    117: 
                    118:            case '\n':
                    119:                (void) putc( '\n', stderr );
                    120: 
                    121:                if ( sectnum == 2 )
                    122:                    beglin = 1;
                    123: 
                    124:                break;
                    125: 
                    126:            case SCDECL:
                    127:                fputs( "%s", stderr );
                    128:                break;
                    129: 
                    130:            case XSCDECL:
                    131:                fputs( "%x", stderr );
                    132:                break;
                    133: 
                    134:            case WHITESPACE:
                    135:                (void) putc( ' ', stderr );
                    136:                break;
                    137: 
                    138:            case SECTEND:
                    139:                fputs( "%%\n", stderr );
                    140: 
                    141:                /* we set beglin to be true so we'll start
                    142:                 * writing out numbers as we echo rules.  flexscan() has
                    143:                 * already assigned sectnum
                    144:                 */
                    145: 
                    146:                if ( sectnum == 2 )
                    147:                    beglin = 1;
                    148: 
                    149:                break;
                    150: 
                    151:            case NAME:
                    152:                fprintf( stderr, "'%s'", nmstr );
                    153:                break;
                    154: 
                    155:            case CHAR:
                    156:                switch ( yylval )
                    157:                    {
                    158:                    case '<':
                    159:                    case '>':
                    160:                    case '^':
                    161:                    case '$':
                    162:                    case '"':
                    163:                    case '[':
                    164:                    case ']':
                    165:                    case '{':
                    166:                    case '}':
                    167:                    case '|':
                    168:                    case '(':
                    169:                    case ')':
                    170:                    case '-':
                    171:                    case '/':
                    172:                    case '\\':
                    173:                    case '?':
                    174:                    case '.':
                    175:                    case '*':
                    176:                    case '+':
                    177:                    case ',':
                    178:                        fprintf( stderr, "\\%c", yylval );
                    179:                        break;
                    180: 
                    181:                    default:
                    182:                        if ( ! isascii( yylval ) || ! isprint( yylval ) )
                    183:                            fprintf( stderr, "\\%.3o", yylval );
                    184:                        else
                    185:                            (void) putc( yylval, stderr );
                    186:                        break;
                    187:                    }
                    188:                        
                    189:                break;
                    190: 
                    191:            case NUMBER:
                    192:                fprintf( stderr, "%d", yylval );
                    193:                break;
                    194: 
                    195:            case PREVCCL:
                    196:                fprintf( stderr, "[%d]", yylval );
                    197:                break;
                    198: 
                    199:            case EOF_OP:
                    200:                fprintf( stderr, "<<EOF>>" );
                    201:                break;
                    202: 
                    203:            case 0:
                    204:                fprintf( stderr, "End Marker" );
                    205:                break;
                    206: 
                    207:            default:
                    208:                fprintf( stderr, "*Something Weird* - tok: %d val: %d\n",
                    209:                         toktype, yylval );
                    210:                break;
                    211:            }
                    212:        }
                    213:            
                    214:     return ( toktype );
                    215:     }

unix.superglobalmegacorp.com

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