Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
LesserThanOrEqualTo.cs
1using System.Collections.Generic;
7
9{
14 {
24 : base(Left, Right, Start, Length, Expression)
25 {
26 }
27
36 {
37 if (!(Left.AssociatedSet is IOrderedSet S))
38 throw new ScriptRuntimeException("Cannot compare operands.", this);
39
40 if (S.Compare(Left, Right) <= 0)
41 return BooleanValue.True;
42 else
43 return BooleanValue.False;
44 }
45
52 public override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary<string, IElement> AlreadyFound)
53 {
54 int i;
55
56 if (!(CheckAgainst.AssociatedSet is IOrderedSet S))
57 return PatternMatchResult.NoMatch;
58
59 if (this.left is ConstantElement LeftConstant)
60 {
61 i = S.Compare(LeftConstant.Constant, CheckAgainst);
62 if (i <= 0)
63 return this.right.PatternMatch(CheckAgainst, AlreadyFound);
64 else
65 return PatternMatchResult.NoMatch;
66 }
67
68 if (this.right is ConstantElement RightConstant)
69 {
70 i = S.Compare(CheckAgainst, RightConstant.Constant);
71 if (i <= 0)
72 return this.left.PatternMatch(CheckAgainst, AlreadyFound);
73 else
74 return PatternMatchResult.NoMatch;
75 }
76
77 if (this.left is VariableReference LeftReference &&
78 (AlreadyFound.TryGetValue(LeftReference.VariableName, out IElement Value) ||
79 Expression.TryGetConstant(LeftReference.VariableName, null, out Value)))
80 {
81 i = S.Compare(Value, CheckAgainst);
82 if (i <= 0)
83 return this.right.PatternMatch(CheckAgainst, AlreadyFound);
84 else
85 return PatternMatchResult.NoMatch;
86 }
87
88 if (this.right is VariableReference RightReference &&
89 (AlreadyFound.TryGetValue(RightReference.VariableName, out Value) ||
90 Expression.TryGetConstant(RightReference.VariableName, null, out Value)))
91 {
92 i = S.Compare(CheckAgainst, Value);
93 if (i <= 0)
94 return this.left.PatternMatch(CheckAgainst, AlreadyFound);
95 else
96 return PatternMatchResult.NoMatch;
97 }
98
99 return PatternMatchResult.NoMatch;
100 }
101 }
102}
Class managing a script expression.
Definition: Expression.cs:39
static bool TryGetConstant(string Name, Variables Variables, out IElement ValueElement)
Tries to get a constant value, given its name.
Definition: Expression.cs:3307
ScriptNode right
Right operand.
ScriptNode left
Left operand.
Base class for binary scalar operators.
Represents a constant element value.
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
virtual PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
Definition: ScriptNode.cs:169
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Represents a variable reference.
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
static readonly BooleanValue True
Constant true value.
LesserThanOrEqualTo(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
Lesser Than Or Equal To.
override IElement EvaluateScalar(IElement Left, IElement Right, Variables Variables)
Evaluates the operator on scalar operands.
override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
Basic interface for ordered sets.
Definition: IOrderedSet.cs:11
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17