title: YACC: How to pass the string value of a token to the yacc program
body: <p>I want to design a program using lex and yacc that will take input in Morse code form and the parser would generate their English meaning.</p>
  
  <p>This is the lex file:</p>
  
  <pre><code>%{
  #include &lt;stdio.h&gt;
  int i=0;
  char c;
  %}
  NewLine ".-.-"
  EOF ".-.-"
  NewPara "-...-"
  Over "K"
  SOS "...---..."
  %%
  ".." {  yylval=(char *)calloc(yyleng,sizeof(char));
  strcpy(yylval,yytext); 
  return (I);}
  
  ".-""--" { yylval=(char *)calloc(yyleng,sizeof(char));
     strcpy(yylval,yytext); 
     return (AM);}
  
  ".-""...-"".-""-."".." {yylval.value=(char *)calloc(yyleng,sizeof(char));
          strcpy(yylval,yytext); 
          return (AVANI);}
  
  . return yytext[0];
  %%
  </code></pre>
  
  <p>The yacc file:</p>
  
  <pre><code>%{
  #include &lt;stdio.h&gt;
  #define YYSTYPE char*
  char message [20];
  %}
  %token I AM AVANI
  %start msg
  %%
  msg :   Np Vp {printf("The sentence is I AM AVANI");}
  ;
  Np  :   I 
  ;
  Vp  :   Aux N
  ;
  Aux :   AM  
  ;
  N   :   AVANI 
  ;
  %%
  #include "lex.yy.c"
  /*extern YYSTYPE yylval*/
  void main(){
  printf("Enter the message\n");
  scanf("%s",message);
  yyparse();
  }
  void yyerror(const char *s)
  {
  fprintf(stderr,"s\n",s);
  }        
  yywrap () 
  {        
  return 1;
  }     
  </code></pre>
  
  <p>This shows the following error on Compiling:</p>
  
  <pre><code>morse_code.l: In function ‘yylex’:
  morse_code.l:13:10: warning: assignment makes integer from pointer
  without a cast [enabled by default]
   ".." {  yylval=(char *)calloc(yyleng,sizeof(char));
            ^
  morse_code.l:14:2: warning: passing argument 1 of ‘strcpy’ makes
  pointer from integer without a cast [enabled by default]
    strcpy(yylval,yytext);
    ^
  In file included from lex.yy.c:20:0:
  /usr/include/string.h:125:14: note: expected ‘char * __restrict__’ but
  argument is of type ‘YYSTYPE’
   extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
                ^
  morse_code.l:17:9: warning: assignment makes integer from pointer
  without a cast [enabled by default]
   ".-""--" { yylval=(char *)calloc(yyleng,sizeof(char));
           ^
  morse_code.l:18:5: warning: passing argument 1 of ‘strcpy’ makes
  pointer from integer without a cast [enabled by default]
       strcpy(yylval,yytext);
       ^
  In file included from lex.yy.c:20:0:
  /usr/include/string.h:125:14: note: expected ‘char * __restrict__’ but
  argument is of type ‘YYSTYPE’
   extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
                ^
  morse_code.l:21:8: error: request for member ‘value’ in something not
  a structure or union
   ".-""...-"".-""-."".." {yylval=(char *)calloc(yyleng,sizeof(char));
          ^
  morse_code.l:22:4: warning: passing argument 1 of ‘strcpy’ makes
  pointer from integer without a cast [enabled by default]
      strcpy(yylval,yytext);
      ^
  In file included from lex.yy.c:20:0: 
  /usr/include/string.h:125:14: note: expected ‘char * __restrict__’ but
  argument is of type ‘YYSTYPE’
   extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
  </code></pre>
  
  <p>It'll be great if someone could help me with the correct way to pass the string value of a token to the yacc file.</p>