예제 #1
0
 // installation hook to re-direct the output to some
 // arbitrary location
 public void redirect(LineConsumer redirection)
 {
     lock (line)
     {
         this.redirection = redirection;
     }
 }
예제 #2
0
 public void Redirect(LineConsumer r)
 {
     lock (line)
     {
         this.redirection = r;
     }
 }
예제 #3
0
        public void TestSingleLine()
        {
            {	// simple int
                string[] strings = { "5" };
                LineConsumer lines = new LineConsumer(strings);
                IScope scope = CreateScope();
                Value value = EvalLines.Do(lines, scope);
                Assert.AreEqual(5, value.AsInt);
            }

            {	// function
                string[] strings = { "subtract [ 7 4 ]" };
                LineConsumer lines = new LineConsumer(strings);
                IScope scope = CreateScope();
                Value value = EvalLines.Do(lines, scope);
                Assert.AreEqual(3, value.AsInt);
            }

            #if false
            {	// functions
                string[] strings = { "subtract [ 7 subtract [ 15 11 ] ]" };
                LineConsumer lines = new LineConsumer(strings);
                IScope scope = CreateScope();
                Value value = EvalLines.Do(lines, scope);
                Assert.AreEqual(3, value.AsInt);
            }
            #endif
        }
예제 #4
0
 public void TestNestedBodies()
 {
     {	// 5 + (3 + 4) + 7
         string[] strings = { "add", " 5", " add", "  3", "  4", " 7" };
         LineConsumer lines = new LineConsumer(strings);
         IScope scope = CreateScope();
         Value value = EvalLines.Do(lines, scope);
         Assert.AreEqual(19, value.AsInt);
     }
 }
예제 #5
0
 public void TestBody()
 {
     {
         string[] strings = { "add", " 5", " 4" };
         LineConsumer lines = new LineConsumer(strings);
         IScope scope = CreateScope();
         Value value = EvalLines.Do(lines, scope);
         Assert.AreEqual(9, value.AsInt);
     }
 }
예제 #6
0
 public PrintStream(bool iserr) : base()
 {
     this.iserr       = iserr;
     this.line        = new System.Text.StringBuilder();
     this.redirection = null;
 }
예제 #7
0
 internal override Value Eval(Value arg, IScope scope)
 {
     List<DelimiterList> body = ValueFunction.ExtractBody(arg);
     LineConsumer consumer = new LineConsumer(body);
     int total = 0;
     while (consumer.HasCurrent())
     {
         Value value = EvalLines.DoOne(consumer, scope);
         total += value.AsInt;
     }
     return new ValueInt(total);
 }