Package Behavioral.Interpreter
Interface Expression
public interface Expression
Represents an expression in a simple boolean grammar for the Interpreter design pattern.
Implementations of this interface define how to interpret the expression given a context of variable bindings. This allows for the evaluation of logical expressions such as AND, OR, NOT, constants, and variables.
Example usage:
Expression expr = new And(new Variable("x"), new Not(new Variable("y")));
boolean result = expr.interpret(Map.of("x", true, "y", false));
- Since:
- 1.0
-
Method Summary
-
Method Details
-
interpret
Interprets this expression under the provided context of variable bindings.- Parameters:
ctx- a map containing variable names as keys and their boolean values as values- Returns:
- the boolean result of evaluating this expression with the given context
- Throws:
IllegalStateException- if a required variable is not present in the context
-