title: How to walk if-else block in ANTLR?
body: <p>I have written grammar for a language (sample code below)</p>
  
  <pre><code>//this is a procedure
  procedure main()
      $i := 0
  begin
      if ($i = 0)
          $i := 10
          loop while ($i != 0)
              print($i)
              $i := $i - 1
          end loop
      end if
  end procedure
  </code></pre>
  
  <p>The tree grammar for which is</p>
  
  <pre><code>@members {
    private Map&lt;String, Integer&gt; variablesTable = new HashMap&lt;String, Integer&gt;();
  }
  procedure
      :   ^('procedure' IDENTIFIER assignment_expression* 'begin' statement+)
      ;
  statement
      :   assignment_expression | selection_statement
      ;
  assignment_expression
      :   ^(':=' IDENTIFIER e=expression)
          { variablesTable.put($IDENTIFIER.text, e); }
      ;
  expression returns [int result]
      :   ^('+' op1=expression op2=expression) { result = op1 + op2; }
      /* removed similar lines */ 
      |   IDENTIFIER { result = variablesTable.get($IDENTIFIER.text); }
      |   INTEGER { result = Integer.parseInt($INTEGER.text); }
      ;
  
  equality_expression returns [boolean truth]
      :   ^('=' op1=expression op2=expression) { truth = op1 == op2; }
      |   ^('!=' op1=expression op2=expression) { truth = op1 != op2; }
      ;
  selection_statement
      :   ^('if' e=equality_expression block1=statement+ ('else' block2=statement+)? )
          { 
              if (e)  {
                   //What do I put here?
              }
          }
      ;
  </code></pre>
  
  <p>While I can evaluate expressions, print messages etc., I am not able figure out how to change execution (interpretation) of program.<br>
  Like in above code, for if-else, how can I execute if-block in case predicate is true, and skip to else (if it is there)?<br>
  Same goes for loop, how can I evaluate loop-predicate at the end of loop?</p>
  
  <p>Thanks!</p>