It depends on the expression. The classical recursive solution for a binary expression is something like (in C code):
int maxstack(expression *exp) {
if (IsLeaf(exp)) {
return 0;
} else {
int left_stack = maxstack(exp->left);
int right_stack = maxstack(exp->right);
if (left_stack == right_stack)
return left_stack + 1;
else if (left_stack > right_stack)
return left_stack;
else
return right_stack;
}
}
extending this to trinary/nary expressions is relatively straight-forward