Space complexity analysis for stack programs