Class Parser

java.lang.Object
Behavioral.Interpreter.Parser

public final class Parser extends Object
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 Details

    • Parser

      public Parser(String s)
      Constructs a parser for the given input string.
      Parameters:
      s - the boolean expression string to parse
  • Method Details

    • parse

      public Expression parse()
      Parses the input string and returns the root Expression.
      Returns:
      the parsed expression tree
      Throws:
      IllegalStateException - if the input is invalid or contains trailing characters