private IfCode GetIfCode(XElement element) { var result = new IfCode(); XElement elementCondition = element.Child("If.Condition"); result.Condition = GetValueOfArgument(elementCondition.Elements().FirstOrDefault()); XElement elementThen = element.Child("If.Then"); if (elementThen != null) { result.Then = Parse(elementThen.Elements().FirstOrDefault())?.WrapInSequence(); } else { result.Then = new Sequence(); } XElement elementElse = element.Child("If.Else"); if (elementElse != null) { result.Else = Parse(elementElse.Elements().FirstOrDefault())?.WrapInSequence(); } // TODO: elseif return(result); }
private void WriteIfCode(StringWriter writer, IfCode ifCode, int tabs) { writer.WriteLineTabs($"if ({ifCode.Condition})", tabs); WriteConstruction(writer, ifCode.Then, tabs + 1); if (ifCode.Else != null) { writer.WriteLineTabs("else", tabs); WriteConstruction(writer, ifCode.Else, tabs + 1); } }
public void Interpret() { if (Interpreter.Interpret(this, Condition).value is bool condition) { if (condition) { IfCode.Interpret(); } else { ElseCode?.Interpret(); } } else { throw new ArgumentException("Logical expression was expected"); } }
public void Print(int offset = 0) { for (int i = 0; i < offset; i++) { Console.Write(" "); } Console.WriteLine($"ConditionBlock {{{string.Join(" ", Condition.Traverse())}}}:"); IfCode.Print(offset + 1); if (ElseCode != null) { for (var i = 0; i < offset; i++) { Console.Write(" "); } Console.WriteLine("ElseCode:"); ElseCode.Print(offset + 1); } }