org.metasyntactic.math.automata
Class LR1Item

java.lang.Object
  |
  +--org.metasyntactic.math.automata.Production
        |
        +--org.metasyntactic.math.automata.LR0Item
              |
              +--org.metasyntactic.math.automata.LR1Item
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class LR1Item
extends LR0Item

An LR(1) item (item for short) of a grammar G is a production of G with a dot at some position of the right side. And a second component called the lookahead

See Also:
Serialized Form

Field Summary
protected  java.lang.Object lookahead
           
 
Fields inherited from class org.metasyntactic.math.automata.LR0Item
dotPosition
 
Fields inherited from class org.metasyntactic.math.automata.Production
variable, yield
 
Constructor Summary
LR1Item(LR1Item copy, int dotPosition)
           
LR1Item(java.lang.Object variable, Tuple yield, int dotPosition, java.lang.Object lookahead)
           
LR1Item(java.lang.Object variable, Tuple yield, java.lang.Object lookahead)
           
 
Method Summary
static java.util.Set _goto(AugmentedGrammar G_prime, java.util.Set I, java.lang.Object X)
          Goto(I, X) is defined to be the closure of the set of all items [A → αX.Β] such that [A → α.XΒ] is in I.
static java.util.Set closure(AugmentedGrammar G_prime, java.util.Set I)
          If I is a set of items for a grammar G, then closure(I) is the set of items constructed from I by the two rules: Initially, every item in I is added to closure(I) If A → α.BΒ is in closure(I) and B → γ is a production, then add the itm B → .γ to I, if is not already there.
 boolean equals(java.lang.Object o)
           
 java.lang.Object getLookahead()
           
 int hashCode()
           
static java.util.Set items(AugmentedGrammar G_prime)
          Items returns the canonical collection of sts of LRItems for an augmented grammar G'
static void main(java.lang.String[] args)
           
 java.lang.String toString()
           
 
Methods inherited from class org.metasyntactic.math.automata.LR0Item
getItems, getSymbolAtDot, isReduce, isShift
 
Methods inherited from class org.metasyntactic.math.automata.Production
compareTo, get, getVariable, getYield, toLatex
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

lookahead

protected java.lang.Object lookahead
Constructor Detail

LR1Item

public LR1Item(java.lang.Object variable,
               Tuple yield,
               int dotPosition,
               java.lang.Object lookahead)

LR1Item

public LR1Item(java.lang.Object variable,
               Tuple yield,
               java.lang.Object lookahead)

LR1Item

public LR1Item(LR1Item copy,
               int dotPosition)
Method Detail

getLookahead

public java.lang.Object getLookahead()

hashCode

public int hashCode()
Overrides:
hashCode in class LR0Item

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class LR0Item

toString

public java.lang.String toString()
Overrides:
toString in class LR0Item

items

public static java.util.Set items(AugmentedGrammar G_prime)
Description copied from class: LR0Item
Items returns the canonical collection of sts of LRItems for an augmented grammar G'


closure

public static java.util.Set closure(AugmentedGrammar G_prime,
                                    java.util.Set I)
Description copied from class: LR0Item
If I is a set of items for a grammar G, then closure(I) is the set of items constructed from I by the two rules:
  1. Initially, every item in I is added to closure(I)
  2. If A → α.BΒ is in closure(I) and B → γ is a production, then add the itm B → .γ to I, if is not already there. We apply the rule until no more new items can be added to closure(I).

Intuitively, A → α.Bβ in closure(I) indicates that, at some point in the parsing process, we think we might next see a substring derivable from BΒ as input. If B → γ is a production, we also expect we might see a substring drivable from γ at this point. For this reason we also include B → .γ in closure(I).


_goto

public static java.util.Set _goto(AugmentedGrammar G_prime,
                                  java.util.Set I,
                                  java.lang.Object X)
Description copied from class: LR0Item
Goto(I, X) is defined to be the closure of the set of all items [A → αX.Β] such that [A → α.XΒ] is in I. Intuitively, if I is the set of items that are valid for some viable prefix γ, then goto(I, X) is the set of items that are valid for the viable prefix X.


main

public static void main(java.lang.String[] args)