BadScript 2
Loading...
Searching...
No Matches
BadExponentiationExpression.cs
Go to the documentation of this file.
6
8
13{
21 right,
22 position
23 ) { }
24
26 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
27 {
29
30 foreach (BadObject o in Left.Execute(context))
31 {
32 left = o;
33
34 yield return o;
35 }
36
37 left = left.Dereference(Position);
38 BadObject right = BadObject.Null;
39
40 foreach (BadObject o in Right.Execute(context))
41 {
42 right = o;
43
44 yield return o;
45 }
46
47 right = right.Dereference(Position);
48
49 foreach (BadObject? o in ExpWithOverride(context, left, right, Position))
50 {
51 yield return o;
52 }
53 }
54
63 public static IEnumerable<BadObject> ExpWithOverride(BadExecutionContext? context,
64 BadObject left,
65 BadObject right,
66 BadSourcePosition position)
67 {
69 {
70 foreach (BadObject o in ExecuteOperatorOverride(left,
71 right,
72 context!,
74 position
75 ))
76 {
77 yield return o;
78 }
79 }
80 else
81 {
82 yield return Exp(left, right, position);
83 }
84 }
85
94 public static BadObject Exp(BadObject left, BadObject right, BadSourcePosition position)
95 {
96 if (left is not IBadNumber lNum)
97 {
98 throw new BadRuntimeException($"Can not apply operator '*' to {left} and {right}", position);
99 }
100
101 if (right is IBadNumber rNum)
102 {
103 return BadObject.Wrap(System.Math.Pow((double)lNum.Value, (double)rNum.Value));
104 }
105
106 throw new BadRuntimeException($"Can not apply operator '*' to {left} and {right}", position);
107 }
108
109
111 protected override string GetSymbol()
112 {
113 return "**";
114 }
115}
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 Exp(BadObject left, BadObject right, BadSourcePosition position)
Implements the logic of the Exponentiation Operator.
static IEnumerable< BadObject > ExpWithOverride(BadExecutionContext? context, BadObject left, BadObject right, BadSourcePosition position)
Runs the Exponentiation Operator on the given objects.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
BadExponentiationExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Creates a new Exponentiation 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
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 Math 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.