isBoolean method

bool isBoolean()

Checks whether the expression is a boolean expression. An expression is considered a boolean expression, if the last operator or function is boolean. The IF function is handled special. If the third parameter is boolean, then the IF is also considered boolean, else non-boolean.

Returns true if the last operator/function was a boolean.

Implementation

bool isBoolean() {
  List<Token> rpnList = getRPN();
  if (rpnList.isNotEmpty) {
    for (int i = rpnList.length - 1; i >= 0; i--) {
      Token t = rpnList[i];

      /*
               * The IF function is handled special. If the third parameter is
               * boolean, then the IF is also considered a boolean. Just skip
               * the IF function to check the second parameter.
               */
      if (t.surface == "IF") {
        continue;
      }
      if (t.type == TokenType.function) {
        return functions[t.surface]!.isBooleanFunction();
      } else if (t.type == TokenType.operator) {
        return operators[t.surface]!.isBooleanOperator();
      }
    }
  }
  return false;
}