SStackSundial
Product

Product features · Bounded postfix arithmetic

01

Trace operand order in StackSundial; subtraction and floor division depend on which value leaves the stack first.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Bounded postfix arithmetic

● ● ●StackSundial●
A concrete starting point · Bounded postfix arithmetic ×
def postfix_value(tokens):
    tokens = tuple(tokens)
    if not 1 <= len(tokens) <= 100:
        raise ValueError("tokens.limit")
    stack = []
    for token in tokens:
        if type(token) is int and abs(token) <= 1000000000:
            stack.append(token)
            continue
        if type(token) is not str or token not in ("+", "-", "*", "//") or len(stack) < 2:
            raise ValueError("token.invalid")
        right, left = stack.pop(), stack.pop()
        if token == "//" and right == 0:
            raise ValueError("division.zero")
        value = (left + right if token == "+" else left - right if token == "-" else left * right if token == "*" else left // right)
        if abs(value) > 10**18:
            raise ValueError("result.range")
        stack.append(value)
    if len(stack) != 1:
        raise ValueError("stack.remainder")
    return stack[0]
✳Evaluate one through 100 postfix tokens using bounded integers and the operators +, -, * and //.
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗