Language Models Are Greedy Reasoners: A Systematic Formal Analysis of Chain-of-Thought