Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
WhileDo.cs
1using System;
2using System.Threading.Tasks;
7
9{
13 public class WhileDo : BinaryOperator
14 {
23 public WhileDo(ScriptNode Condition, ScriptNode Statement, int Start, int Length, Expression Expression)
24 : base(Condition, Statement, Start, Length, Expression)
25 {
26 }
27
34 {
35 IElement Last = null;
36 BooleanValue Condition;
37
38 Condition = this.left.Evaluate(Variables) as BooleanValue;
39 if (Condition is null)
40 throw new ScriptRuntimeException("Condition must evaluate to a boolean value.", this);
41
42 while (Condition.Value)
43 {
44 Last = this.right.Evaluate(Variables);
45
46 Condition = this.left.Evaluate(Variables) as BooleanValue;
47 if (Condition is null)
48 throw new ScriptRuntimeException("Condition must evaluate to a boolean value.", this);
49 }
50
51 if (Last is null)
52 return ObjectValue.Null;
53 else
54 return Last;
55 }
56
62 public override async Task<IElement> EvaluateAsync(Variables Variables)
63 {
64 if (!this.isAsync)
65 return this.Evaluate(Variables);
66
67 IElement Last = null;
68 BooleanValue Condition;
69
70 Condition = await this.left.EvaluateAsync(Variables) as BooleanValue;
71 if (Condition is null)
72 throw new ScriptRuntimeException("Condition must evaluate to a boolean value.", this);
73
74 while (Condition.Value)
75 {
76 Last = await this.right.EvaluateAsync(Variables);
77
78 Condition = await this.left.EvaluateAsync(Variables) as BooleanValue;
79 if (Condition is null)
80 throw new ScriptRuntimeException("Condition must evaluate to a boolean value.", this);
81 }
82
83 if (Last is null)
84 return ObjectValue.Null;
85 else
86 return Last;
87 }
88 }
89}
Class managing a script expression.
Definition: Expression.cs:39
Base class for all binary operators.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Definition: ScriptNode.cs:158
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly ObjectValue Null
Null value.
Definition: ObjectValue.cs:86
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: WhileDo.cs:33
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: WhileDo.cs:62
WhileDo(ScriptNode Condition, ScriptNode Statement, int Start, int Length, Expression Expression)
WHILE-DO operator.
Definition: WhileDo.cs:23
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20