]> git.draconx.ca Git - cdecl99.git/blobdiff - src/scan.l
libcdecl: Fix scanning of hexadecimal constants.
[cdecl99.git] / src / scan.l
index 67183815da48e97642536c72e7dd131e050bf744..fbe80b2fddae12cc5076a9a0e108497d0b28d7ff 100644 (file)
@@ -19,6 +19,9 @@
 
 #include <config.h>
 #include "parse.h"
+
+#define YY_NO_INPUT 1
+#define YY_NO_UNPUT 1
 }
 
 %option nodefault noyywrap bison-locations reentrant never-interactive
 #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;
@@ -118,17 +111,12 @@ static void to_readable_ch(char *dst, char c)
 %}
 
 IDENT [_[:alpha:]][-_[:alnum:]]*
-INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
+INTEGER 0[Xx][[:xdigit:]]*|[[:digit:]]+
 
 %%
 
 %{
        char *c;
-
-       if (yyextra > 0) {
-               yyextra = -yyextra;
-               return T_ENGLISH;
-       }
 %}
 
 "..."|[][;*(),] {
@@ -169,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
@@ -182,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:]]+