[BACK]Return to tokenizer.l CVS log [TXT][DIR] Up to [local] / src / usr.bin / m4

Annotation of src/usr.bin/m4/tokenizer.l, Revision 1.2

1.1       espie       1: %{
1.2     ! espie       2: /* $OpenBSD: tokenizer.l,v 1.1 2004/05/12 21:17:03 espie Exp $ */
1.1       espie       3: /*
                      4:  * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18: #include "parser.h"
                     19: #include <stdlib.h>
                     20: #include <errno.h>
                     21: #include <sys/types.h>
                     22: #include <limits.h>
1.2     ! espie      23:
1.1       espie      24: extern int32_t yylval;
                     25:
                     26: int32_t number(void);
                     27: %}
                     28:
                     29: delim  [ \t\n]
                     30: ws     {delim}+
                     31: hex    0[xX][0-9a-fA-F]+
                     32: oct    0[0-7]*
                     33: dec    [1-9][0-9]*
                     34:
                     35: %%
1.2     ! espie      36: {ws}                   {/* just skip it */}
        !            37: {hex}|{oct}|{dec}      { yylval = number(); return(NUMBER); }
        !            38: "<="                   { return(LE); }
        !            39: ">="                   { return(GE); }
        !            40: "<<"                   { return(LSHIFT); }
        !            41: ">>"                   { return(RSHIFT); }
        !            42: "=="                   { return(EQ); }
        !            43: "!="                   { return(NE); }
        !            44: "&&"                   { return(LAND); }
        !            45: "||"                   { return(LOR); }
        !            46: .                      { return yytext[0]; }
1.1       espie      47: %%
                     48:
                     49: int32_t
                     50: number()
                     51: {
                     52:        long l;
                     53:
                     54:        errno = 0;
                     55:        l = strtol(yytext, NULL, 0);
                     56:        if (((l == LONG_MAX || l == LONG_MIN) && errno == ERANGE) ||
                     57:            l > 0x7fffffff || l < (-0x7fffffff - 1)) {
                     58:                fprintf(stderr, "m4: numeric overflow in expr: %s\n", yytext);
                     59:        }
                     60:        return l;
                     61:
                     62: }