]> git.draconx.ca Git - cdecl99.git/blobdiff - src/scan.l
libcdecl: Don't dynamically allocate null declarators.
[cdecl99.git] / src / scan.l
index 90f5ad9de3b88af33fc145f76181a4c9e32ef653..7549e6f7baee99cafb40a46d72f2211f10d511ce 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;
@@ -124,11 +117,6 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
 
 %{
        char *c;
-
-       if (yyextra > 0) {
-               yyextra = -yyextra;
-               return T_ENGLISH;
-       }
 %}
 
 "..."|[][;*(),] {
@@ -173,7 +161,7 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
        int tok;
 
        yylval->spectype = UNPACK_SPEC(x & 0xff);
-       if ((tok = (x >> 8)) == T_IDENT) {
+       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
@@ -190,7 +178,9 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+
 #else
                yyless(strcspn(yytext, "-"));
 #endif
-               dup_token();
+               if (!(yylval->item = cdecl__alloc_item(yyleng+1)))
+                       return T_LEX_ERROR; \
+               memcpy(yylval->item->s, yytext, yyleng+1);
        }
        return UNPACK_TOKEN(tok);
 }