public string Execute() { MemoryStream stream = new MemoryStream(); ExecutionState state = new ExecutionState(stream); try { instruction.Execute(state); stream.Seek(0, SeekOrigin.Begin); using (StreamReader reader = new StreamReader(stream)) return reader.ReadToEnd(); } catch (InstructionExecutionException ex) { return GetErrorHTML(ex.Message, ex.Token); } }
public bool Execute(ExecutionState state) { foreach (IInstruction instruction in list) if (!instruction.Execute(state)) return false; return true; }
public bool Execute(ExecutionState state) { string text = expression.Evaluate(state).ToString(); state.Output.Write(text); return true; }
protected override object Evaluate(IExpression left, IExpression right, ExecutionState state) { object b = right.Evaluate(state); object a = left.Evaluate(state); decimal x, y; if (a is decimal) x = (decimal)a; else { TypeConverter tc = TypeDescriptor.GetConverter(a); if (!tc.CanConvertTo(typeof(decimal))) return string.Concat(a, b); x = (decimal)tc.ConvertTo(a, typeof(decimal)); } if (b is decimal) y = (decimal)b; else { TypeConverter tc = TypeDescriptor.GetConverter(b); if (!tc.CanConvertTo(typeof(decimal))) return string.Concat(a, b); y = (decimal)tc.ConvertTo(b, typeof(decimal)); } return x + y; }
public object Evaluate(ExecutionState state) { return value; }
public object Evaluate(ExecutionState state) { return text; }
protected override object Evaluate(IExpression left, IExpression right, ExecutionState state) { object b = right.Evaluate(state); object a = left.Evaluate(state); return !(a.Equals(b) || b.Equals(a)); // we check both sides in case one side has overridden the Equals method }
public object Evaluate(ExecutionState state) { return new NotValue(expression.Evaluate(state)); }
protected override object Evaluate(IExpression left, IExpression right, ExecutionState state) { object b = right.Evaluate(state); object a = left.Evaluate(state); decimal x, y; if (a is decimal) x = (decimal)a; else { TypeConverter tc = TypeDescriptor.GetConverter(a); if (!tc.CanConvertTo(typeof(decimal))) ThrowException(); x = (decimal)tc.ConvertTo(a, typeof(decimal)); } if (b is decimal) y = (decimal)b; else { TypeConverter tc = TypeDescriptor.GetConverter(b); if (!tc.CanConvertTo(typeof(decimal))) ThrowException(); y = (decimal)tc.ConvertTo(b, typeof(decimal)); } if (y == 0) throw new InstructionExecutionException("I can't divide the first number by the second because the second is zero. i.e. Noone can divide by zero. Not even me.", token); return x / y; }
public object Evaluate(ExecutionState state) { if(expr != null) o = expr.Evaluate(state); return new SoftBoolean(!(o.Equals(0m) || o.Equals(null) || o.Equals("") || o.Equals(false))); }
protected abstract object Evaluate(IExpression left, IExpression right, ExecutionState state);
public object Evaluate(ExecutionState state) { return Evaluate(left, right, state); }
protected override object Evaluate(IExpression left, IExpression right, ExecutionState state) { if (!(left is BooleanExpression)) left = new BooleanExpression(left); if (!(right is BooleanExpression)) right = new BooleanExpression(right); return left.Evaluate(state).Equals(true) && right.Evaluate(state).Equals(true); }