Define INFIX_TO_POSTFIX_SIZE

Define Documentation

INFIX_TO_POSTFIX_SIZE(n)

Calculate required size of postfix buffer from infix.

This macro calculates the maximum size of postfix buffer needed for an infix expression buffer of a given size. The argument n must count the trailing nil byte in the input expression string. The actual size needed is never larger than this value, although it is actually a few bytes smaller for some sizes.

The maximum expansion from infix to postfix is for the sub-expression

.1?.1:
which is 6 characters long and results in 21 bytes of postfix:
.1 => LITERAL_DOUBLE + 8 byte value
?  => COND_IF
.1 => LITERAL_DOUBLE + 8 byte value
:  => COND_ELSE
...
   => COND_END
For other short expressions the factor 21/6 always gives a big enough postfix buffer (proven by hand, look at ‘1+’ and ‘.1+’ as well).