lr

In computer science, LR parsers are a type of bottom-up parser that analyse deterministic context-free languages in linear time. There are several variants of LR parsers: SLR parsers, LALR parsers, canonical LR(1) parsers, minimal LR(1) parsers, and generalized LR parsers (GLR parsers). LR parsers can be generated by a parser generator from a formal grammar defining the syntax of the language to be parsed. They are widely used for the processing of computer languages.
An LR parser (left-to-right, rightmost derivation in reverse) reads input text from left to right without backing up (this is true for most parsers), and produces a rightmost derivation in reverse: it does a bottom-up parse – not a top-down LL parse or ad-hoc parse. The name "LR" is often followed by a numeric qualifier, as in "LR(1)" or sometimes "LR(k)". To avoid backtracking or guessing, the LR parser is allowed to peek ahead at k lookahead input symbols before deciding how to parse earlier symbols. Typically k is 1 and is not mentioned. The name "LR" is often preceded by other qualifiers, as in "SLR" and "LALR". The "LR(k)" notation for a grammar was suggested by Knuth to stand for "translatable from left to right with bound k."
LR parsers are deterministic; they produce a single correct parse without guesswork or backtracking, in linear time. This is ideal for computer languages, but LR parsers are not suited for human languages which need more flexible but inevitably slower methods. Some methods which can parse arbitrary context-free languages (e.g., Cocke–Younger–Kasami, Earley, GLR) have worst-case performance of O(n3) time. Other methods which backtrack or yield multiple parses may even take exponential time when they guess badly.
The above properties of L, R, and k are actually shared by all shift-reduce parsers, including precedence parsers. But by convention, the LR name stands for the form of parsing invented by Donald Knuth, and excludes the earlier, less powerful precedence methods (for example Operator-precedence parser).
LR parsers can handle a larger range of languages and grammars than precedence parsers or top-down LL parsing. This is because the LR parser waits until it has seen an entire instance of some grammar pattern before committing to what it has found. An LL parser has to decide or guess what it is seeing much sooner, when it has only seen the leftmost input symbol of that pattern.

View More On Wikipedia.org
  • 2

    Everest

    Established Member From UK
    • Messages
      528
    • Reaction score
      636
    • Points
      200
  • 2

    Tony60

    Standard Member From Liverpool
    • Messages
      21
    • Reaction score
      6
    • Points
      9
  • 1

    NickT

    Standard Member From Scotland
    • Messages
      30
    • Reaction score
      58
    • Points
      21
  • 1

    Ian Key

    Distinguished Member From Derby UK
    • Messages
      4,835
    • Reaction score
      8,621
    • Points
      2,314
  • 1

    Scp

    Novice Member From L342QT
    • Messages
      2
    • Reaction score
      1
    • Points
      1
  • 1

    figgles

    Standard Member From Cheshire
    • Messages
      4
    • Reaction score
      7
    • Points
      2
  • 1

    Layzell86

    Novice Member From Cogenhoe Northampton
    • Messages
      16
    • Reaction score
      1
    • Points
      3
  • 1

    MattyS

    Established Member From UK, Eastbourne
    • Messages
      61
    • Reaction score
      46
    • Points
      21
  • 1

    neeti

    Novice Member From Bucks
    • Messages
      4
    • Reaction score
      0
    • Points
      1
  • 1

    TroubledSaint

    Standard Member From UK
    • Messages
      13
    • Reaction score
      9
    • Points
      5
  • 1

    SiW80

    Established Member From Herts
    • Messages
      146
    • Reaction score
      80
    • Points
      48
  • 1

    Muffler

    Established Member From Bucks
    • Messages
      198
    • Reaction score
      247
    • Points
      75
  • 1

    csimeon

    Standard Member From Athens, Greece
    • Messages
      42
    • Reaction score
      32
    • Points
      15
  • 1

    CX8

    Novice Member From Stockholm, Sweden
    • Messages
      5
    • Reaction score
      0
    • Points
      1
  • 1

    splreece25

    Novice Member From Durham uk
    • Messages
      2
    • Reaction score
      0
    • Points
      1
  • 1

    JasonSivyerUK

    Standard Member From South Coast, UK
    • Messages
      5
    • Reaction score
      7
    • Points
      2
  • Back
    Top Bottom