X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/ec4bdd2e748b84924b0b6bae6c37ff6f0ec8cc6c..5fc35dc076078b9710d86b47c53f4315edd3cd82:/src/scan.l diff --git a/src/scan.l b/src/scan.l index 7e3e365..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; @@ -124,37 +117,26 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+ %{ char *c; - - if (yyextra > 0) { - yyextra = -yyextra; - return T_ENGLISH; - } %} "..."|[][;*(),] { + unsigned char *match; static const unsigned char tab[2][8] = { "*[](),.;", { - T_ASTERISK & 0xff, - T_LBRACKET & 0xff, - T_RBRACKET & 0xff, - T_LPAREN & 0xff, - T_RPAREN & 0xff, - T_COMMA & 0xff, - T_ELLIPSIS & 0xff, - T_SEMICOLON & 0xff + PACK_TOKEN(T_ASTERISK), + PACK_TOKEN(T_LBRACKET), + PACK_TOKEN(T_RBRACKET), + PACK_TOKEN(T_LPAREN), + PACK_TOKEN(T_RPAREN), + PACK_TOKEN(T_COMMA), + PACK_TOKEN(T_ELLIPSIS), + PACK_TOKEN(T_SEMICOLON) } }; - unsigned char *match; - int x; - match = memchr(&tab, yytext[0], sizeof tab[0]); - x = match[sizeof tab[0]]; - - if (T_VOID >= 256) - x += 256; - return x; + return UNPACK_TOKEN(match[sizeof tab[0]]); } {INTEGER} { @@ -175,8 +157,12 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+ } {IDENT} { - int ret = cdecl__to_keyword(yytext, yyleng, yyextra); - if (ret == T_IDENT) { + 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)) { /* * Our IDENT pattern includes hyphens so we can match * "variable-length" as a keyword. In all other cases a @@ -188,14 +174,16 @@ 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 ret; + return UNPACK_TOKEN(tok); } [[:space:]]+