BadScript 2
Loading...
Searching...
No Matches
BadLessOrEqualExpression.cs
Go to the documentation of this file.
6
8
14{
22 left,
23 right,
24 position
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> LessOrEqualWithOverride(
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 }
78 {
80 right,
81 left,
82 context!,
84 position
85 ))
86 {
87 yield return o;
88 }
89 }
90 else
91
92 {
93 yield return LessOrEqual(left, right, position);
94 }
95 }
96
98 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
99 {
100 BadObject left = BadObject.Null;
101
102 foreach (BadObject o in Left.Execute(context))
103 {
104 left = o;
105
106 yield return o;
107 }
108
109 left = left.Dereference();
110 BadObject right = BadObject.Null;
111
112 foreach (BadObject o in Right.Execute(context))
113 {
114 right = o;
115
116 yield return o;
117 }
118
119 right = right.Dereference();
120
121
122 foreach (BadObject o in LessOrEqualWithOverride(context, left, right, Position))
123 {
124 yield return o;
125 }
126 }
127
129 protected override string GetSymbol()
130 {
131 return "<=";
132 }
133}
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.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
static BadObject LessOrEqual(BadObject left, BadObject right, BadSourcePosition pos)
Returns true if the left side is less or equal to the right side.
static IEnumerable< BadObject > LessOrEqualWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Executes the expression.
BadLessOrEqualExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor of the Less or Equal 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.