Annotation of src/usr.bin/m4/tokenizer.l, Revision 1.1
1.1 ! espie 1: %{
! 2: /* $OpenBSD$ */
! 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>
! 23: extern int32_t yylval;
! 24:
! 25: int32_t number(void);
! 26: %}
! 27:
! 28: delim [ \t\n]
! 29: ws {delim}+
! 30: hex 0[xX][0-9a-fA-F]+
! 31: oct 0[0-7]*
! 32: dec [1-9][0-9]*
! 33:
! 34: %%
! 35: {ws} {/* just skip it */}
! 36: {hex} { yylval = number(); return(NUMBER); }
! 37: {oct} { yylval = number(); return(NUMBER); }
! 38: {dec} { yylval = number(); return(NUMBER); }
! 39: "<=" { return(LE); }
! 40: ">=" { return(GE); }
! 41: "<<" { return(LSHIFT); }
! 42: ">>" { return(RSHIFT); }
! 43: "==" { return(EQ); }
! 44: "!=" { return(NE); }
! 45: "&&" { return(LAND); }
! 46: "||" { return(LOR); }
! 47: . { return yytext[0]; }
! 48: %%
! 49:
! 50: int32_t
! 51: number()
! 52: {
! 53: long l;
! 54:
! 55: errno = 0;
! 56: l = strtol(yytext, NULL, 0);
! 57: if (((l == LONG_MAX || l == LONG_MIN) && errno == ERANGE) ||
! 58: l > 0x7fffffff || l < (-0x7fffffff - 1)) {
! 59: fprintf(stderr, "m4: numeric overflow in expr: %s\n", yytext);
! 60: }
! 61: return l;
! 62:
! 63: }
! 64: