Operator-precedence Parser - Relationship To Other Parsers

Relationship To Other Parsers

An operator-precedence parser is a simple shift-reduce parser that is capable of parsing a subset of LR(1) grammars. More precisely, the operator-precedence parser can parse all LR(1) grammars where two consecutive nonterminals never appear in the right-hand side of any rule.

Operator-precedence parsers are not used often in practice; however they do have some properties that make them useful within a larger design. First, they are simple enough to write by hand, which is not generally the case with more sophisticated shift-reduce parsers. Second, they can be written to consult an operator table at run time, which makes them suitable for languages that can add to or change their operators while parsing. (An example is Haskell, which allows user-defined infix operators with custom associativity and precedence; consequentially, an operator-precedence parser must be run on the program after parsing of all referenced modules.)

Perl 6 sandwiches an operator-precedence parser between two Recursive descent parsers in order to achieve a balance of speed and dynamism. This is expressed in the virtual machine for Perl 6, Parrot, as the Parser Grammar Engine (PGE). GCC's C and C++ parsers, which are hand-coded recursive descent parsers, are both sped up by an operator-precedence parser that can quickly examine arithmetic expressions. Operator precedence parsers are also embedded within compiler compiler-generated parsers to noticeably speed up the recursive descent approach to expression parsing.

Read more about this topic:  Operator-precedence Parser

Famous quotes containing the words relationship to and/or relationship:

    Poetry is above all a concentration of the power of language, which is the power of our ultimate relationship to everything in the universe.
    Adrienne Rich (b. 1929)

    In contrast with envy, which usually occurs between two people and is focused upon another person’s qualities or possessions, jealousy occurs when a third person becomes a threat to a dyad. Jealousy involves the loss or the impending loss of a relationship that one wants to hold onto, a relationship that is vital to personal fulfillment and claimed as one’s own.
    Carol S. Becker (b. 1942)