BadScript 2
Loading...
Searching...
No Matches
BadGreaterThanExpression.cs
Go to the documentation of this file.
6
8
13{
20 public BadGreaterThanExpression(BadExpression left, BadExpression right, BadSourcePosition position) : base(left,
21 right,
22 position
23 ) { }
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> GreaterThanWithOverride(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 }
74 else if (right.HasProperty(BadStaticKeys.GREATER_OPERATOR_NAME, context?.Scope))
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 yield return GreaterThan(left, right, position);
89 }
90 }
91
93 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
94 {
96
97 foreach (BadObject o in Left.Execute(context))
98 {
99 left = o;
100
101 yield return o;
102 }
103
104 left = left.Dereference(Position);
105 BadObject right = BadObject.Null;
106
107 foreach (BadObject o in Right.Execute(context))
108 {
109 right = o;
110
111 yield return o;
112 }
113
114 right = right.Dereference(Position);
115
116 foreach (BadObject o in GreaterThanWithOverride(context, left, right, Position))
117 {
118 yield return o;
119 }
120 }
121
123 protected override string GetSymbol()
124 {
125 return ">";
126 }
127}
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: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.