1
$\begingroup$
  • All sources I have seen list taking two operands from the stack once we encounter an operator.
  • Why? What if not all of my operators are binary (taking two arguments)? What if I have custom unary and ternary operators?
$\endgroup$

1 Answer 1

3
$\begingroup$

I guess those sources innately assume binary operators. In a stack-based language (like postfix math notation) an $n$-ary operator takes $n$ items from the top of the stack as its input. Constants are often also viewed as arity 0, or nullary operators in this context.

$\endgroup$
1
  • 2
    $\begingroup$ I guess I would need a table to specify n-arity of each operator; so that the stack is processed accordingly when a specific operator is encountered. $\endgroup$ Aug 17, 2021 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.