BadScript 2
Loading...
Searching...
No Matches
BadLessOrEqualExpression.cs
Go to the documentation of this file.
6
8
14{
21 public BadLessOrEqualExpression(BadExpression left, BadExpression right, BadSourcePosition position) : base(left,
22 right,
23 position
24 ) { }
25
35 {
36 if (left is not IBadNumber lNum)
37 {
38 throw new BadRuntimeException($"Can not apply operator '<=' to {left} and {right}", pos);
39 }
40
41 if (right is IBadNumber rNum)
42 {
43 return lNum.Value <= rNum.Value ? BadObject.True : BadObject.False;
44 }
45
46 throw new BadRuntimeException($"Can not apply operator '<=' to {left} and {right}", pos);
47 }
48
57 public static IEnumerable<BadObject> LessOrEqualWithOverride(BadExecutionContext? context,
58 BadObject left,
59 BadObject right,
60 BadSourcePosition position)
61 {
63 {
64 foreach (BadObject o in ExecuteOperatorOverride(left,
65 right,
66 context!,
68 position
69 ))
70 {
71 yield return o;
72 }
73 }
75 {
76 foreach (BadObject o in ExecuteOperatorOverride(right,
77 left,
78 context!,
80 position
81 ))
82 {
83 yield return o;
84 }
85 }
86 else
87
88 {
89 yield return LessOrEqual(left, right, position);
90 }
91 }
92
94 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
95 {
97
98 foreach (BadObject o in Left.Execute(context))
99 {
100 left = o;
101
102 yield return o;
103 }
104
105 left = left.Dereference(Position);
106 BadObject right = BadObject.Null;
107
108 foreach (BadObject o in Right.Execute(context))
109 {
110 right = o;
111
112 yield return o;
113 }
114
115 right = right.Dereference(Position);
116
117 foreach (BadObject o in LessOrEqualWithOverride(context, left, right, Position))
118 {
119 yield return o;
120 }
121 }
122
124 protected override string GetSymbol()
125 {
126 return "<=";
127 }
128}
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:130
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.