title: Using only string with Flex/Bison
body: <p>I am new in Flex/Bison. I want to use only strings for values (is a language translator). I have this for test:</p>
  
  <p><strong>example.l:</strong></p>
  
  <pre><code>%option noyywrap nodefault
  
  %{
  #include &lt;string.h&gt;
  #include "example.tab.h"
  %}
  
  %%
  
  [ \t\n] {;}
  "&lt;="    {return LEFT;}
  "=&gt;"    {return RIGHT;}
  [0-9]+ { yylval=strdup(yytext); return NUMBER; }
  . { return yytext[0]; }
  
  %%
  </code></pre>
  
  <p><strong>example.y:</strong></p>
  
  <pre><code>%{
  #include &lt;stdio.h&gt;
  #define YYSTYPE char const *
  %}
  
  %token NUMBER
  %token LEFT "&lt;=" RIGHT "=&gt;"
  
  %%
  
  start: %empty | start tokens
  
  tokens:
         NUMBER "&lt;=" NUMBER { printf("%s &lt;= %s\n",$1,$3); }
       | NUMBER "=&gt;" NUMBER { printf("%s =&gt; %s\n",$1,$3); }
       | NUMBER '&gt;' NUMBER  { printf("%s &gt; %s\n",$1,$3); }
       | NUMBER '&lt;' NUMBER  { printf("%s &lt; %s\n",$1,$3); }
  
  %%
  
  main(int argc, char **argv) { yyparse(); }
  yyerror(char *s) { fprintf(stderr, "error: %s\n", s); }
  </code></pre>
  
  <p>When I compiled:</p>
  
  <pre><code>bison -d example.y
  flex example.l
  cc -o example example.tab.c lex.yy.c -lfl
  example.l: In function ‘yylex’:
  example.l:13:9: warning: assignment makes integer from pointer without a cast
   [0-9]+ { yylval=strdup(yytext); return NUMBER; }
           ^
  </code></pre>
  
  <p>But work as awaited.</p>
  
  <p>If I don't use <code>#define YYSTYPE char const *</code> and use instead the %union:</p>
  
  <pre><code>%union {
     char * txt;
  }
  
  %token &lt;txt&gt; NUMBER
  </code></pre>
  
  <p>And change the assignation to <code>[0-9]+ { yylval.txt=strdup(yytext); return NUMBER; }</code>, it has no warning and works.</p>
  
  <p>I tried thing like define the same YYSTYPE in flex file and cast the assignation without success. What is wrong? How to fix without using %union?</p>
  
  <p>Thanks.</p>