title: flex and bison: g++ compiling error
body: <p>I'm trying to compile scanner and parser for the toy language using g++. Here is the code for every file which I use (if you want, I can post it to <code>pastebin</code> or anywhere else).</p>
  
  <p><code>caesar.ll</code></p>
  
  <pre><code>/* Simple scanner for a Caesar language */
  %{
  #include "caesar.tab.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  int chars = 0;
  int words = 0;
  int lines = 0;
  %}
  
  /* Define constants */
  OWS            [" "\t]*
  COMMA          {OWS}","{OWS}
  ID             [A-Za-z_][A-Za-z0-9_]*
  INT            ([0-9]+)|("0x"[A-Ha-h0-9]+)
  FLOAT          [0-9]+"."[0-9]+
  BSTREAM        b[\'\"].*[\'\"]
  USTREAM        u?[\'\"].*[\'\"]
  ARRAY          {LBRACE}({INT}|{FLOAT})({COMMA}({INT}|{FLOAT})){RBRACE}
  LIST           {LBRACKET}.*({COMMA}.*){RBRACKET}
  RANGE          {LBRACE}{INT}":"{INT}(":"{INT})?{RBRACE}
  ARGS           {ID}({COMMA}{ID})*
  LPARENTHESIS   "("{OWS}
  RPARENTHESIS   {OWS}")"
  LBRACE         "{"{OWS}
  RBRACE         {OWS}"}"
  LBRACKET       "["{OWS}
  RBRACKET       {OWS}"]"
  
  %%
  %{
  /*============================================================================*/
  /* Define types */
  /*============================================================================*/
  %}
  {INT} {
    cout &lt;&lt; "int: " &lt;&lt; yytext &lt;&lt; endl;
    yylval = atoi(yytext);
    return INT;
  } /* int type */
  
  {FLOAT} {
    cout &lt;&lt; "float: " &lt;&lt; yytext &lt;&lt; endl;
    yylval = atof(yytext);
    return FLOAT;
  } /* float type */
  
  {BSTREAM} {
    cout &lt;&lt; "bstream: " &lt;&lt; yytext &lt;&lt; endl;
    return BSTREAM;
  } /* bstream type */
  
  {USTREAM} {
    cout &lt;&lt; "ustream: " &lt;&lt; yytext &lt;&lt; endl;
    return USTREAM;
  } /* ustream type */
  
  %{
  /*============================================================================*/
  /* Define operators */
  /*============================================================================*/
  %}
  "+"    { return ADD; }
  "-"    { return SUB; }
  "*"    { return MUL; }
  "/"    { return DIV; }
  "//"   { return FDIV; }
  "|"    { return ABS; }
  "\n"   { return EOL; }
  
  %{
  /*============================================================================*/
  /* Define statements */
  /*============================================================================*/
  %}
  {RANGE} {
    cout &lt;&lt; "range: " &lt;&lt; yytext &lt;&lt; endl;
    return RANGE;
  } /* range function */
  
  %%
  </code></pre>
  
  <p><code>caesar.yy</code></p>
  
  <pre><code>/* Simple parser for a Caesar language */
  %{
  #include &lt;iostream&gt;
  using namespace std;
  %}
  
  /* Define built-in types */
  %token INT FLOAT BSTREAM USTREAM 
  %token ADD SUB MUL DIV FDIV ABS
  %token EOL
  
  %%
  
  calclist: /* nothing */
    | calclist exp EOL {
        cout &lt;&lt; $2 &lt;&lt; endl;
      }
    | calclist EOL {
        cout &lt;&lt; "&gt;&gt;&gt; ";
      }
    ;
  
  exp: factor
    | exp ADD exp { $$ = $1 + $3; }
    | exp SUB factor { $$ = $1 - $3; }
    | exp ABS factor { $$ = $1 | $3; }
    ;
  
  factor: term
    | factor MUL term { $$ = $1 * $3; }
    | factor DIV term { $$ = $1 / $3; }
    ;
  
  term: INT
    | ABS term { $$ = $2 &gt;= 0? $2 : - $2; }
    ;
  
  %%
  
  main()
  {
    cout &lt;&lt; "&gt;&gt;&gt; ";
    yyparse();
  }
  
  yyerror(char *error)
  {
    cerr &lt;&lt; error;
  }
  </code></pre>
  
  <p><code>Makefile</code></p>
  
  <pre><code>caesar: caesar.ll caesar.yy
      bison -d caesar.yy
      flex caesar.ll
      g++ -o $@ caesar.tab.cc lex.yy.c -lfl
  </code></pre>
  
  <p>When I try to compile it using <code>make</code>, I see couple of errors:</p>
  
  <pre><code>bison -d caesar.yy
  caesar.yy: conflicts: 3 shift/reduce
  flex caesar.ll
  g++ -o caesar caesar.tab.cc lex.yy.c -lfl
  caesar.tab.cc: In function 'int yyparse()':
  caesar.tab.cc:1281:16: error: 'yylex' was not declared in this scope
  caesar.tab.cc:1470:35: error: 'yyerror' was not declared in this scope
  caesar.tab.cc:1612:35: error: 'yyerror' was not declared in this scope
  caesar.yy: At global scope:
  caesar.yy:46:20: error: ISO C++ forbids declaration of 'yyerror' with no type [-fpermissive]
  caesar.ll:3:24: fatal error: caesar.tab.h: No such file or directory
  compilation terminated.
  make: *** [caesar] Error 1
  </code></pre>
  
  <p>Could you help me, please? Thanks!</p>
  
  <p><strong>UPDATE</strong>: I've already fixed error with incorrect function type.</p>