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