gt: 						if (localPointers.get(dataToken.getDataLiteral()) == null
context: package com.rayburn.engine.dew.lang;
  
  import com.rayburn.engine.dew.DewException;
  import com.rayburn.engine.util.debug.Logger;
  import org.apache.commons.lang3.mutable.MutableInt;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.LinkedList;
  import java.util.Set;
  import java.util.Stack;
  import java.util.regex.Pattern;
  
  import static com.rayburn.engine.dew.lang.DewInterpreter.DewMathFunctionSet.add;
  import static com.rayburn.engine.dew.lang.DewInterpreter.DewMathFunctionSet.castToFloat;
  import static com.rayburn.engine.dew.lang.DewInterpreter.DewMathFunctionSet.castToInteger;
  import static com.rayburn.engine.dew.lang.DewInterpreter.DewMathFunctionSet.div;
  import static com.rayburn.engine.dew.lang.DewInterpreter.DewMathFunctionSet.mod;
  import static com.rayburn.engine.dew.lang.DewInterpreter.DewMathFunctionSet.mul;
  import static com.rayburn.engine.dew.lang.DewInterpreter.DewMathFunctionSet.sub;
  import static com.rayburn.engine.dew.lang.DewParser.AlgebraicExpressionBranch
  		.canEvaluateNaturalMathToConstant;
  import static com.rayburn.engine.dew.lang.DewParser.AlgebraicExpressionBranch
  		.convertNaturalMathToRPN;
  import static com.rayburn.engine.dew.lang.DewParser.AlgebraicExpressionBranch.evalRPN;
  
  /**
   * @author guyfleeman
   * @date 03/03/14
   */
  public class DewParser
  {
  	private static DewParser instance;
  	private static Logger parserLogger = new Logger();
  
  	/**
  	 * Map linking syntax token to their precedence
  	 */
  	public static final HashMap<DewLexer.LexicalTokens.SyntaticToken.SyntaxElement, Integer> shuntingYardPrecedence;
  
  	/**
  	 * Regex to identify numbers.
  	 */
  	public static final Pattern genericNumberRegex = Pattern.compile("^-?\\d+([,\\.]\\d+)?([eE]-?\\d+)?$");
  
  	static
  	{
  		shuntingYardPrecedence = new HashMap<DewLexer.LexicalTokens.SyntaticToken.SyntaxElement, Integer>();
  		shuntingYardPrecedence.put(DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.OPERATOR_MATH_MUL, 2);
  		shuntingYardPrecedence.put(DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.OPERATOR_MATH_DIV, 2);
  		shuntingYardPrecedence.put(DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.OPERATOR_MATH_MOD, 2);
  		shuntingYardPrecedence.put(DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.OPERATOR_MATH_ADD, 1);
  		shuntingYardPrecedence.put(DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.OPERATOR_MATH_SUB, 1);
  
  		instance = new DewParser();
  	}
  
  	DewParser() {}
  
  	public static DewParser getInstance()
  	{
  		return instance;
  	}
  
  	///////////////////////////////////
  	//  end instance initialization  //
  	///////////////////////////////////
  
  
  
  	public SyntaxBranch parse(Stack tokenizedDewScript) throws DewException
  	{
  		DewLexer.LexicalTokens.SyntaticToken initialTriggerToken;
  		SyntaxBranch primaryBranch;
  		ArrayList<DewLexer.LexicalTokens.LexicalToken> scriptTokens = new ArrayList<DewLexer.LexicalTokens
  				.LexicalToken>();
  		ArrayList<ParseTokens.Variable> globalVariables = new ArrayList<ParseTokens.Variable>();
  		HashMap<String, Short> globalPointers = new HashMap<String, Short>();
  		MutableInt index = new MutableInt(0);
  		short initialDepth = 0;
  
  		for (Object genericToken : tokenizedDewScript)
  			scriptTokens.add((DewLexer.LexicalTokens.LexicalToken) genericToken);
  
  		parserLogger.log(Logger.LogLevel.INFO, "Evaluating token " + scriptTokens.get(0));
  
  		if (!(scriptTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.SyntaticToken)
  				|| !(((DewLexer.LexicalTokens.SyntaticToken) scriptTokens.get(index.getValue())).getElement()
  					== DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.START_OF_FILE))
  		{
  			parserLogger.log(Logger.LogLevel.FATAL, "Script entry point not found.");
  			parserLogger.log(Logger.LogLevel.INFO, "Did DewParser successfully parse source?");
  			throw new DewException("Start of file not found. Quitting.");
  		}
  		else
  		{
  			parserLogger.log(Logger.LogLevel.INFO, "Valid entry point found. Proceeding.");
  			initialTriggerToken = (DewLexer.LexicalTokens.SyntaticToken) scriptTokens.get(index.getValue());
  			scriptTokens.remove(index.getValue());
  		}
  
  		primaryBranch = createBranch(initialTriggerToken,
  				0,
  				scriptTokens,
  				globalVariables,
  				globalVariables,
  				globalPointers,
  				globalPointers,
  				initialDepth,
  				index);
  
  		return primaryBranch;
  	}
  
  	/**
  	 * This recursive method creates a syntax tree by processing a Stack containing tokenized DewScript source. It
  	 * handles expression evaluation and subbranching as necessary. It handles variable scope as necessary. It
  	 * handles variable pointers as necessary.
  	 *
  	 * @param branchTriggerToken the token that flagged the method to make a recursive call
  	 *                           and evaulate a subbranch.
  	 * @param branchTriggerTokenIndex the index of the arrayList that flagged the method to make a recursive call
  	 *                                and evaulate a subbranch.
  	 * @param lexicalTokens an ArrayList containing the lexical tokens from the lexer to be parsed and assembled
  	 *                      into a syntax tree or subbranch.
  	 * @param globalVariableList the ArrayList containg the highest level branch's (the trunk, or starting branch of
  	 *                           the tree) variables. Any variabel declared as public should added to this list to
  	 *                           ensure public scope.
  	 * @param localVariableList the ArrayList conaining private variables only relative to the current subbranch.
  	 *                          Variables added to this list are not passed up the syntax tree as this list is
  	 *                          cloned in subbraches to keep the security of variabel scope. Varibles added to this
  	 *                          list will be passed to subbranches.
  	 * @param globalVariablePointersMap the HashMap containig the highest level branch's (the trunk, or starting
  	 *                                   branch of the tree) variable pointers. Any varible delcared as public
  	 *                                   should have it's pointer added to this Map to ensure global scope.
  	 * @param localVariablePointersMap the HashMap containg pointers to variables relative to the current subbranch.
  	 *                                 Pointers added to this Map are not passed up the syntax tree as this list is
  	 *                                 cloned in subbranches to keep the security of variable scope. Pointers added
  	 *                                 to this list will be passed to subbranches.
  	 * @param depth the depth of the subbranch, currently used for debugging purposes. Likely to be removed.
  	 * @param branchLoopIndex the MutableInt represinting the looping index of the super branch. As tokens are used
  	 *                        by the subbranch, the super branch no longer needs to evalutate them becuase they only
  	 *                        belong to the subbranch. Evaluating them else where would cause the syntax tree to
  	 *                        redundant and wrong evlauations. A MutableInt is used to keep a pointer to the looping
  	 *                        index of the superbranch,incrementing it as the subbranch evlauated tokens. This
  	 *                        ensures when the subbranch has been evaluated, the superbranch will where to pick up
  	 *                        the evaluation process in teh ArrayList.
  	 * @return the syntax branch to be added to the syntax tree for evaluation.
  	 * @throws com.rayburn.engine.dew.DewException if the syntax rules of DewScript are violated or if the parser
  	 *                                             experiences an internal error, a DewException will be thrown.
  	 */
  	private static SyntaxBranch createBranch(DewLexer.LexicalTokens.LexicalToken branchTriggerToken,
  	                                         int branchTriggerTokenIndex,
  	                                         ArrayList<DewLexer.LexicalTokens.LexicalToken> lexicalTokens,
  	                                         ArrayList<ParseTokens.Variable> globalVariableList,
  	                                         ArrayList<ParseTokens.Variable> localVariableList,
  	                                         HashMap<String, Short> globalVariablePointersMap,
  	                                         HashMap<String, Short> localVariablePointersMap,
  	                                         short depth,
  	                                         MutableInt branchLoopIndex) throws DewException
  	{
  		parserLogger.log(Logger.LogLevel.INFO, "Creating subbranch @L" + depth);
  
  		/*
  		 * Check if the syntax tree has exceeded 32,768 branching levels. I don't anticipate any code reacing this
  		 * many sublevels, but this is primarily here to check the integrity DewParser and DewLexer algorithms. May
  		 * be commented out in the future or the branch level may be increased to Integer.MAX_VALUE.
  		 * This serves as an inital check for the validity of the branch.
  		 */
  		if (depth == Short.MAX_VALUE)
  		{
  			parserLogger.log(Logger.LogLevel.FATAL, "Syntax tree depth exceeded! (" + depth + ")");
  			parserLogger.log(Logger.LogLevel.INFO, "Is syntax error creating recursive depth problem?");
  			throw new DewException("Syntax tree depth exceeded. Quitting.");
  		}
  		depth++;
  
  		//initial check passed, create the new branch.
  		SyntaxBranch currentBranch = new SyntaxBranch();
  
  		if (!(branchTriggerToken instanceof DewLexer.LexicalTokens.SyntaticToken))
  		{
  			parserLogger.log(Logger.LogLevel.FATAL, "Branch entrancy token not of type SyntaxToken.");
  			throw new DewException("Invalid entrance token.");
  		}
  
  		/*
  		 * Given the entrance token, determine the corresponding token that will signal the branch to break,
  		 * ending the branch and stopping its execution.
  		 */
  		DewLexer.LexicalTokens.SyntaticToken.SyntaxElement endOfBranchElement = DewLexer.LexicalTokens.SyntaticToken
  				.SyntaxElement.END_OF_STATEMENT;
  		switch (((DewLexer.LexicalTokens.SyntaticToken) branchTriggerToken).getElement())
  		{
  			case START_OF_FILE:
  				endOfBranchElement = DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.END_OF_FILE;
  				break;
  			case STRUCTURE_IF:
  			case STRUCTURE_ELSEIF:
  			case STRUCTURE_ELSE:
  			case STRUCTURE_WHILE:
  			case STRUCTURE_FOR:
  				endOfBranchElement = DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.END_OF_STATEMENT;
  				break;
  			case DELIMITER_LEFT_BRACE:
  				endOfBranchElement = DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.DELIMITER_RIGHT_BRACE;
  				break;
  			case DELIMITER_LEFT_BRACK:
  				endOfBranchElement = DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.DELIMITER_RIGHT_BRACK;
  				break;
  			case DELIMITER_LEFT_PAREN:
  				endOfBranchElement = DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.DELIMITER_RIGHT_PAREN;
  				break;
  		}
  
  		parserLogger.log(Logger.LogLevel.INFO, "Exit token determined: " + endOfBranchElement.toString());
  
  		/*
  		 * Level specfic copies of resources are made to ensure branch level cnages are not carried up the syntax
  		 * tree, only down it. For example, if a local variable is created in a for loop, the scope of the variable
  		 * is limited to the context of the loop or any subcontexts below it. The variable's data and pointer
  		 * should not be accesssible to higher branches. Branch level copies are made to keep variable (and
  		 * eventually function) scope in check.
  		 */
  		@SuppressWarnings("unchecked")
  		ArrayList<DewLexer.LexicalTokens.LexicalToken> branchLexicalTokenSubset =
  				(ArrayList<DewLexer.LexicalTokens.LexicalToken>) lexicalTokens.clone();
  		@SuppressWarnings("unchecked")
  		ArrayList<ParseTokens.Variable> branchVariableSubset =
  				(ArrayList<ParseTokens.Variable>) localVariableList.clone();
  		@SuppressWarnings("unchecked")
  		HashMap<String, Short> branchVariablePointersSubset =
  				(HashMap<String, Short>) localVariablePointersMap.clone();
  
  		assert branchLexicalTokenSubset     != null;
  		assert branchVariableSubset         != null;
  		assert branchVariablePointersSubset != null;
  
  		//branch loop label to stop branch creation once the end of branch sequence has been reached
  		branchLoop:
  		//TODO minus 1 check
  		for (MutableInt index = branchLoopIndex; index.getValue() < lexicalTokens.size() - 1; index.increment())
  		{
  			branchLoopIndex.increment();
  
  			parserLogger.log(Logger.LogLevel.INFO, "Evaluating token: "
  					+ lexicalTokens.get(index.getValue()).toString());
  
  			//if the end of the branch has been reached, break and return the branch
  			if (lexicalTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.SyntaticToken
  					&& ((DewLexer.LexicalTokens.SyntaticToken) lexicalTokens.get(index.getValue())).getElement()
  					== endOfBranchElement)
  			{
  				parserLogger.log(Logger.LogLevel.INFO, "End of branch token found: "
  						+ endOfBranchElement.toString());
  				break;
  			}
  
  			//if the end of the block execution has been reached, break adn return the branch
  			if (lexicalTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.SyntaticToken
  					&& ((DewLexer.LexicalTokens.SyntaticToken) lexicalTokens.get(index.getValue())).getElement()
  					== DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.END_OF_BLOCK)
  			{
  				parserLogger.log(Logger.LogLevel.INFO, "End of block found.");
  				break;
  			}
  
  			/*
  			 * Check if a syntax element is present. If so, determine if its presence with the surroundings tokens
  			 * requires the creation of a subbranch.
  			 */
  			if (lexicalTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.SyntaticToken)
  			{
  				DewLexer.LexicalTokens.SyntaticToken.SyntaxElement syntaxElement =
  						((DewLexer.LexicalTokens.SyntaticToken) lexicalTokens.get(index.getValue())).getElement();
  
  				//TODO check security of removing this block
  				//if the end of the branch has been reached, break and return the branch
  				if (syntaxElement == endOfBranchElement)
  					break branchLoop;
  
  				switch (syntaxElement)
  				{
  					case END_OF_FILE: break branchLoop;
  					case END_OF_BLOCK: break branchLoop;
  					/*
  					 * A left brace signals a new scope and possible routine block. A new branch needs to be created
  					 * to handleKey this.
  					 */
  					case DELIMITER_LEFT_BRACE:
  					case DELIMITER_LEFT_BRACK:
  					case DELIMITER_LEFT_PAREN:
  						createBranch(lexicalTokens.get(index.getValue()),
  								index.getValue(),
  								lexicalTokens,
  								globalVariableList,
  								branchVariableSubset,
  								globalVariablePointersMap,
  								branchVariablePointersSubset,
  								depth,
  								index);
  						break;
  
  
  				}
  
  			}
  
  			/*
  			 * Check for variable declaration.
  			 */
  			if (lexicalTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.VariableDeclarationToken)
  			{
  				/*
  				 * Ensure a variable name follows the declaration token. If index + 1 (name token location) is
  				 * greater than the size of the list or its not a VariableNameToken, throw a parse exception.
  				 */
  				if (index.getValue() + 1 > lexicalTokens.size()
  						|| !(lexicalTokens.get(index.getValue() + 1) instanceof DewLexer.LexicalTokens.VariableNameToken))
  				{
  
  					parserLogger.log(Logger.LogLevel.FATAL, "Expected variable name: "
  							+ lexicalTokens.get(index.getValue()).toString());
  					throw new DewParseException("Expected variable name token following@" +
  							lexicalTokens.get(index.getValue()).toString());
  				}
  
  				/*
  				 * Ensure the maximum number of variables has not been exceeded. This is to ensure the pointer
  				 * system can accurtely point to the variable. The current number of variables is limited to
  				 * Short.MAX_VALUE and cannot be negative. Shorts are used to check the integrity of the pointer
  				 * system while the Interpreter is being tested. Once the stability is the system is verified the
  				 * number will be increased to Long.MAX_VALUE.
  				 */
  				if (branchVariableSubset.size() >= Short.MAX_VALUE)
  					throw new DewParseException(
  							"Max number of variables exceeded, cannot assign pointer to new variable@"
  									+ lexicalTokens.get(index.getValue()).toString());
  
  				DewLexer.LexicalTokens.VariableDeclarationToken decToken =
  						((DewLexer.LexicalTokens.VariableDeclarationToken) lexicalTokens.get(index.getValue()));
  				index.increment();
  				DewLexer.LexicalTokens.VariableNameToken nameToken =
  						((DewLexer.LexicalTokens.VariableNameToken) lexicalTokens.get(index.getValue()));
  				index.increment();
  
  				Set<String> keys = localVariablePointersMap.keySet();
  				for (String key : keys)
  					if (nameToken.getVariableName().equals(key))
  						throw new DewParseException("Variable name already defined in scope@"
  								+ nameToken.toString());
  
  				keys = branchVariablePointersSubset.keySet();
  				for (String key : keys)
  					if (nameToken.getVariableName().equals(key))
  						throw new DewParseException("Variable name already defined in scope@"
  								+ nameToken.toString());
  
  				keys = null;
  
  				//TODO check for global definition when internal global declaration feature is added
  
  				/*
  				 * Add the variables pointer map to the local maps list.
  				 */
  				branchVariablePointersSubset.put(
  						nameToken.getVariableName(), (short) branchVariableSubset.size());
  
  				switch (decToken.getVariableType())
  				{
  					case BOOL:
  						boolean boolValue = false;
  
  						if (index.getValue() <= lexicalTokens.size()
  								&& lexicalTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.SyntaticToken
  								&& ((DewLexer.LexicalTokens.SyntaticToken) lexicalTokens.get(index.getValue())).getElement()
  								== DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.OPERATOR_EQ)
  						{
  							index.increment();
  
  							ArrayList<DewLexer.LexicalTokens.LexicalToken> expressionTokens = new ArrayList<DewLexer.LexicalTokens.LexicalToken>();
  							while (index.getValue() <= lexicalTokens.size()
  									&& !(lexicalTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.SyntaticToken
  											&& ((DewLexer.LexicalTokens.SyntaticToken) lexicalTokens.get(index.getValue())).getElement()
  											== DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.END_OF_STATEMENT))
  							{
  								expressionTokens.add(lexicalTokens.get(index.getValue()));
  								index.increment();
  							}
  							index.increment(); //EOS increment
  
  							//value = ;
  						}
  
  						/*
  						 * Add a new boolean variable. Give it a pointer to the size of the local variable's list
  						 * size. Give it a default value of false.
  						 */
  						branchVariableSubset.add(new ParseTokens.Variable<Boolean>(
  								boolValue, Boolean.class, (short) branchVariableSubset.size()));
  						continue branchLoop;
  						//break;
  					case INT:
  						int intValue = 0;
  
  						/*
  						 * If an equals sign is the next token, calculate the value.
  						 */
  						if (index.getValue() <= lexicalTokens.size()
  								&& lexicalTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.SyntaticToken
  								&& ((DewLexer.LexicalTokens.SyntaticToken) lexicalTokens.get(index.getValue())).getElement()
  								== DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.OPERATOR_EQ)
  						{
  							index.increment();
  
  							/*
  							 * While the end of statement hasn't been reached, gather tokens as expression tokens.
  							 */
  							ArrayList<DewLexer.LexicalTokens.LexicalToken> expressionTokens = new ArrayList<DewLexer.LexicalTokens.LexicalToken>();
  							while (index.getValue() <= lexicalTokens.size()
  									&& !(lexicalTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.SyntaticToken
  									&& ((DewLexer.LexicalTokens.SyntaticToken) lexicalTokens.get(index.getValue())).getElement()
  									== DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.END_OF_STATEMENT))
  							{
  								expressionTokens.add(lexicalTokens.get(index.getValue()));
  								index.increment();
  							}
  							index.decrement();
  
  							boolean canEvalIntExp = canEvaluateNaturalMathToConstant(expressionTokens,
  									globalVariableList,
  									localVariableList,
  									globalVariablePointersMap,
  									localVariablePointersMap,
  									parserLogger);
  
  							if(canEvalIntExp)
  							{
  								parserLogger.log(Logger.LogLevel.INFO, "Found RPN sequence that can be evaluated " +
  										"as a constant...");
  								LinkedList<DewInterpreter.Token> expressionQueue = convertNaturalMathToRPN(expressionTokens,
  									globalVariableList,
  									localVariableList,
  									globalVariablePointersMap,
  									localVariablePointersMap,
  									parserLogger);
  								intValue = Integer.parseInt(evalRPN(expressionQueue,
  										globalVariableList,
  										localVariableList,
  										Integer.class,
  										parserLogger).toString());
  								parserLogger.log(Logger.LogLevel.INFO, "Added int variable with value " + intValue);
  
  							}
  						}
  
  						/*
  						 * Add a new int variable. Give it a pointer to the size of the local variable's list
  						 * size. Give it a default value of 0.
  						 */
  						branchVariableSubset.add(new ParseTokens.Variable<Integer>(
  								intValue,
  								Integer.class,
  								(short) branchVariableSubset.size()));
  
  						continue branchLoop;
  					case FLOAT:
  						float floatValue = 0f;
  
  						/*
  						 * If an equals sign is the next token, calculate the value.
  						 */
  						if (index.getValue() <= lexicalTokens.size()
  								&& lexicalTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.SyntaticToken
  								&& ((DewLexer.LexicalTokens.SyntaticToken) lexicalTokens.get(index.getValue())).getElement()
  								== DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.OPERATOR_EQ)
  						{
  							index.increment();
  
  							/*
  							 * While the end of statement hasn't been reached, gather tokens as expression tokens.
  							 */
  							ArrayList<DewLexer.LexicalTokens.LexicalToken> expressionTokens = new ArrayList<DewLexer.LexicalTokens.LexicalToken>();
  							while (index.getValue() <= lexicalTokens.size()
  									&& !(lexicalTokens.get(index.getValue()) instanceof DewLexer.LexicalTokens.SyntaticToken
  									&& ((DewLexer.LexicalTokens.SyntaticToken) lexicalTokens.get(index.getValue())).getElement()
  									== DewLexer.LexicalTokens.SyntaticToken.SyntaxElement.END_OF_STATEMENT))
  							{
  								expressionTokens.add(lexicalTokens.get(index.getValue()));
  								index.increment();
  							}
  							index.decrement();
  
  							boolean canEvalFloatExp = canEvaluateNaturalMathToConstant(expressionTokens,
  									globalVariableList,
  									localVariableList,
  									globalVariablePointersMap,
  									localVariablePointersMap,
  									parserLogger);
  
  							if(canEvalFloatExp)
  							{
  								parserLogger.log(Logger.LogLevel.INFO, "Found RPN sequence that can be evaluated " +
  										"as a constant...");
  								LinkedList<DewInterpreter.Token> expressionQueue = convertNaturalMathToRPN(expressionTokens,
  										globalVariableList,
  										localVariableList,
  										globalVariablePointersMap,
  										localVariablePointersMap,
  										parserLogger);
  								floatValue = Float.parseFloat(evalRPN(expressionQueue,
  										globalVariableList,
  										localVariableList,
  										Float.class,
  										parserLogger).toString());
  								parserLogger.log(Logger.LogLevel.INFO, "Added float variable with value " + floatValue);
  
  							}
  						}
  
  						/*
  						 * Add a new float variable. Give it a pointer to the size of the local variable's list
  						 * size. Give it a default value of 0f.
  						 */
  						branchVariableSubset.add(new ParseTokens.Variable<Float>(
  								floatValue,
  								Float.class,
  								(short) branchVariableSubset.size()));
  						continue branchLoop;
  						//break;
  					case CHAR:
  						/*
  						 * Add a new char variable. Give it a pointer to the size of the local variable's list
  						 * size. Give it a default value of \0.
  						 */
  						branchVariableSubset.add(new ParseTokens.Variable<Character>(
  								'\0', Character.class, (short) branchVariableSubset.size()));
  						continue branchLoop;
  						//break;
  					case STRING:
  					default:
  						/*
  						 * Add a new String variable. Give it a pointer to the size of the local variable's list
  						 * size. Give it a default value of "".
  						 */
  						branchVariableSubset.add(new ParseTokens.Variable<String>(
  								"", String.class, (short) branchVariableSubset.size()));
  						continue branchLoop;
  						//break;
  				}
  
  
  			}
  
  			//if ()
  
  		}
  
  		//return the branch
  		return currentBranch;
  	}
  
  	public AlgebraicExpressionBranch createExpressionBranch()
  	{
  		return null;
  	}
  
  
  	///////////////////////////////
  	//  inner class declaration  //
  	///////////////////////////////
  
  	/**
  	 * @author guyfleeman
  	 * @date 03/03/14
  	 * This class contains the syntactical branch for the interpreter to interpret
  	 */
  	public static class SyntaxBranch implements BranchElement
  	{
  		private ArrayList<BranchElement>                   branchElements;
  		private ArrayList<ArrayList<ParseTokens.Variable>> variables;
  
  		public void call()
  		{
  			for (BranchElement branchElement : branchElements)
  				branchElement.call();
  		}
  	}
  
  	/**
  	 * This class represents a branch that can be attached to the abstract syntax tree, and be evaluated at runtime.
  	 * This class represents an algebraic expression branch, converted from infix (natural language) to postfix
  	 * (reverse polish notation) queue for computational evaluation at runtime. Computers can't evaluate infix, so
  	 * infix is changed to postfix at the parse stage, and queue up for evaluation in an instance of this object.
  	 */
  	public static class AlgebraicExpressionBranch implements BranchElement
  	{
  		/**
  		 * The expression queue to be evaluated at runtime.
  		 */
  		private final LinkedList<DewLexer.LexicalTokens.LexicalToken> expressionQueue;
  
  		/**
  		 * The global varables list.
  		 */
  		private final ArrayList<ParseTokens.Variable> globalVariableList;
  
  		/**
  		 * The local variables list.
  		 */
  		private final ArrayList<ParseTokens.Variable> localVariableList;
  
  		/**
  		 * The global pointers map.
  		 */
  		private final HashMap<String, Short> globalVariablePointersMap;
  
  		/**
  		 * The local pointers map.
  		 */
  		private final HashMap<String, Short> localVariablePointersMap;
  
  		/**
  		 * The value of the expression. Will be set at the earliest possible opportunity.
  		 */
  		private Object value = null;
  
  		/**
  		 *
  		 * @param expressionQueue the expression queue
  		 * @param globalVariableList the global variables list
  		 * @param localVariableList the local variables list
  		 * @param globalVariablePointersMap the global pointers map
  		 * @param localVariablePointersMap the local pointers map
  		 */
  		public AlgebraicExpressionBranch(LinkedList<DewLexer.LexicalTokens.LexicalToken> expressionQueue,
  		                                 ArrayList<ParseTokens.Variable> globalVariableList,
  		                                 ArrayList<ParseTokens.Variable> localVariableList,
  		                                 HashMap<String, Short> globalVariablePointersMap,
  		                                 HashMap<String, Short> localVariablePointersMap)
  		{
  			this.expressionQueue = expressionQueue;
  			this.globalVariableList = globalVariableList;
  			this.localVariableList = localVariableList;
  			this.globalVariablePointersMap = globalVariablePointersMap;
  			this.localVariablePointersMap = localVariablePointersMap;
  		}
  
  		/**
  		 * Calls the branch to update value
  		 */
  		public void call()
  		{
  			value = getValue();
  		}
  
  		/**
  		 * @return the value of the branch at runtime
  		 */
  		public Object getValue()
  		{
  			return null;
  		}
  
  		/**
  		 * Check to see if a natural math expression can be evaluated as a constant (only constants and final vars)
  		 * @param expressionTokens the tokens the describe the algebraic expression
  		 * @param globalVariables global variables
  		 * @param localVariables local variables
  		 * @param globalPointers global pointers
  		 * @param localPointers local pointers
  		 * @return if the expression can be evaluated as a constant
  		 */
  		public static boolean canEvaluateNaturalMathToConstant(ArrayList<DewLexer.LexicalTokens.LexicalToken>
  				                                                       expressionTokens,
  		                                                       ArrayList<ParseTokens.Variable> globalVariables,
  		                                                       ArrayList<ParseTokens.Variable> localVariables,
  		                                                       HashMap<String, Short> globalPointers,
  		                                                       HashMap<String, Short> localPointers,
  		                                                       Logger logger)
  		{
  			/*
  			 * If any necessary resources are null, return false.
  			 */
  			if (globalVariables == null
  					|| localVariables == null
  					|| globalPointers == null
  					|| localPointers == null)
  			{
  				logger.log(Logger.LogLevel.WARNING, "Found essential null paramaters in RPN constant eval check. " +
  						"Returning false");
  				return false;
  			}
  
  			expressionLoop:
  			for (DewLexer.LexicalTokens.LexicalToken token : expressionTokens)
  			{
  				/*
  				 * If the token is SyntacticToken and does not represent a valid expression syntactic element,
  				 * return false.
  				 */
  				if (token instanceof DewLexer.LexicalTokens.SyntaticToken)
  				{
  					DewLexer.LexicalTokens.SyntaticToken syntacticToken = (DewLexer.LexicalTokens.SyntaticToken) token;
  
  					if (syntacticToken.getElement() != DewLexer.LexicalTokens.SyntaticToken.SyntaxElement
  							.OPERATOR_MATH_MUL
  							&& syntacticToken.getElement() != DewLexer.LexicalTokens.SyntaticToken.SyntaxElement
  							.OPERATOR_MATH_DIV
  							&& syntacticToken.getElement() != DewLexer.LexicalTokens.SyntaticToken.SyntaxElement
  							.OPERATOR_MATH_MOD
  							&& syntacticToken.getElement() != DewLexer.LexicalTokens.SyntaticToken.SyntaxElement
  							.OPERATOR_MATH_ADD
  							&& syntacticToken.getElement() != DewLexer.LexicalTokens.SyntaticToken.SyntaxElement
  							.OPERATOR_MATH_SUB
  							&& syntacticToken.getElement() != DewLexer.LexicalTokens.SyntaticToken.SyntaxElement
  							.DELIMITER_LEFT_PAREN
  							&& syntacticToken.getElement() != DewLexer.LexicalTokens.SyntaticToken.SyntaxElement
  							.DELIMITER_RIGHT_PAREN)
  					{
  						logger.log(Logger.LogLevel.INFO, "Found invalid syntax element in RPN constant eval " +
  								"check. Returning false");
  						return false;
  					}
  				}
  				else if (token instanceof DewLexer.LexicalTokens.DataLiteralToken)
  				{
  					DewLexer.LexicalTokens.DataLiteralToken dataToken = (DewLexer.LexicalTokens.DataLiteralToken)
  							token;
  
  					/*
  					 * If the token is a number, its okay. Else do further analysis.
  					 */
  					if (isNumber(dataToken))
  					{
  						logger.log(Logger.LogLevel.INFO, "Found numeric literal in expression. Continuing.");
  					}
  					else
  					{
  						logger.log(Logger.LogLevel.INFO, "Found non numeric literal in expression. Continuing " +
  								"evaluation.");
  
  						/*
  						 * If the pointers map is empty, this literal cant be a valid variable, so the expression
  						 * cannot be evaluated to a constant.
  						 */
  						if (globalPointers.isEmpty() && localPointers.isEmpty())
  						{
  							logger.log(Logger.LogLevel.WARNING, "Found empty pointer maps. Cannot map literal. " +
  									"Returning false");
  							return false;
  						}
  
  						/*
  						 * If there is no match for the literal, it can't be valid and can't be evaluated to a
  						 * constant. Return false;
  						 */
  