Rewrite and simplify stack functions

Reduce coupling between the stack and parser. Use `const void *` for
values in the stack, which isn't ideal, but allows for storing both
strings and operator structs in different stacks.