Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DoWhile.cs
1using System;
2using System.Threading.Tasks;
7
9{
13 public class DoWhile : BinaryOperator
14 {
23 public DoWhile(ScriptNode Statement, ScriptNode Condition, int Start, int Length, Expression Expression)
24 : base(Statement, Condition, Start, Length, Expression)
25 {
26 }
27
34 {
35 IElement Last;
36 BooleanValue Condition;
37
38 do
39 {
40 Last = this.left.Evaluate(Variables);
41
42 Condition = this.right.Evaluate(Variables) as BooleanValue;
43 if (Condition is null)
44 throw new ScriptRuntimeException("Condition must evaluate to a boolean value.", this);
45 }
46 while (Condition.Value);
47
48 return Last;
49 }
50
56 public override async Task<IElement> EvaluateAsync(Variables Variables)
57 {
58 if (!this.isAsync)
59 return this.Evaluate(Variables);
60
61 IElement Last;
62 BooleanValue Condition;
63
64 do
65 {
66 Last = await this.left.EvaluateAsync(Variables);
67
68 Condition = await this.right.EvaluateAsync(Variables) as BooleanValue;
69 if (Condition is null)
70 throw new ScriptRuntimeException("Condition must evaluate to a boolean value.", this);
71 }
72 while (Condition.Value);
73
74 return Last;
75 }
76 }
77}
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
DoWhile(ScriptNode Statement, ScriptNode Condition, int Start, int Length, Expression Expression)
DO-WHILE operator.
Definition: DoWhile.cs:23
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: DoWhile.cs:56
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: DoWhile.cs:33
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20