In SLR(1) parsing, FOLLOW sets are crucial for deciding when to reduce. What is the primary purpose of the FOLLOW set in this context?
Think about when the parser decides to reduce a production based on the next input symbol.
The FOLLOW set contains terminals that can appear immediately after a non-terminal. In SLR(1) parsing, reduce actions are allowed only when the lookahead symbol is in the FOLLOW set of the production's left-hand side non-terminal.
Which of the following steps is not part of constructing an SLR(1) parsing table?
SLR(1) parsing uses LR(0) items, not LR(1) items with lookaheads.
SLR(1) parsing tables are built using LR(0) items and FOLLOW sets. LR(1) items with lookahead symbols are used in more powerful parsing methods like canonical LR(1), not in SLR(1).
Consider the grammar:S → Aa | bA → b
Which type of conflict is most likely to appear in the SLR(1) parsing table for this grammar?
The FOLLOW sets of S ({$}) and A ({a}) are disjoint, preventing reduce-reduce conflicts, and there are no shift-reduce situations.
This grammar has no conflicts in its SLR(1) parsing table. In the state with items S → b• and A → b•, reduce S → b uses lookahead in FOLLOW(S) = {$}, and reduce A → b uses lookahead in FOLLOW(A) = {a}. These are disjoint, and there are no shift actions in that state.
Which statement correctly compares SLR(1) and canonical LR(1) parsing methods?
Consider how lookahead information is computed and used in both methods.
SLR(1) uses FOLLOW sets for all reductions, which can be imprecise and cause conflicts. LR(1) uses specific lookahead sets for each item, making it more powerful and able to parse more grammars without conflicts.
Given the grammar:E → E + T | TT → T * F | FF → ( E ) | id
How many states will the canonical collection of LR(0) items have when constructing the SLR(1) parsing automaton?
Recall the classic expression grammar and the typical size of its LR(0) automaton.
This classic expression grammar generates 12 LR(0) states in its canonical collection, as it includes states for each position of the dot in all productions plus closure expansions.
