public override dynamic Execute(Ast_Scope scope) { var child = scope.CreateChild("while.execute"); child.IsLoop = true; child.InLoop = true; while (child.InLoop) { var value = Expression.Execute(scope); if (value == true || (value != null && value != false && value != 0)) { foreach (Ast_Base fi in Block) { var res = fi.Execute(child); if (res == true || res is Ast_Terminate) { child.InLoop = false; return(true); } } } else { child.InLoop = false; } } return(false); }
public override dynamic Execute(Ast_Scope scope) { var value = Expression.Execute(scope); if (value == true || (value != null && value != false && value != 0)) { return(ExecuteElif(scope)); } return(false); }
public override dynamic Execute(Ast_Scope scope) { var res = new List <dynamic>(); foreach (var expr in Block) { Ast_Expression expression = expr as Ast_Expression; res.Add(expression.Execute(scope)); } return(res); }
public override dynamic Execute(Ast_Scope scope) { var value = Exitcode.Execute(scope); var estr = $"Program terminated at {Token.Line}, {Token.Offset}. Exit code: {value}."; var v = scope.Variables["exitcode"]; if (v == null) { v = new Ast_Variable(null) { Name = "exitcode" }; scope.Variables.Add(v); } v.DoSetValue(estr); return(Ast_Terminate.Halt); }
public override dynamic Execute(Ast_Scope scope) { var value = Expression.Execute(scope); if (value == true || (value != null && value != false && value != 0)) { return(ExecuteIf(scope)); } if (ElIf?.Block.Count > 0 && ExecuteElifBlock(scope)) { return(false); } if (Else?.Block.Count > 0) { Else.Execute(scope); } return(false); }
public override dynamic Execute(Ast_Scope scope) { dynamic value = Expression.Execute(scope); if (value is Ast_Procedure procedure) { value = procedure.Clone(Variable.Token); } else if (value is Ast_Function function) { value = function.Clone(Variable.Token); } else if (value is Ast_Struct strct) { value = strct.Clone(Variable.Token); } else if (value is List <VT_Any> ) { value = CloneArray(value); } else if (value is Dictionary <string, VT_Any> ) { value = CloneRecord(value); } dynamic index = null; if (Variable.Index != null) { index = Variable.Index; } Ast_Variable ScopeVar; var ve = scope.VariableExists(Variable.Name); if (!ve) { ScopeVar = scope.Variables.Append(Variable.Name, value); } else { ScopeVar = scope.GetVariable(Variable.Name); } if (index != null) { dynamic indexedv = null; if (Operand.Type != TokenType.OpAssign) { indexedv = ScopeVar.DoGetValue(index, scope); } switch (Operand.Type) { case TokenType.OpAssign: ScopeVar.DoSetValue(value, index, scope); break; case TokenType.OpAssignAdd: ScopeVar.DoSetValue(indexedv + value, index, scope); break; case TokenType.OpAssignDivide: if (value == 0) { throw new RuntimeError(Token, "Division by zero."); } ScopeVar.DoSetValue(indexedv / value, index, scope); break; case TokenType.OpAssignMultiply: ScopeVar.DoSetValue(indexedv * value, index, scope); break; case TokenType.OpAssignSubtract: ScopeVar.DoSetValue(indexedv - value, index, scope); break; } } else { dynamic v = null; if (Operand.Type != TokenType.OpAssign) { v = ScopeVar.DoGetValue(); } switch (Operand.Type) { case TokenType.OpAssign: ScopeVar.DoSetValue(value); break; case TokenType.OpAssignAdd: ScopeVar.DoSetValue(v + value); break; case TokenType.OpAssignDivide: if (value == 0) { throw new RuntimeError(Token, "Division by zero."); } ScopeVar.DoSetValue(v / value); break; case TokenType.OpAssignMultiply: ScopeVar.DoSetValue(v * value); break; case TokenType.OpAssignSubtract: ScopeVar.DoSetValue(v - value); break; } } return(false); }