Skip to content

Commit e8cc214

Browse files
committed
Add variables dictionary to evaluate methods
1 parent 18b86de commit e8cc214

File tree

9 files changed

+11
-11
lines changed

9 files changed

+11
-11
lines changed

BooleanExpressionParser/Nodes/AndOperatorNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ class AndOperatorNode : OperatorNode
22
{
33
public AndOperatorNode(Node left, Node right) : base(left, right) { }
44

5-
public override bool Evaluate() => Left.Evaluate() && Right!.Evaluate();
5+
public override bool Evaluate(Dictionary<string, bool> variables) => Left.Evaluate(variables) && Right!.Evaluate(variables);
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class NandOperatorNode : OperatorNode
22
{
33
public NandOperatorNode(Node left, Node right) : base(left, right) { }
4-
5-
public override bool Evaluate() => !(Left.Evaluate() && Right!.Evaluate());
4+
5+
public override bool Evaluate(Dictionary<string, bool> variables) => !(Left.Evaluate(variables) && Right!.Evaluate(variables));
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
abstract class Node
22
{
3-
public abstract bool Evaluate();
3+
public abstract bool Evaluate(Dictionary<string, bool> variables);
44
}

BooleanExpressionParser/Nodes/NorOperatorNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ class NorOperatorNode : OperatorNode
22
{
33
public NorOperatorNode(Node left, Node right) : base(left, right) { }
44

5-
public override bool Evaluate() => !(Left.Evaluate() || Right!.Evaluate());
5+
public override bool Evaluate(Dictionary<string, bool> variables) => !(Left.Evaluate(variables) || Right!.Evaluate(variables));
66
}

BooleanExpressionParser/Nodes/NotOperatorNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ class NotOperatorNode : OperatorNode
22
{
33
public NotOperatorNode(Node left) : base(left, null) { }
44

5-
public override bool Evaluate() => !Left.Evaluate();
5+
public override bool Evaluate(Dictionary<string, bool> variables) => !Left.Evaluate(variables);
66
}

BooleanExpressionParser/Nodes/OrOperatorNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ class OrOperatorNode : OperatorNode
22
{
33
public OrOperatorNode(Node left, Node right) : base(left, right) { }
44

5-
public override bool Evaluate() => Left.Evaluate() || Right!.Evaluate();
5+
public override bool Evaluate(Dictionary<string, bool> variables) => Left.Evaluate(variables) || Right!.Evaluate(variables);
66
}

BooleanExpressionParser/Nodes/VariableNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public VariableNode(String name)
66
}
77

88
public String Name { get; set; }
9-
public bool Value { get; set; }
9+
// public bool Value { get; set; }
1010

11-
public override bool Evaluate() => Value;
11+
public override bool Evaluate(Dictionary<string, bool> variables) => variables[Name];
1212
}

BooleanExpressionParser/Nodes/XnorOperatorNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ class XnorOperatorNode : OperatorNode
22
{
33
public XnorOperatorNode(Node left, Node right) : base(left, right) { }
44

5-
public override bool Evaluate() => Left.Evaluate() == Right!.Evaluate();
5+
public override bool Evaluate(Dictionary<string, bool> variables) => Left.Evaluate(variables) == Right!.Evaluate(variables);
66
}

BooleanExpressionParser/Nodes/XorOperatorNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ class XorOperatorNode : OperatorNode
22
{
33
public XorOperatorNode(Node left, Node right) : base(left, right) { }
44

5-
public override bool Evaluate() => Left.Evaluate() ^ Right!.Evaluate();
5+
public override bool Evaluate(Dictionary<string, bool> variables) => Left.Evaluate(variables) ^ Right!.Evaluate(variables);
66
}

0 commit comments

Comments
 (0)