Bounded postfix arithmetic
StackSundial is a Windows workspace for reviewing small arithmetic interpreters with AI. Trace the operand stack through a conversation, then check rejection paths and division semantics in the model’s proposed edits.
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]- Project
- Check negative floor division and reject division by zero, an incomplete stack or any intermediate magnitude above 10**18.
- Review before applying
- Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
- Connection
- Base URL, credentials and a reachable server.
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]Define what an expression may do before changing its parser
Expression handling needs clear boundaries even when the language is small. StackSundial is a Windows AI coding workspace for discussing those boundaries beside the source files. Open your project and ask the connected model to inspect accepted tokens, evaluation rules and the caller’s error handling before it proposes an implementation change.
A possible task is reviewing a postfix evaluator used by an internal calculation screen. Specify allowed operators, numeric limits and the response to malformed expressions. Ask the assistant to identify where those requirements are enforced and propose focused changes where they are missing. This makes the conversation about maintaining your software instead of merely generating another evaluator.
Review rejection paths with the same attention as successful arithmetic. Run project checks for missing operands, extra results, division by zero and values beyond the permitted bounds. Inspect operand order in noncommutative operations and confirm that the caller receives the intended error. Avoid accepting a shorter evaluation loop if it weakens the contract around it.
StackSundial supports connections to OpenAI-compatible or Anthropic endpoints. Where available, choose an abliterated AI model with the understanding that restrictions, context limits and tools depend on the selected service. Its proposed code remains a starting point for inspection and your own verification, not evidence that the interpreter is ready.
Before accepting an evaluator patch
- Which rules should I include in the task description?
State permitted tokens, operand types, numeric bounds and error behavior. Include the caller that presents failures to users. Without those rules, a proposal may calculate ordinary examples correctly while accepting expressions the application was meant to reject.
- Why test subtraction and division explicitly?
Their results depend on operand order, unlike addition in ordinary cases. Use fixtures with visibly different outcomes when operands are reversed. Check the division convention required by your project as well as its response to a zero divisor.
- Should malformed expressions return zero?
Only if that is an explicit application requirement. A plausible numeric fallback can conceal bad input. Ask the assistant to preserve a clear rejection path and inspect how the caller distinguishes a valid zero result from an error.
- Can a token limit alone bound evaluation?
Review all limits the project requires, including intermediate values and accepted input structure. A token count answers only one part of that contract. Test the relevant rejection paths after any change to the evaluation loop.
StackSundial · Updated 2026-10-25