title: Bison unexpected token causing syntax errors
body: <p>This compiler are forked from <a href="https://github.com/eubnara/flex-bison" rel="nofollow noreferrer">miniC compiler</a>. </p>
  
  <p>I'm building a converter to PDL and after add <code>FACTOR TERM MathEql MathRel</code> to fix shift reduce error, I have problems with the syntax.</p>
  
  <p>miniC.y</p>
  
  <pre><code>%{
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include "AST.h"
  #include "print.h"
  #include "lex.yy.h"
  #include "Converter.h"
  #include "symboltable.h"
  //global variables which can be used in other .c .h
  struct PROGRAM *head;
  FILE *fp;   //for AST
  FILE *fp2;  //for symboltable 
  void yyerror(char const*text){
  
      fprintf(stderr, "%s\n", text);
  }
  /*
  void lyyerror(YYLTYPE t, char *s, ...)
  {
      va_list ap;
      va_start(ap, s);
  
      if(t.first_line)
          fprintf(stderr, "%d.%d-%d.%d: error: ", t.first_line, t.first_column, t.last_line, t.last_column);
      vfprintf(stderr, s, ap);
      fprintf(stderr, "\n");
  }
  */
  %}
  
  
  %union{
      struct PROGRAM                      *ptr_program;
      struct DECLARATION                  *ptr_declaration;
      struct IDENTIFIER                   *ptr_identifier;
      struct FUNCTION                     *ptr_function;
      struct PARAMETER                    *ptr_parameter;
      struct COMPOUNDSTMT                 *ptr_compoundstmt;
      struct STMT                         *ptr_stmt;
      struct ASSIGN                       *ptr_assign;
      struct CALL                         *ptr_call;
      struct ARG                          *ptr_arg;
      struct WHILE_S                      *ptr_while_s;
      struct FOR_S                        *ptr_for_s;
      struct IF_S                         *ptr_if_s;
      struct ID_S                         *ptr_id_s;
      struct EXPR                         *ptr_expr;
      struct ADDIOP                       *ptr_addiop;
      struct MULTOP                       *ptr_multop;
      struct RELAOP                       *ptr_relaop;
      struct EQLTOP                       *ptr_eqltop;
      struct FACTOR                       *ptr_factor;
      struct TERM                         *ptr_term;
      struct MATHEQL                      *ptr_math_eql;
      struct MATHREL                      *ptr_math_rel;
      Type_e type;
      //TODO int, float to char*
      int intnum;
      float floatnum;
      char* id;
  }
  
  %token &lt;intnum&gt;INTNUM &lt;floatnum&gt;FLOATNUM &lt;id&gt;ID
  %token INT FLOAT MINUS PLUS MULT DIV LE GE EQ NE GT LT
  %token IF ELSE FOR WHILE DO RETURN DQUOT_T SQUOT_T AMP_T 
  
  %right ELSE then;
  
  %type &lt;type&gt; Type
  
  %define parse.error verbose
  
  %type &lt;ptr_program&gt; Program
  %type &lt;ptr_declaration&gt; Declaration DeclList
  %type &lt;ptr_identifier&gt; Identifier IdentList
  %type &lt;ptr_function&gt; Function FuncList
  %type &lt;ptr_parameter&gt; Parameter ParamList 
  %type &lt;ptr_compoundstmt&gt; CompoundStmt
  %type &lt;ptr_stmt&gt; Stmt StmtList
  %type &lt;ptr_assign&gt; Assign AssignStmt 
  %type &lt;ptr_call&gt; Call CallStmt
  %type &lt;ptr_arg&gt; Arg ArgList
  %type &lt;ptr_while_s&gt; While_s
  %type &lt;ptr_for_s&gt; For_s
  %type &lt;ptr_if_s&gt; If_s
  %type &lt;ptr_expr&gt; Expr RetStmt
  %type &lt;ptr_addiop&gt; Addiop
  %type &lt;ptr_multop&gt; Multop
  %type &lt;ptr_relaop&gt; Relaop
  %type &lt;ptr_eqltop&gt; Eqltop
  %type &lt;ptr_factor&gt; FACTOR
  %type &lt;ptr_term&gt; TERM
  %type &lt;ptr_id_s&gt; Id_s
  %type &lt;ptr_math_eql&gt; MathEql
  %type &lt;ptr_math_rel&gt; MathRel;
  
  %start Program
  %%
  //입력이 없는 경우는 main() 에서 head = NULL 인 상태로 처리됨.
  //"DeclList" in "Program" denotes global declaration
  Program: DeclList FuncList {
              struct PROGRAM *prog = (struct PROGRAM*) malloc (sizeof (struct PROGRAM));
              prog-&gt;decl = $1;
              prog-&gt;func = $2;
              head = prog;
              $$ = prog;
         }
         | DeclList {
              struct PROGRAM *prog = (struct PROGRAM*) malloc (sizeof (struct PROGRAM));
              prog-&gt;decl = $1;
              prog-&gt;func = NULL;
              head = prog;
              $$ = prog;
         }
         | FuncList {
              struct PROGRAM *prog = (struct PROGRAM*) malloc (sizeof (struct PROGRAM));
              prog-&gt;decl = NULL;
              prog-&gt;func = $1;
              head = prog;
              $$ = prog;
         }
         ;
  DeclList: Declaration {
              $$ = $1;
          }
          | DeclList Declaration {
              struct DECLARATION *decl;
              decl = $2;
              decl-&gt;prev = $1;
              $$ = decl;
          }
          ;
  FuncList: Function {
              $$ = $1;
          }
          | FuncList Function {
              struct FUNCTION *func;
              func = $2;
              func-&gt;prev = $1;
              $$ = func;
          }
          ;
  Declaration: Type IdentList ';' {
                  struct DECLARATION *decl = (struct DECLARATION*) malloc (sizeof (struct DECLARATION));
                  decl-&gt;t = $1;
                  decl-&gt;id = $2;
                  $$ = decl;
              }
             ;
  IdentList: Identifier {
              $$ = $1;
          }
          | IdentList ',' Identifier {
              struct IDENTIFIER *iden;
              iden = $3;
              iden-&gt;prev = $1;
              $$ = iden;
          }
          ;
  Identifier: ID {
              struct IDENTIFIER *iden = (struct IDENTIFIER*) malloc (sizeof (struct IDENTIFIER));
              iden-&gt;ID = $1;
              iden-&gt;intnum = 0;   // zero, If scalar
              iden-&gt;prev = NULL;
              $$ = iden;
            }
            | ID '[' INTNUM ']' {
              struct IDENTIFIER *iden = (struct IDENTIFIER*) malloc (sizeof (struct IDENTIFIER));
              iden-&gt;ID = $1;
              iden-&gt;intnum = $3;   // zero, If scalar
              iden-&gt;prev = NULL;
              $$ = iden;
             }
            ;
  ParamList: Parameter {
              struct PARAMETER *param;
              param = $1;
              param-&gt;prev = NULL;
              $$ = param;
          }
           | ParamList ',' Parameter {
              struct PARAMETER *param;
              param = $3;
              param-&gt;prev = $1;
              $$ = param;
          }
  Parameter: Type Identifier {
              struct PARAMETER *param = (struct PARAMETER*) malloc (sizeof (struct PARAMETER));
              param-&gt;t = $1;
              param-&gt;id = $2;
              param-&gt;prev = NULL;
              $$ = param;
          }
  Function: Type ID '(' ')' CompoundStmt {
              struct FUNCTION *func = (struct FUNCTION*) malloc (sizeof (struct FUNCTION));
              func-&gt;t = $1;
              func-&gt;ID = $2;
              func-&gt;param = NULL;
              func-&gt;cstmt = $5;
              $$ = func;
  
          }
          | Type ID '(' ParamList ')' CompoundStmt {
          struct FUNCTION *func = (struct FUNCTION*) malloc (sizeof (struct FUNCTION));
          func-&gt;t = $1;
          func-&gt;ID = $2;
          func-&gt;param = $4;
          func-&gt;cstmt = $6;
          $$ = func;
      }
      ;
  Type: INT { $$ = eInt;}
      | FLOAT { $$ = eFloat;}
      ;
  //cf. Stmt 안에 CompoundStmt 존재
  //StmtList 에서 empty 입력을 허용하지 않도록 StmtList 가 없는 Compound 정의
  CompoundStmt: '{' '}' {
                  struct COMPOUNDSTMT *comp = (struct COMPOUNDSTMT*) malloc (sizeof (struct COMPOUNDSTMT));
                  comp-&gt;decl = NULL;
                  comp-&gt;stmt = NULL;
                  $$ = comp;
                  /*
                  { } 안에 { } 만 들어 있는 경우도 표현하기 위하여,
                  NULL을 반환하지 않고 내용이 비어있어도 동적할당을 하였다.
                  */
  
              }
              | '{' StmtList '}'  {
                  struct COMPOUNDSTMT *comp = (struct COMPOUNDSTMT*) malloc (sizeof (struct COMPOUNDSTMT));
                  comp-&gt;decl = NULL;
                  comp-&gt;stmt = $2;
                  $$ = comp;
              }
              |  '{' DeclList StmtList '}' {
                  struct COMPOUNDSTMT *comp = (struct COMPOUNDSTMT*) malloc (sizeof (struct COMPOUNDSTMT));
                  comp-&gt;decl = $2;
                  comp-&gt;stmt = $3;
                  $$ = comp;
              }
              |  '{' DeclList '}' {
                  struct COMPOUNDSTMT *comp = (struct COMPOUNDSTMT*) malloc (sizeof (struct COMPOUNDSTMT));
                  comp-&gt;decl = $2;
                  comp-&gt;stmt = NULL;
                  $$ = comp;
              }
              ;
  StmtList: Stmt {
              struct STMT *stmt;
              stmt = $1;
              stmt-&gt;prev = NULL;
              $$ = stmt;
          }
          | StmtList Stmt {
              struct STMT *stmt;
              stmt = $2;
              stmt-&gt;prev = $1;
              $$ = stmt;
          }
          ;
  Stmt: AssignStmt { 
          struct STMT *stmt = (struct STMT*) malloc (sizeof (struct STMT));
          stmt-&gt;s = eAssign;
          stmt-&gt;stmt.assign_ = $1;
          $$ = stmt;
      }
      | CallStmt {
          struct STMT *stmt = (struct STMT*) malloc (sizeof (struct STMT));
          stmt-&gt;s = eCall;
          stmt-&gt;stmt.call_ = $1;
          $$ = stmt;
      }
      | RetStmt {
          struct STMT *stmt = (struct STMT*) malloc (sizeof (struct STMT));
          stmt-&gt;s = eRet;
          stmt-&gt;stmt.return_ = $1;
          $$ = stmt;
      }
      | While_s {
          struct STMT *stmt = (struct STMT*) malloc (sizeof (struct STMT));
          stmt-&gt;s = eWhile;
          stmt-&gt;stmt.while_ = $1;
          $$ = stmt;
      }
      | For_s {
          struct STMT *stmt = (struct STMT*) malloc (sizeof (struct STMT));
          stmt-&gt;s = eFor;
          stmt-&gt;stmt.for_ = $1;
          $$ = stmt;
      }
      | If_s {
          struct STMT *stmt = (struct STMT*) malloc (sizeof (struct STMT));
          stmt-&gt;s = eIf;
          stmt-&gt;stmt.if_ = $1; 
          $$ = stmt;
      }
      | CompoundStmt {
          struct STMT *stmt = (struct STMT*) malloc (sizeof (struct STMT));
          stmt-&gt;s = eCompound;
          stmt-&gt;stmt.cstmt_ = $1;
          $$ = stmt;
      }
      | ';' {
          struct STMT *stmt = (struct STMT*) malloc (sizeof (struct STMT));
          stmt-&gt;s = eSemi;
          $$ = stmt;
      }
      ;
  AssignStmt: Assign ';' { 
              $$ = $1;
            }
            ;
  Assign: ID '=' Expr {
              struct ASSIGN *assign = (struct ASSIGN*) malloc (sizeof (struct ASSIGN));
              assign-&gt;ID = $1;
              assign-&gt;index = NULL; //NUL, if LHS is scalar variable
              assign-&gt;expr = $3;
              $$ = assign;
          }
        | ID '[' Expr ']' '=' Expr {
              struct ASSIGN *assign = (struct ASSIGN*) malloc (sizeof (struct ASSIGN));
              assign-&gt;ID = $1;
              assign-&gt;index = $3; 
              assign-&gt;expr = $6;
              $$ = assign;
          }
        ;
  CallStmt: Call ';' {
              $$ = $1;
          }
          ;
  /*
  ArgList의 정의에서 empty가 되지 않도록
  Call의 정의에서 ArgList가 빠진 형태를 추가하였다.
  */
  Call: ID '(' ')' {
          struct CALL *call = (struct CALL*) malloc (sizeof (struct CALL));
          call-&gt;ID = $1;
          call-&gt;arg = NULL;
          $$ = call;
      }
      | ID '(' ArgList ')' {
          struct CALL *call = (struct CALL*) malloc (sizeof (struct CALL));
          call-&gt;ID = $1;
          call-&gt;arg = $3;
          $$ = call;
      }
      ;
  ArgList: Arg { $$ = $1;}
         | ArgList ',' Arg {
              struct ARG *arg;
              arg = $3;
              arg-&gt;prev = $1;
              $$ = arg;
          }
         ;
  Arg: Expr {
      struct ARG *arg = (struct ARG*) malloc (sizeof (struct ARG));
      arg-&gt;expr = $1;
      arg-&gt;prev = NULL;
      $$ = arg;
     }
     ;
  RetStmt: RETURN ';' {
          $$ = NULL;
          }
         | RETURN Expr ';' {
          $$ = $2;
         }
         ;
  Expr: MINUS Expr  {
          struct UNOP *unop = (struct UNOP*) malloc (sizeof (struct UNOP));
          unop-&gt;u = eNegative;
          unop-&gt;expr = $2;
  
          struct EXPR *expr = (struct EXPR*) malloc (sizeof (struct EXPR));
          expr-&gt;e = eUnop;
          expr-&gt;expression.unop_ = unop;
          $$ = expr;
      }
      | MathRel Eqltop Expr {
          struct EQLTOP *eqltop;
          eqltop = $2; 
          eqltop-&gt;lhs=$1;
          eqltop-&gt;rhs=$3;
  
          struct EXPR *expr = (struct EXPR*) malloc (sizeof (struct EXPR));
          expr-&gt;e = eEqlt;  
          expr-&gt;expression.eqltop_ = eqltop;
          $$ = expr;
      }
      | MathRel {
          struct EXPR *expr = (struct EXPR*) malloc (sizeof (struct EXPR));
          expr-&gt;e = eMathRel;  
          expr-&gt;expression.mathrel_ = $1; 
          $$ = expr;
      }   
      | Call {
          struct EXPR *expr = (struct EXPR*) malloc (sizeof (struct EXPR));
          expr-&gt;e = eCallExpr;  
          expr-&gt;expression.call_ = $1;
          $$ = expr;
      }   
      | Id_s {
          struct EXPR *expr = (struct EXPR*) malloc (sizeof (struct EXPR));
          expr-&gt;e = eId;  
          expr-&gt;expression.ID_ = $1;
          $$ = expr;
      } 
      ;
  
  MathRel: MathEql Relaop MathRel {
          struct RELAOP *relaop;
          relaop = $2;
          relaop-&gt;lhs=$1;
          relaop-&gt;rhs=$3;
  
          struct MATHREL *math = (struct MATHREL*) malloc (sizeof (struct MATHREL));
          math-&gt;r = eRela;  
          math-&gt;math_rel.relaop_ = relaop;
          $$ = math;
      }
      | MathEql {
          struct MATHREL *math = (struct MATHREL*) malloc (sizeof (struct MATHREL));
          math-&gt;r = eMathEql;  
          math-&gt;math_rel.MathEql_ = $1;
          $$ = math;
      }
      ;
  MathEql: TERM Addiop MathEql {
          struct ADDIOP *addiop;
          addiop = $2;
          addiop-&gt;lhs=$1;
          addiop-&gt;rhs=$3;
  
          struct MATHEQL *math = (struct MATHEQL*) malloc (sizeof (struct MATHEQL));
          math-&gt;e = eAddi;
          math-&gt;math_eql.addiop_ = addiop;
          $$ = math;
      }
      | TERM {
          struct MATHEQL *math = (struct MATHEQL*) malloc (sizeof (struct MATHEQL));
          math-&gt;e = eTerm;  
          math-&gt;math_eql.term_ = $1;
          $$ = math;
      }
      ;
  TERM: FACTOR Multop TERM {
          struct MULTOP *multop;
          multop = $2;
          multop-&gt;lhs=$1;
          multop-&gt;rhs=$3;
  
          struct TERM *term = (struct TERM*) malloc (sizeof (struct TERM));
          term-&gt;t = eMulti;   // eMult와 다름 
          term-&gt;ter.multop_ = multop;
          $$ = term;
      }
      | FACTOR {
          struct TERM *term = (struct TERM*) malloc (sizeof (struct TERM));
          term-&gt;t = eFactor;
          term-&gt;ter.Facop_ = $1;
          $$ = term;
      }   
      ;
  FACTOR: '(' Expr ')' {
          struct FACTOR *factor = (struct FACTOR*) malloc (sizeof (struct FACTOR));
          factor-&gt;f = eExpre;  
          factor-&gt;fac.bracket = $2;
      }
      | FLOATNUM {
          struct FACTOR *factor = (struct FACTOR*) malloc (sizeof (struct FACTOR));
          factor-&gt;f = eFloatnum;  
          factor-&gt;fac.floatnum = $1;
          $$ = factor;
      }
      | INTNUM {
          struct FACTOR *factor = (struct FACTOR*) malloc (sizeof (struct FACTOR));
          factor-&gt;f = eIntnum;  
          factor-&gt;fac.intnum = $1;
          $$ = factor;
      }
      ;   
  Id_s: ID {
          struct ID_S *id_s = (struct ID_S*)malloc(sizeof (struct ID_S));
          id_s-&gt;ID = $1;
          id_s-&gt;expr = NULL;
          $$ = id_s;
      }
      | ID '[' Expr ']' {
          struct ID_S *id_s = (struct ID_S*)malloc(sizeof (struct ID_S));
          id_s-&gt;ID = $1;
          id_s-&gt;expr = $3;
          $$ = id_s;
      }
      ;
  Addiop: MINUS {
           struct ADDIOP *addiop = (struct ADDIOP*) malloc (sizeof (struct ADDIOP));
           addiop-&gt;a = eMinus;
           $$ = addiop;
        }
        | PLUS { 
          struct ADDIOP *addiop = (struct ADDIOP*) malloc (sizeof (struct ADDIOP));
          addiop-&gt;a = ePlus;
          $$ = addiop;
        }
        ;
  Multop: MULT {
           struct MULTOP *multop = (struct MULTOP*) malloc (sizeof (struct MULTOP));
           multop-&gt;m = eMult;
           $$ = multop;
        }
        | DIV {
           struct MULTOP *multop = (struct MULTOP*) malloc (sizeof (struct MULTOP));
           multop-&gt;m = eDiv;
           $$ = multop;
        }
        ;
  Relaop: LE {
           struct RELAOP *relaop = (struct RELAOP*) malloc (sizeof (struct RELAOP));
           relaop-&gt;r = eLE;
           $$ = relaop;
        }
        | GE {
           struct RELAOP *relaop = (struct RELAOP*) malloc (sizeof (struct RELAOP));
           relaop-&gt;r = eGE;
           $$ = relaop;
        }
        | GT {
           struct RELAOP *relaop = (struct RELAOP*) malloc (sizeof (struct RELAOP));
           relaop-&gt;r = eGT;
           $$ = relaop;
        }
        | LT { 
           struct RELAOP *relaop = (struct RELAOP*) malloc (sizeof (struct RELAOP));
           relaop-&gt;r = eLT;
           $$ = relaop;
        }
        ;
  Eqltop: EQ {
           struct EQLTOP *eqltop = (struct EQLTOP*) malloc (sizeof (struct EQLTOP));
           eqltop-&gt;e = eEQ;
           $$ = eqltop;
        }
        | NE { 
           struct EQLTOP *eqltop = (struct EQLTOP*) malloc (sizeof (struct EQLTOP));
           eqltop-&gt;e = eNE;
           $$ = eqltop;
        }
        ;
  While_s: WHILE '(' Expr ')'  Stmt  {
             struct WHILE_S* while_s = (struct WHILE_S*) malloc (sizeof(struct WHILE_S));
             while_s-&gt;do_while = false;
             while_s-&gt;cond = $3;
             while_s-&gt;stmt = $5;
             $$ = while_s;
          }
           | DO  Stmt  WHILE '(' Expr ')' ';' {
             struct WHILE_S* while_s = (struct WHILE_S*) malloc (sizeof(struct WHILE_S));
             while_s-&gt;do_while = true;
             while_s-&gt;cond = $5;
             while_s-&gt;stmt = $2;
             $$ = while_s;
          }
           ;
  For_s: FOR '(' Assign ';' Expr ';' Assign ')' Stmt {
             struct FOR_S *for_s = (struct FOR_S*) malloc (sizeof(struct FOR_S));
             for_s-&gt;init = $3;
             for_s-&gt;cond = $5;
             for_s-&gt;inc = $7;
             for_s-&gt;stmt = $9;
             $$ = for_s;
          }
         ;
  
  If_s: IF '(' Expr ')' Stmt %prec then{
         struct IF_S *if_s = (struct IF_S*) malloc (sizeof(struct IF_S));
         if_s-&gt;cond=$3;
         if_s-&gt;if_=$5;
         if_s-&gt;else_=NULL;
         $$ = if_s;
      }
        | IF '(' Expr ')' Stmt ELSE Stmt {
         struct IF_S *if_s = (struct IF_S*) malloc (sizeof(struct IF_S));
         if_s-&gt;cond=$3;
         if_s-&gt;if_=$5;
         if_s-&gt;else_=$7;
         $$ = if_s;
        }
        ;
  %%
  
  void doProcess();
  int main(int argc, char* argv[]) {
      //헤드 초기화, 만일 토큰이 없다면 dfs(), bfs() 를 작동하지 않게 함.
      head = NULL;
      scopeHead = NULL;
      scopeTail = NULL;
      //print AST
      fp = fopen("tree.txt","w");
      fp2 = fopen("table.txt","w");
      if(!yyparse())
          doProcess();
      fprintf(fp, "\n");
      pclose(fp);
      pclose(fp2);
      return 0;
  }
  void doProcess() {
      //TODO
      if(head == NULL)
          exit(1);
      //make global node
      scopeHead = newScope(sGLOBAL, NULL);
      scopeTail = scopeHead;
      if(head-&gt;decl != NULL)
          visitDeclaration(head-&gt;decl);
      if(head-&gt;func != NULL)
          visitFunction(head-&gt;func);
      BuildTree(head);
  
  }
  </code></pre>
  
  <p>miniC.l</p>
  
  <pre><code>%{
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include "AST.h"
  #include "miniC.tab.h"
  %}
  
  
  
  intnum [0-9]+
  floatnum [0-9]+.[0-9]+
  id [A-Za-z][A-Za-z0-9_]*     
  space [ \t\r\n]
  
  
  %%
  
  int     return INT;
  float   return FLOAT;
  
  if return IF;
  else return ELSE;
  for return FOR;
  while return WHILE;
  do return DO;
  return return RETURN;
  
  "[" |
  "]" |
  "{" |
  "}" |
  "(" |
  ")" |
  ";" |
  "." |
  "," |
  "=" {return yytext[0];} //character 자체로 token
  "\""  {return DQUOT_T;}
  "\'"  {return SQUOT_T;}
  "\&amp;"  {return AMP_T;}
  "-"     return MINUS;
  "+"     return PLUS;
  "*"     return MULT;
  "/"     return DIV;
  "&lt;="    return LE;
  "&gt;="    return GE;
  "&gt;"     return GT;
  "&lt;"     return LT;
  "=="    return EQ;
  "!="    return NE;
  
  {intnum} {
      yylval.intnum = atoi(yytext);
      return INTNUM;
  }
  {floatnum} {
      yylval.floatnum = atof(yytext);
      return FLOATNUM;
  }
  {id}   {
      yylval.id = strndup(yytext, yyleng);
      return ID;
  }
  
  {space} { break;}
  
  %%
  </code></pre>
  
  <p>AST.h</p>
  
  <pre><code>#ifndef AST_H
  #define AST_H
  
  #define bool char 
  #define true 1 
  #define false 0
  
  typedef enum
  {eInt,eFloat} Type_e;
  typedef enum
  {eNegative} Unop_e;
  typedef enum
  {eAssign,eCall,eRet,eWhile,eFor,eIf,eCompound,eSemi} Stmt_e;
  typedef enum
  {eUnop,eEqlt,eCallExpr,eId,eMathRel} Expr_e;
  typedef enum
  {eRela,eMathEql} MathRel_r;
  typedef enum
  {eAddi,eTerm} MathEql_e;
  typedef enum
  {eCom,eInc} Cond_c;
  typedef enum
  {eStmt,eIncom,eComp} Sta_s;
  typedef enum
  {eFactor,eMulti} Term_t;
  typedef enum
  {eIntnum,eFloatnum,eExpre} Factor_f;
  typedef enum
  {ePlus,eMinus} Addi_e;
  typedef enum
  {eMult,eDiv} Mult_e;
  typedef enum
  {eLT,eGT,eLE,eGE} Rela_e;
  typedef enum
  {eEQ,eNE} Eqlt_e;
  
  
  
  struct PROGRAM
  {
      struct DECLARATION *decl;
      struct FUNCTION *func;
  };
  
  struct DECLARATION
  {
      Type_e t;
      struct IDENTIFIER *id;
      struct DECLARATION *prev;
  };
  
  struct IDENTIFIER
  {
      char *ID;
      int intnum; // zero  , if scalar
      struct IDENTIFIER *prev;
  
  };
  
  struct FUNCTION  // *prev  type id (parameter) {} 
  {
      Type_e t;
      char *ID;
      struct PARAMETER *param;
      struct COMPOUNDSTMT *cstmt;
      struct FUNCTION *prev;
  };
  
  struct PARAMETER
  {
      Type_e t;
      struct IDENTIFIER *id;
      struct PARAMETER *prev;
  };
  
  struct COMPOUNDSTMT // {}
  {
      struct DECLARATION *decl;
      struct STMT *stmt;
  };
  /*
  break,semi stmt union stmt -&gt; no value; 
  */
  struct STMT 
  {   
      Stmt_e s;
      union {
          struct ASSIGN *assign_; // id=expr;
          struct CALL *call_; // id(arg) 
          struct EXPR *return_; // return expr
          struct WHILE_S *while_; // while()stmt | do_while() stmt
          struct FOR_S *for_; // for()stmt
          struct IF_S *if_;  // if()stmt
          struct COMPOUNDSTMT *cstmt_; // {}
      } stmt; 
      struct STMT *prev;
  };
  
  /* id[index]=expr;  */
  struct ASSIGN
  {
      char *ID;
      struct EXPR *index; // Null, if LHS is scalar variable
      struct EXPR *expr;  // RHS
  };
  
  /* id(arglist?);  */
  struct CALL
  {
      char *ID;
      struct ARG *arg;
  };
  
  /* (expr,expr*)  */
  struct ARG
  {
      struct EXPR *expr;
      struct ARG *prev;
  
  };
  
  /* while(cond)stmt;  | do stmt while (cond) */ 
  struct WHILE_S 
  {
      bool do_while;
      struct EXPR *cond;
      struct STMT *stmt;
  
  };
  
  /* for(init;cond;inc)stmt;  */
  struct FOR_S
  {
      struct ASSIGN *init;
      struct EXPR *cond;
      struct ASSIGN *inc;
      struct STMT *stmt; 
  
  };
  
  /* if(cond)if_s else else_s  */
  struct IF_S
  {
      struct EXPR *cond;
      struct STMT *if_;
      struct STMT *else_; // NUll, if 'else' not exist
  };
  
  struct EXPR
  {
      Expr_e e;   // EXPR type (enumeration type)
      union
      {
          struct UNOP *unop_; // -expr
          struct MATHREL *mathrel_;
          struct ADDIOP *addiop_; // epxr + expr
          struct EXPR *bracket;
          struct EQLTOP *eqltop_;
          struct CALL *call_; // call 
          struct ID_S *ID_; // id[expr]
      } expression;
  };
  
  struct MATHREL
  {
      MathRel_r r;
      union
      {
          struct RELAOP *relaop_; // expr &gt;= expr
          struct MATHEQL *MathEql_; // expr &gt;= expr
      } math_rel;
  };
  
  struct MATHEQL
  {
      MathEql_e e;
      union
      {
          struct ADDIOP *addiop_; // expr == expr
          struct TERM *term_;
      } math_eql;
  };
  
  struct TERM
  {
      Term_t t;
      union
      {
          struct MULTOP *multop_;
          struct FACTOR *Facop_;
      } ter;
  };
  
  struct FACTOR
  {
      Factor_f f;
      union
      {
          int intnum; // int
          float floatnum; // float
          struct EXPR *bracket;
      } fac;
  };
  
  struct UNOP
  {
      Unop_e u;
      struct EXPR *expr;
  };
  
  /* lhs addiop rhs */
  struct ADDIOP
  {
      Addi_e a;
      struct TERM *lhs;
      struct MATHEQL *rhs;
  };
  
  /* lhs multiop rhs */
  struct MULTOP
  {
      Mult_e m;
      struct FACTOR *lhs;
      struct TERM *rhs;
  };
  
  /* lhs relaop rhs */
  struct RELAOP
  {
      Rela_e r;
      struct MATHEQL *lhs;
      struct MATHREL *rhs;
  };
  
  /* lhs eqltop rhs */
  struct EQLTOP
  {
      Eqlt_e e;
      struct MATHREL *lhs;
      struct EXPR *rhs;
  };
  
  /* id[expr]  */
  struct ID_S
  {
      char *ID;
      struct EXPR *expr; // NULL , if scalar variable
  };
  
  #endif
  </code></pre>
  
  <p>input.txt</p>
  
  <pre><code>int main () 
  {
      int result;
  
      result = 0; 
  
      if (result &gt; 0) 
      {  
          result = 1;
      } else {
          result  = 2;
          result = 32;
      }
      return result; 
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>syntax error, unexpected GT, expecting ')'
  </code></pre>
  
  <p>How to run: </p>
  
  <pre><code>./miniC &lt;input.txt
  </code></pre>
  
  <p>More information <a href="https://github.com/phgeraldeli/CtoPDLConverter" rel="nofollow noreferrer">here</a></p>
  
  <p>It should work according to <a href="https://cs.stackexchange.com/questions/23738/grammar-for-parsing-simple-mathematical-expression?fbclid=IwAR1hggMp-eE4A9f1ww0fOH7tTSI5Z1IB_w91l9T4CRIZ4PE2HwXglPTVIpE">Grammar for parsing simple mathematical expression</a></p>
  
  <p>But still have these problems, can you help me?</p>