Simple LR parser: Difference between revisions

Content deleted Content added
cn
m Lookahead Sets: Added link to production rule
Line 9:
To understand the differences between SLR and LALR, you should first understand their many similarities and how they both make shift-reduce decisions. Please read article [[LR parser]] now for that background, up through the section on reductions' Lookahead Sets.
 
The one difference between SLR and LALR is how their generators calculate the '''lookahead sets''' of input symbols that should appear next, whenever some completed [[Formal grammar#The syntax of grammars|production rule]] is found and reduced.
 
SLR generators calculate that lookahead by an easy approximation method based directly on the grammar, ignoring the details of individual parser states and transitions. This ignores the particular context of the current parser state. If some nonterminal symbol S is used in several places in the grammar, SLR treats those places in the same single way rather than handling them individually. The SLR generator works out Follow(S), the set of all terminal symbols which can immediately follow some occurrence of S. In the parse table, each reduction to S uses Follow(S) as its LR(1) lookahead set. Such follow sets are also used by generators for LL top-down parsers. A grammar that has no shift/reduce or reduce/reduce conflicts when using Follow sets is called an [[SLR grammar]].