private void NewOperation(RpnOperation operation) { while (expressionStack.TryPeek(out var stackOp) && !(stackOp is null) && !(stackOp.HasLessPriorityThan(operation))) { AddRpn(expressionStack.Pop()); } expressionStack.Push(operation); }
/// <summary> /// Adds a new unary operation. /// </summary> public void UnaryOperation(Token token) { RpnOperation rpn = token.Value switch { "!" => new RpnNot(token), "-" => new RpnNegate(token), "$" => new RpnGetValue(token, variables), var op => throw new RpnCreationException("Unknown unary operation: " + op) }; NewOperation(rpn); }
/// <summary> /// Adds a new binary operation. /// </summary> public void BinaryOperation(Token token) { RpnOperation rpn = token.Value switch { "=" => new RpnAssign(token, variables), "+" => new RpnAdd(token), "-" => new RpnSubtract(token), "*" => new RpnMultiply(token), "/" => new RpnDivide(token), "%" => new RpnMod(token), "|" => new RpnOr(token), "&" => new RpnAnd(token), "~" => new RpnEqual(token), ">" => new RpnGreater(token), "<" => new RpnLess(token), ":" => new RpnCast(token), "?" => new RpnCheckCast(token), "->" => new RpnRightAssign(token, variables), var op => throw new RpnCreationException("Unknown binary operation: " + op) }; NewOperation(rpn); }