Content deleted Content added
m Replaced 1 bare URLs by {{Cite web}}; Replaced "Archived copy" by actual titles |
|||
(13 intermediate revisions by 8 users not shown) | |||
Line 1:
{{Short description|Computer mechanic}}
{{more citations needed|date=November 2024}}
In [[computer science]], a '''Simple LR''' or '''SLR parser''' is a type of [[LR parser]] with small [[LR parser#Constructing LR(0) parsing tables|parse table]]s and a relatively simple parser generator algorithm. As with other types of LR(1) parser, an SLR parser is quite efficient at finding the single correct [[bottom-up parsing|bottom-up parse]] in a single left-to-right scan over the input stream, without guesswork or backtracking. The parser is mechanically generated from a formal grammar for the language.
SLR and the more
SLR and LALR were both developed by [[Frank DeRemer]] as the first practical uses of [[Donald Knuth]]'s LR parser theory.<ref>{{
== Lookahead sets ==
Line 11 ⟶ 12:
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.
LALR generators calculate lookahead sets by a more precise method based on exploring the graph of parser states and their transitions. This method considers the particular context of the current parser state. It customizes the handling of each grammar occurrence of some nonterminal S. See article [[LALR parser]] for further details of this calculation. The lookahead sets calculated by LALR generators are a subset of (and hence better than) the approximate sets calculated by SLR generators. If a grammar has table conflicts when using SLR follow sets, but is conflict-free when using LALR follow sets, it is called a LALR grammar. {{citation needed|date=November 2024}}
== Example ==
Line 76 ⟶ 77:
function mustBeAdded(reduceAction, action) {
ruleNumber = reduceAction.value;
ruleSymbol = rules[ruleNumber].leftHandSide;
return (action in followSet(ruleSymbol))
}
Line 111 ⟶ 112:
* [[LALR parser]]
* [[SLR grammar]]
==References==
{{reflist}}
{{Parsers}}
|