title: Syntax analysis and semantic analysis
body: <p>I am wondering how the syntax analysis and semantic analysis work.</p>
  
  <p>I have finished the lexer and the grammar construction of my interpreter.</p>
  
  <p>Now I am going to implement a recursive descent (top down) parser for this grammar</p>
  
  <p>For example, I have the following grammar:</p>
  
  <pre><code>&lt;declaration&gt;  ::=   &lt;data_type&gt; &lt;identifier&gt; ASSIGN &lt;value&gt;
  </code></pre>
  
  <p>so i coded it like this (in java):</p>
  
  <pre><code>public void declaration(){
      data_type();
      identifier();
      if(token.equals("ASSIGN")){
          lexer();   //calls next token
          value();
      } else {
          error();
      }
  }
  </code></pre>
  
  <p>Assuming I have three data types: Int, String and Boolean. Since the values for each data types are different, (ex. true or false only in Boolean) how can I determine if it fits the data type correctly? What part of my code would determine that? </p>
  
  <p>I am wondering where would I put the code to:</p>
  
  <pre><code>1.) call the semantic analysis part of my program. 
  2.) store my variables into the symbol table.
  </code></pre>
  
  <p>Do syntax analysis and semantic analysis happen at the same time? 
  or do i need to finish the syntax analysis first, then do the semantic analysis?</p>
  
  <p>I am really confused. Please help.</p>
  
  <p>Thank you.</p>