title: Errors in making a re-entrant parser
body: <p>I have tried a lot, but could not figure out what the errors are.
  Any detailed explanation about the this will be very helpful.</p>
  
  <p>So basically i am trying to write a re-entrant parser and these are my files.</p>
  
  <p>Lex1.ll</p>
  
  <pre><code>%{
  #include "Globals.h"
  #include "yac1.tab.hh"
  
      extern "C"
      {
          int yylex(void);
      }
  
  
  %}
  alpha [A-Za-z]
  digit [0-9]
  %option case-insensitive
  %option bison-bridge
  %option reentrant
  %option noyywrap
  %%
  
  
  "DELETE ALL" return DELALL;
  
  "INSERT"       return INSERT;
  
  
  DELETE       return DELETE;
  FIND         return FIND;
  
  (\+|\-)?[0-9]+         { return INT;    }
  
  \n             { return ENDL; }
  .    ;
  %%
  </code></pre>
  
  <p>yac1.yy</p>
  
  <pre><code>%{
  #include &lt;stdio.h&gt;
  #include "Globals.h"
  %}
  %pure-parser
  %error-verbose
  
  %{
  
  #define YYPARSE_PARAM parm
  #define YYLEX_PARAM ((struct parsed_vals *)parm)-&gt;scanner
  #define cast ((struct parsed_vals *) parm)
  
  void yyerror(struct parsed_vals * parm,const char *s)
  {
      fprintf(stderr, "error: %s\n", s);
  }
  extern "C"
  {
          int yylex(void );  
  
        //  int yywrap()
        //  {
        //          return 1;
        //  }
  }
  %}
  
  %token INSERT DELETE DELALL FIND ENDL
  %union {
      int ival;
      float fval;
      char *sval;
  }
  
  %token &lt;ival&gt; INT
  %token &lt;fval&gt; FLOAT
  %token &lt;sval&gt; STRING
  %%
  
  S:T    
  
  T:      INSERT val  {cast-&gt;cmd=INSERT_CMD;}
        | DELETE val  {cast-&gt;cmd=DELETE_CMD;}
  
  ;
  
  val :   INT ENDL    {cast-&gt;type=INT_TYPE;
                  (cast-&gt;data).int_data=$1;}   
        |
          FLOAT ENDL  {cast-&gt;type=FLOAT_TYPE;
              (cast-&gt;data).float_data=$1;}  
        |
          STRING ENDL {cast-&gt;type=STRING_TYPE;
              (cast-&gt;data).str_data=$1;}       
  ;
  
  %%
  </code></pre>
  
  <p>My main function testlex.cc</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "Globals.h"
  #include "lexheader.h"
  #include "yac1.tab.hh"
  
  int yyparse(void *);
  yyscan_t scanner;
  main()
  {
  
  struct parsed_vals foo;
  const char * buffer = "inseRt 4\n";
  yylex_init(&amp;(foo.scanner));
  yyset_extra(&amp;foo, foo.scanner);
  YY_BUFFER_STATE bp = yy_scan_string( buffer, foo.scanner ); 
  yy_switch_to_buffer(bp, foo.scanner);
  int a; 
  int ret_val = yyparse(&amp;foo); 
  yy_delete_buffer(bp, foo.scanner);  
  if(ret_val!=0) printf("False");
  printf ("hello %d\n",foo.data.int_data);
  printf ("hello %d\n",foo.type);
  yylex_destroy(foo.scanner);
  
  }
  </code></pre>
  
  <p>Globals.h</p>
  
  <pre><code>/* 
   * File:   Globals.h
   * Author: atghosh
   *
   * Created on 3 August, 2013, 8:39 PM
   */
  
  #ifndef GLOBALS_H
  #define GLOBALS_H
  
  enum CMD {INSERT_CMD=1, DELETE_CMD, FIND_CMD, DELALL_CMD};
  enum TYPE {INT_TYPE=5, FLOAT_TYPE, STRING_TYPE};
  
  struct parsed_vals{
      int cmd;
      int type;
      union{      
          int int_data;
          float float_data;
          char *str_data;
      } data;
      void * scanner;
  };
  #endif  /* GLOBALS_H */
  </code></pre>
  
  <p>Makefile</p>
  
  <pre><code>parser: lex1.ll yac1.yy testlex.cc
      bison -d yac1.yy
      flex --header-file="lexheader.h" lex1.ll
      g++ -o parser yac1.tab.cc lex.yy.c testlex.cc -lfl
  
  clean:
      rm -rf *.o parser lexheader.h  lex.yy.c  lex.yy.cc  parser   yac1.tab.cc  yac1.tab.hh 
  </code></pre>
  
  <p>And my error list</p>
  
  <pre><code>bison -d yac1.yy
  flex --header-file="lexheader.h" lex1.ll
  g++ -o parser yac1.tab.cc lex.yy.c testlex.cc -lfl
  yac1.tab.cc: In function ‘int yyparse(void*)’:
  yac1.tab.cc:1302:16: error: too many arguments to function ‘int yylex()’
  yac1.yy:20:13: note: declared here
  yac1.tab.cc:1510:24: error: cannot convert ‘const char*’ to ‘parsed_vals*’ for argument ‘1’ to ‘void yyerror(parsed_vals*, const char*)’
  yac1.tab.cc:1625:35: error: cannot convert ‘const char*’ to ‘parsed_vals*’ for argument ‘1’ to ‘void yyerror(parsed_vals*, const char*)’
  In file included from testlex.cc:3:0:
  lexheader.h:278:1: error: ‘YYSTYPE’ does not name a type
  lexheader.h:280:18: error: variable or field ‘yyset_lval’ declared void
  lexheader.h:280:18: error: ‘YYSTYPE’ was not declared in this scope
  lexheader.h:280:28: error: ‘yylval_param’ was not declared in this scope
  lexheader.h:280:51: error: expected primary-expression before ‘yyscanner’
  lexheader.h:328:17: warning: ‘yylex’ initialized and declared ‘extern’ [enabled by default]
  lexheader.h:328:17: error: ‘YYSTYPE’ was not declared in this scope
  lexheader.h:328:27: error: ‘yylval_param’ was not declared in this scope
  lexheader.h:328:50: error: expected primary-expression before ‘yyscanner’
  lexheader.h:328:59: error: expression list treated as compound expression in initializer [-fpermissive]
  make: *** [parser] Error 1
  </code></pre>
  
  <p>I am just not able to figure out what is going wrong.</p>
  
  <p>Expecting detailed reply and no links.</p>
  
  <p>I have already referred to these links</p>
  
  <p><a href="http://plindenbaum.blogspot.in/2009/12/parsing-genetic-code-using-flex-and_14.html" rel="nofollow">http://www.phpcompiler.org/articles/reentrantparser.html</a></p>
  
  <p><a href="http://plindenbaum.blogspot.in/2009/12/parsing-genetic-code-using-flex-and_14.html" rel="nofollow">http://plindenbaum.blogspot.in/2009/12/parsing-genetic-code-using-flex-and_14.html</a></p>