Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
VectorDoWhileDefinition.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
8
10{
15 {
24 : base(Elements.LeftOperand, Elements.RightOperand, Start, Length, Expression)
25 {
26 }
27
34 {
35 LinkedList<IElement> Elements = new LinkedList<IElement>();
36 BooleanValue Condition;
37
38 do
39 {
40 Elements.AddLast(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 this.Encapsulate(Elements);
49 }
50
56 public override async Task<IElement> EvaluateAsync(Variables Variables)
57 {
58 if (!this.isAsync)
59 return this.Evaluate(Variables);
60
61 LinkedList<IElement> Elements = new LinkedList<IElement>();
62 BooleanValue Condition;
63
64 do
65 {
66 Elements.AddLast(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 this.Encapsulate(Elements);
75 }
76
82 protected virtual IElement Encapsulate(LinkedList<IElement> Elements)
83 {
84 return VectorDefinition.Encapsulate(Elements, true, this);
85 }
86
87 }
88}
Class managing a script expression.
Definition: Expression.cs:39
Base class for all binary operators.
ScriptNode RightOperand
Right operand.
ScriptNode LeftOperand
Left operand.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
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 IElement Encapsulate(Array Elements, bool CanEncapsulateAsMatrix, ScriptNode Node)
Encapsulates the elements of a vector.
Creates a vector using a DO-WHILE statement.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
virtual IElement Encapsulate(LinkedList< IElement > Elements)
Encapsulates the calculated elements.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
VectorDoWhileDefinition(DoWhile Elements, int Start, int Length, Expression Expression)
Creates a vector using a DO-WHILE statement.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20