Package Behavioral.Interpreter
Class Parser
java.lang.Object
Behavioral.Interpreter.Parser
Minimal recursive-descent parser for a boolean domain-specific language (DSL).
Supports parsing logical expressions with AND, OR, NOT, constants, and variables.
Grammar (EBNF):
Expr := OrExpr
OrExpr := AndExpr { '|' AndExpr }
AndExpr:= NotExpr { '&' NotExpr }
NotExpr:= '!' NotExpr | Primary
Primary:= 'true' | 'false' | Identifier | '(' Expr ')'
Identifier := [A-Za-z_][A-Za-z0-9_]*
Example usage:
Expression expr = new Parser("!(x & y) | z").parse();
- Since:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionparse()Parses the input string and returns the rootExpression.
-
Constructor Details
-
Parser
Constructs a parser for the given input string.- Parameters:
s- the boolean expression string to parse
-
-
Method Details
-
parse
Parses the input string and returns the rootExpression.- Returns:
- the parsed expression tree
- Throws:
IllegalStateException- if the input is invalid or contains trailing characters
-