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);
     }
 }
Example #2
0
 public bool Execute(ExecutionState state)
 {
     foreach (IInstruction instruction in list)
         if (!instruction.Execute(state))
             return false;
     return true;
 }
Example #3
0
 public bool Execute(ExecutionState state)
 {
     string text = expression.Evaluate(state).ToString();
     state.Output.Write(text);
     return true;
 }
Example #4
0
 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;
 }
Example #5
0
 public object Evaluate(ExecutionState state)
 {
     return value;
 }
Example #6
0
 public object Evaluate(ExecutionState state)
 {
     return text;
 }
Example #7
0
 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
 }
Example #8
0
 public object Evaluate(ExecutionState state)
 {
     return new NotValue(expression.Evaluate(state));
 }
Example #9
0
 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;
 }
Example #10
0
 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)));
 }
Example #11
0
 protected abstract object Evaluate(IExpression left, IExpression right, ExecutionState state);
Example #12
0
 public object Evaluate(ExecutionState state)
 {
     return Evaluate(left, right, state);
 }
Example #13
0
 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);
 }