eval method

dynamic eval(
  1. String expr, {
  2. bool nul = false,
})

Evaluates the expression, returns the result. Returns null on failure and sets lastError.

Implementation

dynamic eval(String expr, {bool nul = false}) {
  if (expr.isEmpty) return null;
  lastError =
      ''; // clears the previous error before every evaluation (avoids a stale value causing a false hasError)
  _p.expression = expr;
  _p.nul = nul;
  if (_p.analyzeExpression()) return _p.value;
  lastError = '[ERROR] $expr # ${_p.error}';
  return null;
}