Parsing State – Programming Languages

Let’s trace what happens as we see a little more of the input. Let’s say we actually walk over and we see the 2. Well, then our parcing state looks like this–E goes to 2. We’ve seen the 2, and there’s nothing left. Everything important is in the past. There’s nothing in the future. So conceptually, we can use this rule–this rewrite rule, E goes to 2 like we hinted at here with our purple text, we will also be here. E goes to E + E, but we’ve already seen the E, the +, and the E– E + E. So we can go even further and go back to the first rule in our grammar where we were trying to parse a sentence, which could be an expression. We’ve already seen an entire expression–1 + 2–and now we’re done. In fact, if you can get to the state corresponding to your starting nonterminal being completely finished, everything is in the past. Nothing to see in the future. Then you’ve parsed it! That string was in the language of the grammar. So formally a parsing state, a possible configuration of a parser, a world we could be in is a rewrite rule from the grammar augmented with exactly 1 red dot– that’s where I’m putting my finger. That’s where we are now. The past comes before it. The future comes after it–on the right-hand side of the rule. You can never put the dot on the left. The dot is always to the right. Now for any given input as we’ve seen here, you could actually be in maybe 3 of these parsing states at once. One way of looking at the world is that I just finished seeing the 2. Another way of looking at the world is–actually I’m done with everything. Those can all be true at the same time.