I've read Wikipedia's explanation at least a dozen times, but I'm still confused at how an LR(0) parser ever leaves state 0.
Wikipedia's example, with its explanation, says:
The parser starts out with the stack containing just the initial state (
'0'
):[0]
The first symbol from the input string that the parser sees is'1'
.
... but this doesn't make sense to me, because seeing the input symbol would be performing a lookahead, but an LR(0) parser, by definition, can't perform a lookahead.
When the parser is at state 0, it hasn't shifted yet, so it doesn't have any symbols on its stack.
Given that it's an LR(0) parser, it can't perform a lookahead either.
So how does it use the table to figure out which state to shift or reduce into, from state 0?