public static void ParseNot(ToffeeGenerator generator, string[] args) { // Do we have the correct arguments? if (args.Length != 1) { throw new ToffeeGeneratorException("Invalid number of arguments for 'if' command."); } IfCommand command = new IfCommand(args[0], true); ToffeeGeneratorStackFrame handle = new ToffeeGeneratorStackFrame("if"); handle.State = command; command.TrueCode = handle.Commands; generator.AddCommand(command); generator.Stack.Push(handle); generator.Log("Enter If Block (Condition: {0})", args[0]); }
public static void ParseElseIf(ToffeeGenerator generator, string[] args) { // Do we have the correct arguments? if (args.Length != 1) { throw new ToffeeGeneratorException("Invalid number of arguments for 'elseif' command."); } // Could we even be in an if block? if (generator.Stack.Count < 2) { throw new ToffeeGeneratorException("Encountered 'elseif' command without being inside an if block."); } // Are we in an if block? if (generator.Stack.Peek().Name != "if") { throw new ToffeeGeneratorException("Encountered 'elseif' command instead of 'endpattern'"); } // Get the last stack handle (The If block) ToffeeGeneratorStackFrame handle = generator.Stack.Pop(); // Create an else handle (This will be the ElseIf block) ToffeeGeneratorStackFrame elseHandle = new ToffeeGeneratorStackFrame("if"); // Set the state of the Else handle to the same state as the If handle // (They are both part of the same IfCommand) elseHandle.State = handle.State; // Get the original If command, and set the ConditionFalse to the Else handle's commands IfCommand command = (IfCommand)handle.State; command.FalseCode = elseHandle.Commands; // Push the else handle onto the stack generator.Stack.Push(elseHandle); generator.Log("Exit If, Enter Else Block (Condition: {0})", ((IfCommand)handle.State).Define); // Parse the "elseif" as if it was an "if" // The IfCommand will be placed into the Else block for this If, creating an Else If Parse(generator, args); // The IfCommand that was just added onto the stack has created via ElseIf ((IfCommand)generator.Stack.Peek().State).WasElseIf = true; }