BadScript 2
Loading...
Searching...
No Matches
BadGreaterThanExpression.cs
Go to the documentation of this file.
6
8
13{
21 left,
22 right,
23 position
24 ) { }
25
26
36 {
37 if (left is not IBadNumber lNum)
38 {
39 throw new BadRuntimeException($"Can not apply operator '>' to {left} and {right}", pos);
40 }
41
42 if (right is IBadNumber rNum)
43 {
44 return lNum.Value > rNum.Value ? BadObject.True : BadObject.False;
45 }
46
47 throw new BadRuntimeException($"Can not apply operator '>' to {left} and {right}", pos);
48 }
49
58 public static IEnumerable<BadObject> GreaterThanWithOverride(
59 BadExecutionContext? context,
60 BadObject left,
61 BadObject right,
62 BadSourcePosition position)
63 {
65 {
67 left,
68 right,
69 context!,
71 position
72 ))
73 {
74 yield return o;
75 }
76 }
77 else if (right.HasProperty(BadStaticKeys.GREATER_OPERATOR_NAME, context?.Scope))
78 {
80 right,
81 left,
82 context!,
84 position
85 ))
86 {
87 yield return o;
88 }
89 }
90 else
91 {
92 yield return GreaterThan(left, right, position);
93 }
94 }
95
97 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
98 {
100
101 foreach (BadObject o in Left.Execute(context))
102 {
103 left = o;
104
105 yield return o;
106 }
107
108 left = left.Dereference();
109 BadObject right = BadObject.Null;
110
111 foreach (BadObject o in Right.Execute(context))
112 {
113 right = o;
114
115 yield return o;
116 }
117
118 right = right.Dereference();
119
120 foreach (BadObject o in GreaterThanWithOverride(context, left, right, Position))
121 {
122 yield return o;
123 }
124 }
125
127 protected override string GetSymbol()
128 {
129 return ">";
130 }
131}
Describes a specific position inside a source file.
Contains Static Data for the BadScript Language.
Base Implementation for all Expressions used inside the Script.
static IEnumerable< BadObject > ExecuteOperatorOverride(BadObject left, BadObject right, BadExecutionContext context, string name, BadSourcePosition position)
Helper function that executes an operator override function if implemented.
BadSourcePosition Position
The source Position of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
Base Implementation of all Binary Expressions.
BadExpression Right
Right side of the Expression.
static BadObject GreaterThan(BadObject left, BadObject right, BadSourcePosition pos)
Returns true if the left side is greater than the right side.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
static IEnumerable< BadObject > GreaterThanWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the expression.
BadGreaterThanExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor of the Greater Than Expression.
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject False
The False Value for the BadScript Language.
Definition BadObject.cs:38
virtual bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
Definition BadObject.cs:118
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements the Interface for Native Numbers.
Definition IBadNumber.cs:7
Contains Shared Data Structures and Functionality.
Contains the Comparison Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.