So far, my understanding of the algorithm of bottom-up parsing is this.
- shift a token into the stack
- check the stack from top if some elements including the top can be reduced by some production rule
- if the elements can be reduced, pop and push the left hand side of the production rule.
- continue those steps until top is the start symbol and next input is EOF
So to support my question with an example grammar,
S → aABe
A → Abc
A → b
B → d
if we have input string as
abbcde$
we will shift a
in stack
and because there are no production rule that reduces a
, we shift the next token b
.
Then we can find a production rule A → b
and reduce b
to A
.
Then my question is this. We have aA
on stack and the next input is b
. Then how can the parser determine whether we reduce b
to A
we wait for c
to come and use the rule A → Abc
?
Well of course, reducing b
to A
at that point results in an error. But how does the parser know at that point that we should wait for c
?
I'm sorry if I missed something while studying.