c - Returning "non-ints" from yylex -


I have a generator scanner from Flex, which is not used by yax or bison. Instead of giving Yylex () a token-type signal, a token-like structure gives an indicator on the memory.

Pre-Definition. Foo.l [a-za-z_] [AZA-0 -9 _] * {Return Scanner_token (T_IDIntIFER); } // Example execution of scanner_token token * scanner_token (name) {token * t = (token *) callok (1, size (token)); T- & gt; Name = name; T- & gt; Lexem = (four *) Coloc (Yileng + 1, 1); If (T-> lexam == faucet) {perror_exit ("calloc"); } Memmove (t-> gtx, yytext, yyleng); Return T; } // for example yylex token * t; T = (token *) yylex ();

Of course, the compilation warns me Returns an integer without indicating an artist.

I read in Flex man pages how YY_DECL declares the scanning routine:

YY_DECL < / Code> controls how the scanning routine is declared by default, " int yylex () " or, if prototype is being used, " int yylex (zero) ) ". This definition can change by redefining the " YY_DECL " macro.

When I try to redefine YY_DECL , the resulting file fails to compile.

  #undef YY_DECL #define YY_DECL (token *) yylex ()  

What am I trying to do, what is the right way to accomplish this is ?

Normal syntax will be:

  #define YY_DECL token * Yylex ( Zero)  

This minimum Flex source file shows that:

 % {typedef struct token {int tok; } Tokens; # Defined YY_DECL token * yylex (zero) token t; %} %% {T.tok = 1; Return & amp; T; } %%  

This is compiled for me.


Comments