title: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
body: <p>I am working on a project that parses a text file thats suppose to be a simple coded program. The problem is that when I try to complile the program I get this error:</p>
  
  <pre><code>In file included from driver.c:10:
  parser.c: In function ‘Statement’:
  parser.c:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  parser.c:153: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  parser.c:159: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  parser.c:167: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  parser.c:176: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  parser.c:185: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  parser.c:194: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  parser.c:201: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  parser.c:209: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  driver.c:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  driver.c:50: error: old-style parameter declarations in prototyped function definition
  driver.c:50: error: expected ‘{’ at end of input
  </code></pre>
  
  <p>Im not familiar with this error and not sure how to fix it.</p>
  
  <p>Here is my parser.c file which the error is happening in:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "parser.h"
  
  AST_NODE* Program(AST_NODE* node);
  AST_NODE* Statement(AST_NODE* node)
  AST_NODE* AssignStmt(AST_NODE* node);
  AST_NODE* Print(AST_NODE *node);
  AST_NODE* Repeat(AST_NODE* node);
  AST_NODE* Exp(AST_NODE* node);
  AST_NODE* Factor(AST_NODE* node);
  AST_NODE* Term(AST_NODE* node);
  
  
  AST_NODE* parser(TOKEN* token,AST_NODE* node, FILE* input_file)
  {
      AST_NODE temp = malloc(sizeof(AST_NODE*));
  
      if(token-&gt;type == Id)
      {
          temp-&gt; tok = token;
          node -&gt; child1 = temp;
          return node
      }else
      if(token-&gt;type == keyword)
      {
          if(strcmp(node-&gt;attribute, "print") == 0)
          {
              temp -&gt; type = print;
              node -&gt; child1 = temp;
              return node;
          }
          else if(strcmp(node-&gt;attribute, "repeat") == 0)
          {
              temp -&gt; type = repeat;
              node -&gt; child1 = temp;
              return node;
          }
          return node-&gt;prev;
      }else
      if(token-&gt;type == num)
      {
  
          temp-&gt;type = factor;
          temp-&gt;tok = token;
          AST_NODE temp2 = Exp(Term(temp));
          node-&gt; child3 = temp2
  
          return node;//back to ID-&gt;term-&gt;exp then to either print repeat or assignment
      }else
      if(token-&gt;type == addOp)
      {
          temp-&gt; tok = token;
          node-&gt; child2 = temp;
          return node;
      }else
      if(token-&gt;type == multOp)
      {
          temp-&gt; tok = token;
          node-&gt; child2 = temp;
          return node;
      }else
      if(token-&gt;type == assignment)
      {
          temp-&gt;type = assignStmt;
          temp-&gt;tok = token; 
          node-&gt;child2 = temp;
          return node;
      }else
      if(token-&gt;type == semicolon)
      {
          temp-&gt; type = assignStmt;
          temp-&gt; tok = token;
          if(node-&gt;type == keyword)
          {
              node-&gt;child3 = temp;
          }else
          {
              node-&gt;child4 = temp;
          }
          return node;
      }else
      if(token-&gt;type == lparen)
      {
          temp -&gt; tok = token;
          if(node-&gt;type == repeat)
              node-&gt;child2 = temp;
          else
              node-&gt;child1 = temp;
  
          return node = node-&gt;prev;
      }else
      if(token-&gt;type == rparen)
      {
          temp -&gt; tok = token;
          if(node-&gt;type == repeat)
              node-&gt;child4 = temp;
          else
              node-&gt;child3 = temp;
  
          return node;
      }else if(token-&gt;type == newLine)
      {
          while(node-&gt;type != program)
          {
              node = node-&gt;prev;
          }
          return node;
      }else{
  
          if(token-&gt;type == Id)
          {
              AST_NODE temp2 =  AssignStmt(Program(node));
              temp-&gt;type = Id;
              temp-&gt;tok = token
              temp-&gt;prev = temp2;
              temp2-&gt; child1 = temp;
              return temp2;
          }else if(strcmp(token-&gt;attribute,"print"))
          {
  
              AST_NODE temp2 =  Print(Program(node));
              temp-&gt;type = print;
              temp-&gt;tok = token
              temp-&gt;prev = temp2;
              temp2-&gt; child1 = temp;
              return temp2;
          }else if(strcmp(token-&gt;attribute,"repeat"))
          {
  
              AST_NODE temp2 =  Repeat(Program(node));
              temp-&gt;type = repeat;
              temp-&gt;tok = token
              temp-&gt;prev = temp2;
              temp2-&gt; child1 = temp;
              return temp2;
          }
          printf("error");
          return NULL;
      }
  
  
  }
  AST_NODE* Program(AST_NODE* node)
  {
      node-&gt;type = program;
      Statement(node);
      return node;
  }
  AST_NODE* Statement(AST_NODE* node)
  {
      AST_NODE temp = malloc(sizeof(AST_NODE*));
      temp-&gt; type = statement;
      temp-&gt; prev = node;
      node-&gt;child1-&gt; temp;
      return temp;
  }
  AST_NODE* AssignStmt(AST_NODE* node)
  {
      AST_NODE temp = malloc(sizeof(AST_NODE*));
      temp-&gt;type = assignStmt;
      temp-&gt; prev = node;
      node-&gt;child1-&gt; temp;
      return temp;
  
  }
  AST_NODE* Print(AST_NODE* node)
  {
      AST_NODE temp = malloc(sizeof(AST_NODE*));
      temp-&gt;type = print;
      temp-&gt; prev = node;
      node-&gt;child1-&gt; temp;
      return node;
  
  }
  AST_NODE* Repeat(AST_NODE* node)
  {
      AST_NODE temp = malloc(sizeof(AST_NODE*));
      temp-&gt;type = repeat;
      temp-&gt; prev = node;
      node-&gt;child1-&gt; temp;
      return node;
  
  }
  AST_NODE* Exp(AST_NODE* node)
  {
      AST_NODE temp = malloc(sizeof(AST_NODE*));
      temp-&gt;type = exp;
      temp-&gt;child1-&gt; node;
      return temp;
  }
  AST_NODE* factor(AST_NODE* node)
  {
      AST_NODE Temp = malloc(sizeof(AST_NODE*));
      temp-&gt;type = factor;
      node-&gt;child1-&gt; temp;
      return temp;
  
  }
  AST_NODE* Term(AST_NODE* node)
  {
      AST_NODE temp = malloc(sizeof(AST_NODE*));
      temp-&gt;type = term;
      temp-&gt;child1-&gt; node;
      return temp;
  
  }
  </code></pre>
  
  <p>Here is my driver.c file where I am also getting the error "old-style parameter declarations in prototyped function definition expected '{' at end of input". This also I am very unfamiliar with. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "parser.c"
  #include "parser.h"
  
  
  
  
  AST_NODE* parser(TOKEN* token,AST_NODE node, FILE *input_file);
  
  int main(void)
  {
      TREE *current = 0;
      FILE *input_file = fopen("test.txt", "r");
      TOKEN *token = (TOKEN*) malloc(sizeof(TOKEN));
      TOKEN *tok = (TOKEN*) malloc(sizeof(TOKEN));
      AST_NODE* node = malloc(sizeof(AST_NODE));
  
      while(!feof(input_file))
      {
      token = scan(input_file);
  
          if(token-&gt;type != null)
          {
              parser(token,node,input_file);
              printf("%s", token-&gt;attribute);
              if(token-&gt;checkR == ';')
              {
  
                  tok-&gt;type = semicolon;
                  tok-&gt;attribute = ";";
                  parser(tok,node,input_file);            
              }if(token-&gt;checkR == ')')
              {
                  tok-&gt;type = rparen;
                  tok-&gt;attribute = ")";
                  parser(tok,node,input_file);
              }
          }
      }
      fclose(input_file);
      return 0;
  }
  </code></pre>
  
  <p>Here is my parser.h file where I declare my TOKEN and my AST_NODE to create my tree and form my tokens to fill the tree. </p>
  
  <pre><code>#ifndef _parser_h
  #define _parser_h
  
  
  typedef enum token_type
  {
      null,
      Id,
      keyword,
      num,
      addOp,
      multOp,
      assignment,
      semicolon,
      lparen,
      rparen,
      newLine
  }TOKEN_TYPE;
  
  typedef struct token{
      int type;
      char *attribute;
      char checkR;
  }TOKEN;
  
  typedef enum node_type
  {
      program,
      statement,
      assignStmt,
      print,
      repeat,
      exp,
      factor,
      term
  }NODE_TYPE;
  
  typedef struct ast_node{
      NODE_TYPE type;
      TOKEN *tok;
      struct AST_NODE *prev;
      struct AST_NODE *child1;
      struct AST_NODE *child2;
      struct AST_NODE *child3;
      struct AST_NODE *child4;
      struct AST_NODE *child5;
  
  
  }AST_NODE;
  
  #endif
  </code></pre>
  
  <p>There is one more file called scanner.c but I know its working perfectly because I have tested it in all the possible inputs and got no problems.</p>
  
  <p>If anyone could help I would appreciate it very much. </p>