X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/b9035928d16d032db1882d54ecb481352bd56047..09d517aa84f99c3686803d156cde10fc0c02bdc2:/src/scan.l diff --git a/src/scan.l b/src/scan.l index 8a6572e..2b92846 100644 --- a/src/scan.l +++ b/src/scan.l @@ -19,6 +19,9 @@ #include #include "parse.h" + +#define YY_NO_INPUT 1 +#define YY_NO_UNPUT 1 } %option nodefault noyywrap bison-locations reentrant never-interactive @@ -45,16 +48,6 @@ #define STRTOUMAX strtoul #endif -#define dup_token() do { \ - yylval->strval = malloc(yyleng+1); \ - if (!yylval->strval) { \ - cdecl__errmsg(CDECL__ENOMEM); \ - return T_LEX_ERROR; \ - } \ - memcpy(yylval->strval, yytext, yyleng); \ - yylval->strval[yyleng] = 0; \ -} while(0) - static char *to_octal(char *dst, unsigned val) { unsigned i; @@ -164,9 +157,10 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+ } {IDENT} { - unsigned x = cdecl__to_keyword(yytext, yyleng, yyextra); - int tok; + int len = yyleng, tok; + unsigned x; + x = cdecl__to_keyword(yytext, len, yyextra); yylval->spectype = UNPACK_SPEC(x & 0xff); if ((tok = (x >> 8)) == PACK_TOKEN(T_IDENT)) { /* @@ -180,12 +174,14 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+ * downsides. */ #if 1 - if ((c = strchr(yytext, '-'))) + if ((c = memchr(yytext, '-', len))) goto invalid_char; #else yyless(strcspn(yytext, "-")); #endif - dup_token(); + if (!(yylval->item = cdecl__alloc_item(len+1))) + return T_LEX_ERROR; \ + memcpy(yylval->item->s, yytext, len+1); } return UNPACK_TOKEN(tok); }