1 From edf250c633bef40e7e37dafc9fc393dd2ad9074f Mon Sep 17 00:00:00 2001
2 From: Michael Forney <mforney@mforney.org>
3 Date: Tue, 10 Apr 2018 13:37:14 -0700
4 Subject: [PATCH] m4: Use hand-written lexer to avoid cycle in bootstrap
7 tokenizer.c | 191 +++++++++++++++++++++++++++++++++++++++++
8 tokenizer.l | 109 -----------------------
9 2 files changed, 191 insertions(+), 109 deletions(-)
10 create mode 100644 tokenizer.c
11 delete mode 100644 tokenizer.l
13 diff --git a/tokenizer.c b/tokenizer.c
15 index 00000000000..fa19fc65035
19 +/* $OpenBSD: tokenizer.l,v 1.10 2017/06/17 01:55:16 bcallah Exp $ */
21 + * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
23 + * Permission to use, copy, modify, and distribute this software for any
24 + * purpose with or without fee is hereby granted, provided that the above
25 + * copyright notice and this permission notice appear in all copies.
27 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
28 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
29 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
30 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
32 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
33 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
45 +extern void m4_warnx(const char *, ...);
46 +extern int mimic_gnu;
47 +extern int32_t yylval;
48 +static const char *yypos;
51 +yy_scan_string(const char *s)
57 +number(const char *yytext, size_t yylen)
62 + l = strtol(yytext, NULL, 0);
63 + if (((l == LONG_MAX || l == LONG_MIN) && errno == ERANGE) ||
64 + l > INT32_MAX || l < INT32_MIN)
65 + m4_warnx("numeric overflow in expr: %.*s", (int)yylen, yytext);
70 +parse_radix(const char *yytext, size_t yylen)
78 + base = strtol(yytext+2, &next, 0);
79 + if (base > 36 || next == NULL) {
80 + m4_warnx("error in number %.*s", (int)yylen, yytext);
83 + while (*next != 0) {
84 + if (*next >= '0' && *next <= '9')
86 + else if (*next >= 'a' && *next <= 'z')
87 + d = *next - 'a' + 10;
89 + assert(*next >= 'A' && *next <= 'Z');
90 + d = *next - 'A' + 10;
93 + m4_warnx("error in number %.*s", (int)yylen, yytext);
106 + return c >= '0' && c <= '7';
122 + switch (yypos[1]) {
132 + switch (yypos[1]) {
142 + if (yypos[1] != '=')
147 + if (yypos[1] != '=')
152 + if (yypos[1] != '&')
157 + if (yypos[1] != '|')
162 + if (!mimic_gnu || yypos[1] != '*')
167 + switch (*++yypos) {
170 + if (!isxdigit(*++yypos))
173 + while (isxdigit(*yypos));
179 + if (!isdigit(*++yypos))
182 + while (isdigit(*yypos));
185 + if (!isalnum(*++yypos))
188 + while (isalnum(*yypos));
189 + yylval = parse_radix(start, yypos - start);
193 + while (isodigit(*yypos));
196 + yylval = number(start, yypos - start);
201 + if (isdigit(*yypos)) {
203 + while (isdigit(*yypos));
204 + yylval = number(start, yypos - start);
210 diff --git a/tokenizer.l b/tokenizer.l
211 deleted file mode 100644
212 index 94f02fb6085..00000000000
217 -/* $OpenBSD: tokenizer.l,v 1.10 2017/06/17 01:55:16 bcallah Exp $ */
219 - * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
221 - * Permission to use, copy, modify, and distribute this software for any
222 - * purpose with or without fee is hereby granted, provided that the above
223 - * copyright notice and this permission notice appear in all copies.
225 - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
226 - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
227 - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
228 - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
229 - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
230 - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
231 - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
240 -extern void m4_warnx(const char *, ...);
241 -extern int mimic_gnu;
242 -extern int32_t yylval;
244 -int32_t number(void);
245 -int32_t parse_radix(void);
250 -hex 0[xX][0-9a-fA-F]+
253 -radix 0[rR][0-9]+:[0-9a-zA-Z]+
258 -{ws} {/* just skip it */}
259 -{hex}|{oct}|{dec} { yylval = number(); return(NUMBER); }
260 -{radix} { if (mimic_gnu) {
261 - yylval = parse_radix(); return(NUMBER);
266 -"<=" { return(LE); }
267 -">=" { return(GE); }
268 -"<<" { return(LSHIFT); }
269 -">>" { return(RSHIFT); }
270 -"==" { return(EQ); }
271 -"!=" { return(NE); }
272 -"&&" { return(LAND); }
273 -"||" { return(LOR); }
274 -"**" { if (mimic_gnu) { return (EXPONENT); } }
275 -. { return yytext[0]; }
284 - l = strtol(yytext, NULL, 0);
285 - if (((l == LONG_MAX || l == LONG_MIN) && errno == ERANGE) ||
286 - l > INT32_MAX || l < INT32_MIN)
287 - m4_warnx("numeric overflow in expr: %s", yytext);
300 - base = strtol(yytext+2, &next, 0);
301 - if (base > 36 || next == NULL) {
302 - m4_warnx("error in number %s", yytext);
305 - while (*next != 0) {
306 - if (*next >= '0' && *next <= '9')
308 - else if (*next >= 'a' && *next <= 'z')
309 - d = *next - 'a' + 10;
311 - assert(*next >= 'A' && *next <= 'Z');
312 - d = *next - 'A' + 10;
315 - m4_warnx("error in number %s", yytext);