net.scheinerman.phoenix.interpreter
Class IfInterpreter

java.lang.Object
  extended by net.scheinerman.phoenix.interpreter.IfInterpreter

public class IfInterpreter
extends java.lang.Object

Provides interpretation of if / else / else if blocks in Phoenix by testing the conditions and creating a subordinate Interpreter to interpret the correct code. The IfInterpreter takes a list of conditions and interprets them in order. The code of the first one that is true when evaluated is run, or if there is an else condition, and all of the other conditions are false, the else condition is run. The IfInterpreter acts similarly to the Interpreter class and makes use of it, but does not actually extend the Intepreter class.

Since:
1.5
Version:
1.0
Author:
Jonah Scheinerman

Field Summary
protected  boolean _break
          Indicates whether or not a break was encountered in this scope.
protected  boolean _continue
          Indicates whether or not a continue was encountered in this scope.
protected  boolean _return
          Indicates whether or not a return was encountered in this scope.
protected  int breakValue
          Indicates the value after a break statement that was called within this scope.
private  java.util.ArrayList<Condition> conditions
          The set of conditions making up this if / else / else if block.
private  java.util.LinkedList<java.util.HashMap<java.lang.String,Function>> fat
          The Function Allocation Table (FAT) stores functions and their values for all scopes of the interpretation process.
private  java.lang.String file
          The path of the file that is being interpreted.
private  Interpreter interpreter
          The interpreter that might be used to run the first conditions that evaluates to true, or the else condition if all previous evaluate to false.
protected  Variable retValue
          The value returned after a return statement.
private  java.util.LinkedList<java.util.HashMap<java.lang.String,Variable>> vat
          The Variable Allocation Table (VAT) stores variables and their values for all scopes of the interpretation process.
 
Constructor Summary
IfInterpreter(java.lang.String file, java.util.ArrayList<Condition> conditions, Interpreter interpreter, java.util.LinkedList<java.util.HashMap<java.lang.String,Variable>> vat, java.util.LinkedList<java.util.HashMap<java.lang.String,Function>> fat)
          Creates a new IfInterpreter with a given file, a set of conditions, an interpreter to run the conditions, a VAT and a FAT.
 
Method Summary
protected  void dealWithBreak(int value)
          Deals with a break statement in the subordinate Interpreter by passing it up to the above interpreter.
protected  void dealWithContinue()
          Deals with a continue statement in the subordinate Interpreter by passing it up to the above interpreter.
protected  void dealWithReturn(Variable passed)
          Deals with a return statement in the subordinate Interpreter by passing it up to the above interpreter.
 void run()
          Runs this interpretation by checking through the conditions and running the appropriate one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

breakValue

protected int breakValue
Indicates the value after a break statement that was called within this scope.


_break

protected boolean _break
Indicates whether or not a break was encountered in this scope.


_continue

protected boolean _continue
Indicates whether or not a continue was encountered in this scope.


_return

protected boolean _return
Indicates whether or not a return was encountered in this scope.


retValue

protected Variable retValue
The value returned after a return statement.


file

private java.lang.String file
The path of the file that is being interpreted. This field is used when in the output of error messages.


interpreter

private Interpreter interpreter
The interpreter that might be used to run the first conditions that evaluates to true, or the else condition if all previous evaluate to false.


conditions

private java.util.ArrayList<Condition> conditions
The set of conditions making up this if / else / else if block.


vat

private java.util.LinkedList<java.util.HashMap<java.lang.String,Variable>> vat
The Variable Allocation Table (VAT) stores variables and their values for all scopes of the interpretation process. Each element of the list is a new scope. Each element is a map from the identifier of a variable to its Variable class equivalent. The last element of the list is the global scope, the second to the last is the top-level local scope. The front element of the list is the the most local scope. This VAT is used to pass to the subordinate interpreter for the conditons.


fat

private java.util.LinkedList<java.util.HashMap<java.lang.String,Function>> fat
The Function Allocation Table (FAT) stores functions and their values for all scopes of the interpretation process. Each element of the list is a new scope. Each element is a map from the identifier of a function to its Function class equivalent. The last element of the list is the global scope, the second to the last is the top-level local scope. The front element of the list is the the most local scope. This FAT is used to pass to the subordinate interpreter for the conditons.

Constructor Detail

IfInterpreter

public IfInterpreter(java.lang.String file,
                     java.util.ArrayList<Condition> conditions,
                     Interpreter interpreter,
                     java.util.LinkedList<java.util.HashMap<java.lang.String,Variable>> vat,
                     java.util.LinkedList<java.util.HashMap<java.lang.String,Function>> fat)
Creates a new IfInterpreter with a given file, a set of conditions, an interpreter to run the conditions, a VAT and a FAT.

Parameters:
file - - The path of the file that is being interpreted.
conditions - - The if / else / else if conditons.
interpreter - - The interpreter to be used to run the code.
vat - - The Variable Allocation Table (VAT) for this instance.
fat - - The Function Allocation Table (FAT) for this instance.
Method Detail

run

public void run()
Runs this interpretation by checking through the conditions and running the appropriate one.


dealWithBreak

protected void dealWithBreak(int value)
Deals with a break statement in the subordinate Interpreter by passing it up to the above interpreter.

Parameters:
value - - The value passed by the break statement.

dealWithContinue

protected void dealWithContinue()
Deals with a continue statement in the subordinate Interpreter by passing it up to the above interpreter.


dealWithReturn

protected void dealWithReturn(Variable passed)
Deals with a return statement in the subordinate Interpreter by passing it up to the above interpreter.

Parameters:
passed - - The variable passed to the return statement.