net.scheinerman.phoenix.interpreter
Class LoopInterpreter

java.lang.Object
  extended by net.scheinerman.phoenix.interpreter.Interpreter
      extended by net.scheinerman.phoenix.interpreter.LoopInterpreter
Direct Known Subclasses:
ForInterpreter, WhileInterpreter

public abstract class LoopInterpreter
extends Interpreter

Extends the standard interpreter to provide abstract loop functionality to the standard interpretation of a Phoenix program. This class is meant to be extended and not used. The current implementation provides infinite looping capability. When extending this class, the loop end mechanism can be rewritten by overriding the isDone() method, which determines whether or not the loop has finished.

Since:
1.5
Version:
1.0
Author:
Jonah Scheinerman
See Also:
Interpreter}

Field Summary
private  boolean run
          Indicates whether or not this loop has been executed, not allowing it to be run more than once.
 
Fields inherited from class net.scheinerman.phoenix.interpreter.Interpreter
_break, _continue, _return, breakValue, code, fat, file, keywordList, line, line_diff, printValues, retType, retTypeSet, retValue, run_code, stop, vat
 
Constructor Summary
LoopInterpreter(java.lang.String file, java.lang.String code, int line, 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 basic loop interpreter.
 
Method Summary
protected  void afterEnd()
           
protected  void beforeStart()
           
protected  void dealWithBreak(int value)
          Deals with a break by reducing the value of the break by one, exiting the loop, and passing the break up to the above interpreter if the break value is greater than zero.
protected  int dealWithContinue(int line)
          Deals with a loop by moving to the end of loop and continuing if the ending condition has not been met.
protected  boolean isDone()
          This method is called to indicate that the end of a loop cycle has occurred.
 void run()
          This provides default implementation for a loop run structure.
 
Methods inherited from class net.scheinerman.phoenix.interpreter.Interpreter
dealWithError, dealWithReturn, delete, doRun, getBlock, getFunction, getFunctionArguments, getFunctionFromDefinition, getReturnValue, getVariable, getWhitespace, initNewTables, isValidIdentifier, makeDefaultVariable, makeFunction, makeVariable, makeVariable, parsePhrase, putFunction, removeComments, removeWhitespace, retValueMatches
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

run

private boolean run
Indicates whether or not this loop has been executed, not allowing it to be run more than once.

Constructor Detail

LoopInterpreter

public LoopInterpreter(java.lang.String file,
                       java.lang.String code,
                       int line,
                       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 basic loop interpreter. This constructor provides the necessary requirements for any interpreter subclass. The VAT and FAT of the enclosing interpreter, the file, the code section, and the line number. Any subclasses must use these constructor arguments along with any others that they might need for that specific loop.

Parameters:
file - - The currently read file.
code - - The lines of code that are to be executed.
line - - The starting line number.
vat - - The enclosing interpreter's VAT.
fat - - The enclosing interpreter's FAT.
Method Detail

run

public final void run()
This provides default implementation for a loop run structure. It first tests to see whether the run method has previously been called. If it has, it ends. If not, it creates a new VAT and a new FAT for this level of locality. Then it enters a loop that does not end until one of two things occurs: the method isDone() returns true or the protected variable indicating whether a break has been encountered becomes true. The loop simply calls an execution method on the run_code for this interpreter. When the loop exits, the local VAT and FAT are removed from the lists and execution ends.

Overrides:
run in class Interpreter

dealWithBreak

protected void dealWithBreak(int value)
Deals with a break by reducing the value of the break by one, exiting the loop, and passing the break up to the above interpreter if the break value is greater than zero.

Overrides:
dealWithBreak in class Interpreter
Parameters:
value - - The number of breaks that should be executed.

dealWithContinue

protected int dealWithContinue(int line)
Deals with a loop by moving to the end of loop and continuing if the ending condition has not been met. The returned line of this method is the last line in the loop, thus effectively ending the loop.

Overrides:
dealWithContinue in class Interpreter
Parameters:
line - - The number of the line on which the continue is encountered.
Returns:
The line that should be interpreted next after the continue.

isDone

protected boolean isDone()
This method is called to indicate that the end of a loop cycle has occurred. This method should perform any calculations and return whether or not the loop should end. A return value of false indicates that the loop should continue, true indicates that the loop should end. This particular implementation always returns false creating an infinite loop. If this class is extended, this method should be overridden to provide appropriate functionality.
Note: This method is called before the loop begins, so if the loop should only check at the "end" of a loop a variable must be in place to indicate whether or not this is the first time this method has been called.

Returns:
whether or not the loop should end.

beforeStart

protected void beforeStart()

afterEnd

protected void afterEnd()