src/main/java/com/acme/calculator/main/Calculator.java
/**
     * Parses an expression, performs the specified calculations in the expression, and returns a BigDecimal result.
     *
     * @param expression the expression to parse and calculate
     * @return BigDecimal result of the expression
     */
Parses an expression, performs the specified calculations in the expression, and returns a BigDecimal result.
@param expression the expression to parse and calculate
@return BigDecimal result of the expression
Parses an expression performs the specified calculations in the expression and returns a BigDecimal result . @param expression the expression to parse and calculate @return BigDecimal result of the expression
private BigDecimal parse(final String expression) {
        logger.debug("parse() expression: '{}'", expression);
        variablesMap.clear();
        final BasicCalculatorLexer lexer = createLexer(expression);
        final BasicCalculatorParser parser = createParser(lexer);
        final BasicCalculatorParser.ExprContext context = parser.expr();
        return visit(context);
    }
private BigDecimal parse ( final String expression ) { logger . debug ( "parse() expression: '{}'" , expression ) ; variablesMap . clear ( ) ; final BasicCalculatorLexer lexer = createLexer ( expression ) ; final BasicCalculatorParser parser = createParser ( lexer ) ; final BasicCalculatorParser . ExprContext context = parser . expr ( ) ; return visit ( context ) ; }
Parses an expression, performs the specified calculations in the expression, and returns a BigDecimal result.
Parses an expression performs the specified calculations in the expression and returns a BigDecimal result .
// Clear out any prexisting variable values in the event that an instance of this class is invoked more // than once, since there isn't currently a use-case to cache variable data across multiple expressions. // root of the AST (Abstract Syntax Tree) // todo: research further // This was intended for debugging use but isn't working as expected - causes "Syntax error in expression" // ParseTree tree = parser.calc(); // begin parsing at "calc" rule // System.out.println(tree.toStringTree(parser)); // print LISP-style tree } // visit all the branches of the tree to obtain the result