toRPN method

String toRPN()

Get a string representation of the RPN (Reverse Polish Notation) for this expression.

Returns a string with the RPN representation for this expression.

Implementation

String toRPN() {
  String result = "";
  for (Token t in getRPN()) {
    if (result.isNotEmpty) {
      result += " ";
    }
    if (t.type == TokenType.variable && variables.containsKey(t.surface)) {
      LazyNumber innerVariable = variables[t.surface]!;
      String innerExp = innerVariable.getString();
      if (isNumber(innerExp)) {
        // if it is a number, then we don't
        // expan in the RPN
        result += t.toString();
      } else {
        // expand the nested variable to its RPN representation
        Expression exp = _createEmbeddedExpression(innerExp);
        String nestedExpRpn = exp.toRPN();
        result += nestedExpRpn;
      }
    } else {
      result += t.toString();
    }
  }
  return result.toString();
}