FACTOID # 141: Norwegians drink 10.7 kilograms of coffee per person each year. They also lead the globe in anxiety disorders. Maybe it’s time to switch to herbal tea.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Canonical LR parser

A canonical LR parser or LR(1) parser is an LR parser whose parsing tables are constructed in a similar way as with LR(0) parsers except that the items in the item sets also contain a follow, i.e., a terminal that is expected by the parser after the right-hand side of the rule. For example, such an item for a rule A → B C might be In computer science, an LR parser is a type of bottom-up parser for context-free grammars that is very commonly used by computer programming language compilers (and other associated tools). ... In computer science, an LR parser is a type of bottom-up parser for context-free grammars that is very commonly used by computer programming language compilers (and other associated tools). ... A parser is a computer program or a component of a program that analyses the grammatical structure of an input, with respect to a given formal grammar, a process known as parsing. ...

A → B · C, a

which would mean that the parser has read a string corresponding to B and expects next a string corresponding to C followed by the terminal 'a'. LR(1) parsers can deal with a very large class of grammars but their parsing tables are often very big. This can often be solved by merging item sets if they are identical except for the follows, which results in so-called LALR parsers. Look-Ahead LR parsers or LALR parsers are a specialized form of LR parsers that can deal with more context-free grammars than Simple LR parsers but less than LR(1) parsers can. ...

Contents

Constructing LR(1) parsing tables

An LR(1) item is a production with a marker together with a terminal, e.g., [S → a A · B e, c]. Intuitively, such an item indicates how much of a certain production we have seen already (a A), what we could expect next (B e), and a lookahead that agrees with what should follow in the input if we ever reduce by the production S → a A B e. By incorporating such lookahead information into the item concept, we can make more wise reduce decisions. The lookahead of an LR(1) item is used directly only when considering reduce actions (i.e., when the · marker is at the right end).


The core of an LR(1) item [S → a A · B e, c] is the LR(0) item S → a A · B e. Different LR(1) items may share the same core. For example, if we have two LR(1) items of the form

  • [A → α ·, a] and
  • [B → α ·, b],

we take advantage of the lookahead to decide which reduction to use. (The same setting would perhaps produce a reduce/reduce conflict in the SLR approach.)


Validity

The notion of validity changes. An item [A → β1 · β2, a] is valid for a viable prefix α β1 if there is a rightmost derivation that yields α A a w which in one step yields α β1β2 a w


Initial item

To get the parsing started, we begin with the initial item of

[S’ → · S, $].

Here $ is a special character denoting the end of the string.


Closure

Closure is more refined. If [A → α · B β, a] belongs to the set of items, and B → γ is a production of the grammar, then we add the item [B → · γ, b] for all b in FIRST(β a).


Every state is closed according to Closure.


Goto

Goto is the same. A state containing [A → α · X β, a] will move to a state containing [A → α X · β, a] with label X.


Every state has transitions according to Goto.


Shift actions

The shift actions are the same. If [A → α · b β, a] is in state Ik and Ik moves to state Im with label b, then we add the action

action[k, b] = "shift m"

Reduce actions

The reduce actions are more refined. If [A→α., a] is in state Ik, then we add the action: "Reduce A → α" to action[Ik, a]. Observe that we don’t use information from FOLLOW(A) anymore. The goto part of the table is as before.

S’ → S
S → CC
C → c C | d
FIRST
S c d
C c d
S’ → S
S → L = R | R
L → * R | id
R → L
FIRST
S * id
L * id
R * id

References

 See Discussion: http://www.cse.uconn.edu/~akiayias/cse244fa04/N244-4-LR-more.ppt 

  Results from FactBites:
 
LR parser (2238 words)
An LR parser is a type of parser for context-free grammars that is very commonly used by computer programming language compilers (and other associated tools).
Of all parsers that scan their input left to right, LR parsers detect syntactic errors (that is, when their input does not conform to the grammar) as soon as it possible to do.
LR parsers are difficult to produce by hand; they are usually constructed by a parser generator or a compiler-compiler.
Kids.Net.Au - Encyclopedia > Parser (279 words)
A parser is a computer program or a component of a program that analyses the grammatical structure of an input, with respect to a given formal grammar.
Parsers can be made both for natural languages and for programming languages.
For example LALR parsers are capable of efficiently analysing a wide class of context free grammars.
  More results at FactBites »


 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m