BadScript 2
Loading...
Searching...
No Matches
BadAddExpression.cs
Go to the documentation of this file.
6
11
16{
23 public BadAddExpression(BadExpression left, BadExpression right, BadSourcePosition position) : base(
24 left,
25 right,
26 position
27 ) { }
28
29
31 protected override string GetSymbol()
32 {
33 return "+";
34 }
35
44 public static BadObject Add(BadObject left, BadObject right, BadSourcePosition pos)
45 {
46 switch (left)
47 {
48 case IBadString lStr when right is IBadNative rNative:
49 return BadObject.Wrap(lStr.Value + rNative.Value);
50 case IBadString lStr:
51 return BadObject.Wrap(lStr.Value + right);
52 case IBadNumber lNum when right is IBadString rStr:
53 return BadObject.Wrap(lNum.Value + rStr.Value);
54 case IBadNumber lNum when right is IBadNumber rNum:
55 return BadObject.Wrap(lNum.Value + rNum.Value);
56 case IBadNumber:
57 break;
58 case IBadBoolean lBool:
59 {
60 if (right is IBadString rStr)
61 {
62 return BadObject.Wrap(lBool.Value + rStr.Value);
63 }
64
65 break;
66 }
67 default:
68 {
69 if (right is IBadString rStr)
70 {
71 return BadObject.Wrap(left + rStr.Value);
72 }
73
74 break;
75 }
76 }
77
78 throw new BadRuntimeException($"Can not apply operator '+' to {left} and {right}", pos);
79 }
80
90 public static IEnumerable<BadObject> AddWithOverride(
91 BadExecutionContext? context,
92 BadObject leftRef,
93 BadObject right,
94 BadSourcePosition position)
95 {
96 BadObject left = leftRef.Dereference();
97
99 {
101 left,
102 right,
103 context!,
105 position
106 ))
107 {
108 yield return o;
109 }
110 }
111 else
112 {
113 yield return Add(left, right, position);
114 }
115 }
116
118 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
119 {
120 BadObject left = BadObject.Null;
121
122 foreach (BadObject o in Left.Execute(context))
123 {
124 left = o;
125
126 yield return o;
127 }
128
129 left = left.Dereference();
130 BadObject right = BadObject.Null;
131
132 foreach (BadObject o in Right.Execute(context))
133 {
134 right = o;
135
136 yield return o;
137 }
138
139 right = right.Dereference();
140
141 foreach (BadObject? o in AddWithOverride(context, left, right, Position))
142 {
143 yield return o;
144 }
145 }
146}
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.
BadAddExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor of the Add Expression.
static BadObject Add(BadObject left, BadObject right, BadSourcePosition pos)
Adds left and right together.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
static IEnumerable< BadObject > AddWithOverride(BadExecutionContext? context, BadObject leftRef, BadObject right, BadSourcePosition position)
Executes the Operator with operator overrides.
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:118
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements the Interface for Native Boolean.
Definition IBadBoolean.cs:7
Defines properties for Native Types.
Definition IBadNative.cs:7
Implements the Interface for Native Numbers.
Definition IBadNumber.cs:7
Implements the Interface for Native Strings.
Definition IBadString.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.