I've began to read about LR(k) parse table construction, and all texts explaining the algorithm for k > 0 suggest that the lookaheads should be calculated for every symbol before generating the item sets, then when all item sets are generated, the redundant ones should be merged to generate a minimal parse table.
Consider the following pseudo state/itemset construction routine:
- Start by assuming a state transition can be determined without lookaheads(k = 0)
- Calculate the entire itemset for the current state
- Try to determine the current state action:
- If there's only one item in the set and it has consumed all input(marker to the right of the rhs, the action is reduce to the lhs of the item.
- If every item in the set expects an input, the action is to shift and go to the next state
- If some items expect input and some don't this is a shift/reduce conflict
- If two or more items with different lhs reached end of input, this is a reduce /reduce conflict. If one of the last two cases occurred, it means we need to look ahead before deciding the state action. Increase k by 1 and go back to step 2.
- If the action is to shift, proceed to create the follow up states by simulating combinations of inputs(and lookaheads if k > 0) and going back to step 1 for each new state.
Would it be possible/viable to construct tables for arbitrary LR(k) grammars using the above steps? If not, what am I missing?