title: token redefinition? flex & bison
body: <p>So I am new to flex &amp; bison, and I am trying to build a simple C-like lexical &amp; syntactical analyzer, but I am getting these errors and I can't really make heads or tails from it.
  The errors generated from the auto generated files indicate that there is a token redefinition in y.tab.c &amp; lex.yy.c</p>
  
  <p>Here are the files:
  test.l</p>
  
  <pre><code>%{
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include "y.tab.h"
  
  int yylex();
  void yyerror(const char *s);
  
  %}
  
  %%
  "program"                      { return PROGRAM ; } 
  "function"                     { return FUNCTION ; }
  "integer"                      { return INTEGER ; }
  "boolean"                      { return BOOLEAN ; }
  "if"                           { return IF ; }
  "else"                         { return ELSE ; }
  "end"                          { return END ; }
  "or"                           { return OR ; }
  "and"                          { return AND ; }
  "div"                          { return DIV ; }
  "mod"                          { return MOD ; }
  "not"                          { return NOT ; }
  "("                            { return LPARENTHESIS ; }
  ")"                            { return RPARENTHESIS ; }
  ";"                            { return SEMI ; }
  ","                            { return COMA ; }
  "&lt;="                           { return LESSEQ ; }
  "&gt;="                           { return GREATEREQ ; }
  "+"                            { return PLUS ; }
  "-"                            { return MINUS ; }
  "*"                            { return MUL ; }
  "="                            { return EQUAL ; }
  "!&gt;"                           { return NEQUAL ; }
  "&lt;"                            { return LESS ; }
  "&gt;"                            { return GREATER ; }
  ":="                           { return ASSIGN ; }
  "true"                         { return TRUE ; }
  "false"                        { return FALSE ; }
  "{"                            { return LCURLYBRAKET ; }
  "}"                            { return RCURLYBRAKET ; }
  "void"                         { return VOID; }
  %%
  
  int main(int argc, char* argv) 
  {
      int token;
      while ((token = yylex()) != 0) 
      {
          printf("Token: %d\n", token);
      }
      return 0;
  }
  
  
  void yyerror(const char *s) 
  {
      printf("yyerror has: %s", s);
  }
  </code></pre>
  
  <p>test2.y</p>
  
  <pre><code>%token PROGRAM
  
  %token FUNCTION
  
  %token EXTERN
  
  %token LPARENTHESIS
  %token RPARENTHESIS
  %token LCURLYBRAKET
  %token RCURLYBRAKET
  %token SEMI
  %token COMA
  
  %token VOID
  %token INTEGER
  %token BOOLEAN
  %token STRING
  %token INTCONST
  %token CHARCONST
  
  %token BEGIN
  %token END
  
  %token IF
  %token ELSE
  
  
  %token RETURN
  %token TRUE
  %token FALSE
  
  %token ID
  
  %right ASSIGN
  %left OR AND
  %left EQUAL NEQUAL
  %left GREATER GREATEREQ LESS LESSEQ
  %left NOT
  %left MINUS PLUS
  %left DIV MOD MUL
  
  //%start program
  
  %%
  
  program    : ext_decl head def com;
  ext_decl   : | ext_proto ext_decl;
  ext_proto  : EXTERN func_proto;
  head       : VOID ID LPARENTHESIS RPARENTHESIS;
  def        : | definition def;
  definition : def_var | def_func | func_proto;
  def_var    : data_type var_list;
  data_type  : INTEGER | BOOLEAN | STRING;
  var_list   : ID dummy_ex;
  dummy_ex   : | COMA ID dummy_ex; 
  def_func   : head_func def com;
  func_proto : head_func SEMI;
  head_func  : func_type ID LPARENTHESIS dummy RPARENTHESIS;
  dummy      : | std_par_list;
  func_type  : INTEGER | BOOLEAN | VOID;
  std_par_list : typical_par dummy_par;
  dummy_par    : | COMA typical_par dummy_par;
  typical_par  : data_type dummy_amb ID;
  dummy_amb    : | AND;
  com       : BEGIN dummy_com END;
  dummy_com : | command dummy_com;
  command   : simple_com COMA | structured_com | complex_com;
  complex_com : LCURLYBRAKET dummy_com RCURLYBRAKET;
  structured_com : if_com;
  simple_com : assign | func_call | return_com | null_com; 
  if_com : IF LPARENTHESIS gen_ex RPARENTHESIS command dummy_else;
  dummy_else  : | else_clause;
  else_clause : ELSE command;
  assign    : ID ASSIGN gen_ex;
  
  func_call : ID LPARENTHESIS dummy_true_par RPARENTHESIS;
  dummy_true_par : | gen_ex COMA gen_ex dummy_true_par;
  
  return_com : RETURN dummy_ret;
  dummy_ret  : | gen_ex;
  null_com   : ;
  gen_ex     : gen_term dummy_term;
  dummy_term : | OR OR gen_term dummy_term;
  gen_term   : gen_factor dummy_factor;
  dummy_factor : | AND AND gen_factor dummy_factor;
  gen_factor   : dummy_not gen_first_factor;
  dummy_not  : | NOT;
  gen_first_factor : simple_ex dummy_compare;
  dummy_compare : | compare_sect;
  compare_sect  : comp_op simple_ex;
  comp_op   : EQUAL | NEQUAL | LESS | GREATER | LESSEQ | GREATEREQ;
  simple_ex : simple_term dummy_s;
  dummy_s   : | choice simple_term dummy_s;
  choice : PLUS | MINUS;
  simple_term : simple_factor dummy_t;
  dummy_t   : | choice2 simple_factor dummy_t;
  choice2   : MUL | DIV | MOD;
  simple_factor : choice simple_first_term;
  simple_first_term : ID | const | func_call | LPARENTHESIS gen_ex RPARENTHESIS;
  const : INTCONST | CHARCONST | TRUE | FALSE;
  
  %%
  </code></pre>
  
  <p>and here is the script I use to run them.
  make</p>
  
  <pre><code>flex test.l
  bison -y -d test2.y 
  gcc y.tab.c lex.yy.c
  </code></pre>
  
  <p>&amp; here are the errors:</p>
  
  <p><a href="https://i.stack.imgur.com/Slbyl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Slbyl.png" alt="enter image description here"></a></p>
  
  <p>P.S.
  I know there are some conflicts, but I don't really think they have somethink to do with the errors I am getting so far. Correct me if I am wrong.</p>
  
  <p>Thanks for your time.</p>