[BACK]Return to yylex.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / lex

Annotation of src/usr.bin/lex/yylex.c, Revision 1.6

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