2 /* $NetBSD: tokenizer.l,v 1.4 2009/10/29 14:49:03 christos Exp $ */
3 /* $OpenBSD: tokenizer.l,v 1.6 2008/08/21 21:00:14 espie Exp $ */
5 * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #if HAVE_NBTOOL_CONFIG_H
20 #include "nbtool_config.h"
23 __RCSID("$NetBSD: tokenizer.l,v 1.4 2009/10/29 14:49:03 christos Exp $");
30 extern int32_t yylval;
31 extern int yylex(void);
32 extern int yywrap(void);
35 int32_t parse_radix(void);
46 radix 0[rR][0-9]+:[0-9a-zA-Z]+
49 {ws} {/* just skip it */}
50 {hex}|{oct}|{dec} { yylval = number(); return(NUMBER); }
51 {radix} { if (mimic_gnu) {
52 yylval = parse_radix(); return(NUMBER);
59 "<<" { return(LSHIFT); }
60 ">>" { return(RSHIFT); }
63 "&&" { return(LAND); }
65 . { return yytext[0]; }
74 l = strtol(yytext, NULL, 0);
75 if (((l == LONG_MAX || l == LONG_MIN) && errno == ERANGE) ||
76 l > INT32_MAX || l < INT32_MIN) {
77 fprintf(stderr, "m4: numeric overflow in expr: %s\n", yytext);
90 base = strtol(yytext+2, &next, 0);
91 if (base > 36 || next == NULL) {
92 fprintf(stderr, "m4: error in number %s\n", yytext);
96 if (*next >= '0' && *next <= '9')
97 l = base * l + *next - '0';
98 else if (*next >= 'a' && *next <= 'z')
99 l = base * l + *next - 'a' + 10;
100 else if (*next >= 'A' && *next <= 'Z')
101 l = base * l + *next - 'A' + 10;