Beispiel #1
0
func evalOp(opName string, decimals *DecimalStack) error {
	op := operators.FindOperatorFromString(opName)
	if op == nil {
		return errors.New("Either unmatched paren or unrecognized operator")
	}

	var args = make([]decimal.Decimal, op.Args)
	for i := op.Args - 1; i >= 0; i-- {
		arg, err := decimals.Pop()
		if err != nil {
			return errors.New("Not enough arguments to operator!")
		}
		args[i] = arg
	}

	decimals.Push(op.Operation(args))

	return nil
}
Beispiel #2
0
func parseOperator(lit string) *operators.Operator {
	return operators.FindOperatorFromString(lit)
}