net.scheinerman.phoenix.interpreter
Class ForInterpreter

java.lang.Object
  extended by net.scheinerman.phoenix.interpreter.Interpreter
      extended by net.scheinerman.phoenix.interpreter.LoopInterpreter
          extended by net.scheinerman.phoenix.interpreter.ForInterpreter

public class ForInterpreter
extends LoopInterpreter

Extends the standard Interpreter and LoopInterpreter to provide for-loop functionality. This code loops over a specific variable, incrementing it my some value until an end condition is met.

Since:
1.5
Version:
1.0
Author:
Jonah Scheinerman
See Also:
LoopInterpreter}, {@link Interpreter}

Field Summary
private  java.lang.String endCondition
           
protected  boolean firstLoop
           
private  java.lang.String incCondition
           
private  boolean initialization
           
private  java.lang.String startCondition
           
 
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
ForInterpreter(java.lang.String file, java.lang.String code, int line, java.lang.String forStatement, 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 for loop that takes the LoopInterpreter arguments along with the end condition of the for loop.
 
Method Summary
protected  void afterEnd()
           
protected  void beforeStart()
           
private  boolean endConditionMet()
           
protected  boolean isDone()
          This method determines whether or not the for statement passed to the constructor is true or false.
 
Methods inherited from class net.scheinerman.phoenix.interpreter.LoopInterpreter
dealWithBreak, dealWithContinue, run
 
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

firstLoop

protected boolean firstLoop

initialization

private boolean initialization

startCondition

private java.lang.String startCondition

endCondition

private java.lang.String endCondition

incCondition

private java.lang.String incCondition
Constructor Detail

ForInterpreter

public ForInterpreter(java.lang.String file,
                      java.lang.String code,
                      int line,
                      java.lang.String forStatement,
                      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 for loop that takes the LoopInterpreter arguments along with the end condition of the for loop.

Parameters:
file - - the currently read file
code - - the lines of code that are to be executed
line - - the starting line number
forStatement - - the statement containing the end condition of the loop
vat - - the enclosing interpreter's VAT
fat - - the enclosing interpreter's FAT
Method Detail

isDone

protected boolean isDone()
This method determines whether or not the for statement passed to the constructor is true or false. If the statement is true, the loop continues and the loop variable is incremented by a given amount. If the statement is not true, the loop is ended and the loop variable leaves scope. This method will be called on the first iteration of the loop and if it determines that the loop should continue, it will not increment the loop variable because its the first iteration of the loop.

Overrides:
isDone in class LoopInterpreter
Returns:
whether or not the loop should end.

endConditionMet

private boolean endConditionMet()

beforeStart

protected void beforeStart()
Overrides:
beforeStart in class LoopInterpreter

afterEnd

protected void afterEnd()
Overrides:
afterEnd in class LoopInterpreter