BadScript 2
Loading...
Searching...
No Matches
BadLogicAndExpression.cs
Go to the documentation of this file.
6
11
16{
24 left,
25 right,
26 position
27 ) { }
28
37 public static BadObject And(BadObject left, BadObject right, BadSourcePosition pos)
38 {
39 if (left is not IBadBoolean lBool)
40 {
41 throw new BadRuntimeException($"Can not apply operator '&&' to {left}. expected boolean", pos);
42 }
43
44 if (!lBool.Value)
45 {
46 return BadObject.False;
47 }
48
49 if (right is IBadBoolean rBool)
50 {
51 return rBool.Value ? BadObject.True : BadObject.False;
52 }
53
54 throw new BadRuntimeException($"Can not apply operator '&&' to {left} and {right}", pos);
55 }
56
58 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
59 {
61
62 foreach (BadObject o in Left.Execute(context))
63 {
64 left = o;
65
66 yield return o;
67 }
68
69 left = left.Dereference();
70
71 if (left is not IBadBoolean lBool)
72 {
73 throw new BadRuntimeException($"Can not apply operator '{GetSymbol()}' to {left}. expected boolean", Position);
74 }
75
76 if (!lBool.Value)
77 {
78 yield return BadObject.False;
79
80 yield break;
81 }
82
83 BadObject right = BadObject.Null;
84
85 foreach (BadObject o in Right.Execute(context))
86 {
87 right = o;
88
89 yield return o;
90 }
91
92 right = right.Dereference();
93
94 if (right is not IBadBoolean rBool)
95 {
96 throw new BadRuntimeException($"Can not apply operator '{GetSymbol()}' to {left} and {right}", Position);
97 }
98
99 if (rBool.Value)
100 {
101 yield return BadObject.True;
102 }
103 else
104 {
105 yield return BadObject.False;
106 }
107 }
108
110 protected override string GetSymbol()
111 {
112 return "&&";
113 }
114}
Describes a specific position inside a source file.
Base Implementation for all Expressions used inside the Script.
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 And(BadObject left, BadObject right, BadSourcePosition pos)
Returns true if left and right are true.
BadLogicAndExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor of the Logic And Expression.
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
The Execution Context. Every execution of a script needs a context the script is running in....
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject True
The True Value for the BadScript Language.
Definition BadObject.cs:33
static readonly BadObject False
The False Value for the BadScript Language.
Definition BadObject.cs:38
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
Contains Shared Data Structures and Functionality.
Contains the Logic 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.