// check whether the used functions or references are actually valid.
final Formula f = new Formula(formula);
// connects the parsed formula to the context. The context provides the
// operator and function implementations and resolves the references.
f.initialize(new DemoFormulaContext());
JOptionPane.showMessageDialog(null, "The result is " + f.evaluate(),
"Result", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);