public void AddEndif(int line, int pos, string value) { var instruction = new Interpreter.InterpreterInstructionNoOp(line, pos, value, new Interpreter.Evaluator.NoOpEvaluator()); // determine if there was a previous else - if so set its first instruction's next to here // if there was no else, set the alternative of the closest if to this instruction // so need to find the closest if that has an open alternative or the closest else that has no next yet var closestIfOrElse = ifElseStack.Count > 0 ? ifElseStack.Pop() : null; if (closestIfOrElse != null) { if (closestIfOrElse.GetType() == typeof(Interpreter.InterpreterInstructionBranch)) { // this was an if without else (closestIfOrElse as Interpreter.InterpreterInstructionBranch).Alternative = instruction; (closestIfOrElse as Interpreter.InterpreterInstructionBranch).EndBranch = instruction; } else { // this was an else closestIfOrElse.Next = instruction; } AddInstruction(instruction); DebugInstruction("EndIf", instruction); } else { logger.Error("EndIf without matching If or Else on line {0} - {1} ({2})", line, pos, value); } }
public void AddElse(int line, int pos, string value) { var instruction = new Interpreter.InterpreterInstructionNoOp(line, pos, value, new Interpreter.Evaluator.NoOpEvaluator()); var instruction2 = new Interpreter.InterpreterInstructionNoOp(line, pos, value, new Interpreter.Evaluator.NoOpEvaluator()); var prevIf = ifElseStack.Count > 0 ? ifElseStack.Pop() as InterpreterInstructionBranch : null; if (prevIf != null) { AddInstruction(instruction); AddInstruction(instruction2); prevIf.Alternative = instruction2; ifElseStack.Push(instruction); // set to null so that the next instruction will link to this one and not to instruction2 instruction.Next = null; DebugInstruction("Else", instruction); } else { logger.Error("Else without matching If on line {0} - {1} ({2})", line, pos, value); } }
public void AddLogInstruction(int line, int pos, string logType, string value) { var evaluator = new Interpreter.Evaluator.EvaluateLogging(logType); var instruction = new Interpreter.InterpreterInstructionNoOp(line, pos, value, evaluator); AddInstruction(instruction); DebugInstruction(logType, instruction); }
public void AddLoop(int line, int pos, string value) { var instruction1 = new Interpreter.InterpreterInstructionNoOp(line, pos, value, new Interpreter.Evaluator.EnterLoopEvaluator()); var instruction2 = new Interpreter.InterpreterInstructionBranch(line, pos, value, new Interpreter.Evaluator.LoopEvaluator()); AddInstruction(instruction1); AddInstruction(instruction2); loopStack.Push(instruction2); DebugInstruction("Loop", instruction2); }
public void AddEndFile(int line, int pos, string value) { var instruction = new Interpreter.InterpreterInstructionNoOp(line, pos, value, new Interpreter.Evaluator.EvaluateEndFile()); if (LastFileCreateInstruction != null) { LastFileCreateInstruction.Alternative = instruction; LastFileCreateInstruction = null; } AddInstruction(instruction); DebugInstruction("EndFile", instruction); }
public void AddEndLoop(int line, int pos, string value) { var instruction1 = new Interpreter.InterpreterInstructionNoOp(line, pos, value, new Interpreter.Evaluator.NoOpEvaluator()); var instruction2 = new Interpreter.InterpreterInstructionNoOp(line, pos, value, new Interpreter.Evaluator.ExitLoopEvaluator()); var closestLoop = loopStack.Count > 0 ? loopStack.Pop() : null; if (closestLoop != null) { AddInstruction(instruction1); AddInstruction(instruction2); instruction1.Next = closestLoop; closestLoop.Alternative = instruction2; closestLoop.EndBranch = instruction2; DebugInstruction("EndLoop", instruction1); } else { logger.Error("End loop without matching Loop on line {0} - {1} ({2})", line, pos, value); } }