BadScript 2
Loading...
Searching...
No Matches
BadBinaryExpression.cs
Go to the documentation of this file.
3
5
9public abstract class BadBinaryExpression : BadExpression
10{
17 protected BadBinaryExpression(BadExpression left, BadExpression right, BadSourcePosition position) : base(
18 left.IsConstant && right.IsConstant,
19 position
20 )
21 {
22 Left = left;
23 Right = right;
24 }
25
29 public BadExpression Left { get; private set; }
30
34 public BadExpression Right { get; private set; }
35
42
47 public void SetLeft(BadExpression expr)
48 {
49 Left = expr;
50 }
51
56 public void SetRight(BadExpression expr)
57 {
58 Right = expr;
59 }
60
65 protected abstract string GetSymbol();
66
68 public override IEnumerable<BadExpression> GetDescendants()
69 {
70 foreach (BadExpression expression in Left.GetDescendantsAndSelf())
71 {
72 yield return expression;
73 }
74
75 foreach (BadExpression? expression in Right.GetDescendantsAndSelf())
76 {
77 yield return expression;
78 }
79 }
80
85 public override string ToString()
86 {
87 return $"({Left} {GetSymbol()} {Right})";
88 }
89}
Describes a specific position inside a source file.
static BadExpression Optimize(BadExpression expr)
Optimizes the given expression.
Base Implementation for all Expressions used inside the Script.
IEnumerable< BadExpression > GetDescendantsAndSelf()
Returns all Descendants of the Expression and the Expression itself.
bool IsConstant
Indicates if the expression stays constant at all times.
Base Implementation of all Binary Expressions.
void SetRight(BadExpression expr)
Sets the Right side of the Expression.
BadExpression Right
Right side of the Expression.
BadBinaryExpression(BadExpression left, BadExpression right, BadSourcePosition position)
Constructor for Binary Expressions.
string GetSymbol()
Returns the Symbol of the Operator.
override string ToString()
The String Representation of the Expression.
override IEnumerable< BadExpression > GetDescendants()
void SetLeft(BadExpression expr)
Sets the Left side of the Expression.
override void Optimize()
Uses the Constant Folding Optimizer to optimize the expression.
Contains Shared Data Structures and Functionality.
Contains the BadScript2 Constant Folding Optimizations.
Contains the Binary Expressions for the BadScript2 Language.