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(left,
24 right,
25 position
26 ) { }
27
28
30 protected override string GetSymbol()
31 {
32 return "+";
33 }
34
43 public static BadObject Add(BadObject left, BadObject right, BadSourcePosition pos)
44 {
45 switch (left)
46 {
47 case IBadString lStr when right is IBadNative rNative:
48 return BadObject.Wrap(lStr.Value + rNative.Value);
49 case IBadString lStr:
50 return BadObject.Wrap(lStr.Value + right);
51 case IBadNumber lNum when right is IBadString rStr:
52 return BadObject.Wrap(lNum.Value + rStr.Value);
53 case IBadNumber lNum when right is IBadNumber rNum:
54 return BadObject.Wrap(lNum.Value + rNum.Value);
55 case IBadNumber:
56 break;
57 case IBadBoolean lBool:
58 {
59 if (right is IBadString rStr)
60 {
61 return BadObject.Wrap(lBool.Value + rStr.Value);
62 }
63
64 break;
65 }
66 default:
67 {
68 if (right is IBadString rStr)
69 {
70 return BadObject.Wrap(left + rStr.Value);
71 }
72
73 break;
74 }
75 }
76
77 throw new BadRuntimeException($"Can not apply operator '+' to {left} and {right}", pos);
78 }
79
89 public static IEnumerable<BadObject> AddWithOverride(BadExecutionContext? context,
90 BadObject leftRef,
91 BadObject right,
92 BadSourcePosition position)
93 {
94 BadObject left = leftRef.Dereference(position);
95
97 {
98 foreach (BadObject o in ExecuteOperatorOverride(left,
99 right,
100 context!,
102 position
103 ))
104 {
105 yield return o;
106 }
107 }
108 else
109 {
110 yield return Add(left, right, position);
111 }
112 }
113
115 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
116 {
117 BadObject left = BadObject.Null;
118
119 foreach (BadObject o in Left.Execute(context))
120 {
121 left = o;
122
123 yield return o;
124 }
125
126 left = left.Dereference(Position);
127 BadObject right = BadObject.Null;
128
129 foreach (BadObject o in Right.Execute(context))
130 {
131 right = o;
132
133 yield return o;
134 }
135
136 right = right.Dereference(Position);
137
138 foreach (BadObject? o in AddWithOverride(context, left, right, Position))
139 {
140 yield return o;
141 }
142 }
143}
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:130
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.