Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PreIncrement.cs
1using System;
2using System.Collections.Generic;
7
9{
14 {
24 {
25 }
26
33 {
34 if (!Variables.TryGetVariable(this.variableName, out Variable v))
35 throw new ScriptRuntimeException("Variable not found: " + this.variableName, this);
36
37 IElement Value = v.ValueElement;
38
39 if (Value.AssociatedObjectValue is double d)
40 Value = new DoubleNumber(d + 1);
41 else
42 Value = Increment(Value, this);
43
44 Variables[this.variableName] = Value;
45
46 return Value;
47 }
48
55 public static IElement Increment(IElement Value, ScriptNode Node)
56 {
58 return Operators.Arithmetics.Add.EvaluateAddition(Value, e.One, Node);
59 else if (Value.IsScalar)
60 throw new ScriptRuntimeException("Unable to increment variable.", Node);
61 else
62 {
63 LinkedList<IElement> Elements = new LinkedList<IElement>();
64
65 foreach (IElement Element in Value.ChildElements)
66 Elements.AddLast(Increment(Element, Node));
67
68 return Value.Encapsulate(Elements, Node);
69 }
70 }
71
72 }
73}
Base class for all types of elements.
Definition: Element.cs:13
Class managing a script expression.
Definition: Expression.cs:39
readonly string variableName
Name of variable being referenced by the node.
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
static IElement Increment(IElement Value, ScriptNode Node)
Increments a value.
Definition: PreIncrement.cs:55
PreIncrement(string VariableName, int Start, int Length, Expression Expression)
Pre-Increment operator.
Definition: PreIncrement.cs:22
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: PreIncrement.cs:32
Contains information about a variable.
Definition: Variable.cs:10
Collection of variables.
Definition: Variables.cs:25
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Definition: Variables.cs:52
Basic interface for all types of commutative ring with identity elements.
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: IElement.cs:49
IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
bool IsScalar
If the element represents a scalar value.
Definition: IElement.cs:41