HOME

TheInfoList



OR:

In computer science, parsing reveals the grammatical structure of linear input text, as a first step in working out its meaning. Bottom-up parsing recognizes the text's lowest-level small details first, before its mid-level structures, and leaving the highest-level overall structure to last.


Bottom-up Versus Top-down

The bottom-up name comes from the concept of a parse tree, in which the most detailed parts are at the bottom of the upside-down tree, and larger structures composed from them are in successively higher layers, until at the top or "root" of the tree a single unit describes the entire input stream. A bottom-up parse discovers and processes that tree starting from the bottom left end, and incrementally works its way upwards and rightwards. Compilers: Principles, Techniques, and Tools (2nd Edition), by
Alfred Aho Alfred Vaino Aho (born August 9, 1941) is a Canadian computer scientist best known for his work on programming languages, compilers, and related algorithms, and his textbooks on the art and science of computer programming. Aho was elected int ...
, Monica Lam,
Ravi Sethi Ravi Sethi (born 1947) is an Indian computer scientist retired from executive roles at Bell Labs and Avaya Labs. He also serves as a member of the National Science Foundation's Computer and Information Science and Engineering (CISE) Advisory Co ...
, and Jeffrey Ullman, Prentice Hall 2006.
A parser may act on the structure hierarchy's low, mid, and highest levels without ever creating an actual data tree; the tree is then merely implicit in the parser's actions. Bottom-up parsing patiently waits until it has scanned and parsed all parts of some construct before committing to what the combined construct is. The opposite of this is top-down parsing, in which the input's overall structure is decided (or guessed at) first, before dealing with mid-level parts, leaving completion of all lowest-level details to last. A top-down parser discovers and processes the hierarchical tree starting from the top, and incrementally works its way first downwards and then rightwards. Top-down parsing eagerly decides what a construct is much earlier, when it has only scanned the leftmost symbol of that construct and has not yet parsed any of its parts. Left corner parsing is a hybrid method that works bottom-up along the left edges of each subtree, and top-down on the rest of the parse tree. If a language grammar has multiple rules that may start with the same leftmost symbols but have different endings, then that grammar can be efficiently handled by a deterministic bottom-up parse but cannot be handled top-down without guesswork and
backtracking Backtracking is a class of algorithms for finding solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and abandons a candidate ("backtracks") as soon as it d ...
. So bottom-up parsers in practice handle a somewhat larger range of computer language grammars than do deterministic top-down parsers. Bottom-up parsing is sometimes done by
backtracking Backtracking is a class of algorithms for finding solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and abandons a candidate ("backtracks") as soon as it d ...
. But much more commonly, bottom-up parsing is done by a shift-reduce parser such as a
LALR parser In computer science, an LALR parser or Look-Ahead LR parser is a simplified version of a canonical LR parser, to parse a text according to a set of production rules specified by a formal grammar for a computer language. ("LR" means left-to-right, ...
.


Examples

Some of the parsers that use bottom-up parsing include: * Precedence parser ** Simple precedence parser ** Operator-precedence parser * Bounded-context parser (BC) *
LR parser In computer science, LR parsers are a type of bottom-up parsing, bottom-up parser that analyse deterministic context-free languages in linear time. There are several variants of LR parsers: SLR parser, SLR parsers, LALR parser, LALR parsers, Canoni ...
(Left-to-right, Rightmost derivation in reverse) **
Simple LR parser In computer science, a Simple LR or SLR parser is a type of LR parser with small parse tables 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 ...
(SLR) **
LALR parser In computer science, an LALR parser or Look-Ahead LR parser is a simplified version of a canonical LR parser, to parse a text according to a set of production rules specified by a formal grammar for a computer language. ("LR" means left-to-right, ...
(Look-Ahead) **
Canonical LR parser In computer science, a canonical LR parser or LR(1) parser is an LR(k) parser for ''k=1'', i.e. with a single lookahead terminal. The special attribute of this parser is that any LR(k) grammar with ''k>1'' can be transformed into an LR(1) grammar ...
(LR(1)) **
GLR parser A GLR parser (GLR standing for "Generalized LR", where L stands for "left-to-right" and R stands for "rightmost (derivation)") is an extension of an LR parser algorithm to handle non-deterministic and ambiguous grammars. The theoretical foundatio ...
(Generalized) * CYK parser (Cocke–Younger–Kasami) * Recursive ascent parser * Packrat parser * Shift-reduce parser


References

{{Parsers Parsing algorithms