Class AssemblyParseStateItem

  • All Implemented Interfaces:
    java.lang.Comparable<AssemblyParseStateItem>

    public class AssemblyParseStateItem
    extends java.lang.Object
    implements java.lang.Comparable<AssemblyParseStateItem>
    An item in the state of an LR(0) parser An item is a production with a dot indicating a position while parsing
    • Constructor Detail

      • AssemblyParseStateItem

        public AssemblyParseStateItem​(AssemblyProduction prod)
        Construct a new item starting at the far left of the given production
        Parameters:
        prod - the production
      • AssemblyParseStateItem

        public AssemblyParseStateItem​(AssemblyProduction prod,
                                      int pos)
        Construct a new item starting immediately before the symbol at the given position in the given production
        Parameters:
        prod - the production
        pos - the position of the dot
    • Method Detail

      • read

        public AssemblyParseStateItem read()
        Advance the dot by one position, producing a new item
        Returns:
        the new item
      • getNext

        public AssemblySymbol getNext()
        Get the symbol immediately to the right of the dot This is the symbol which must be matched to advance the dot.
        Returns:
        the symbol, or null if the item is completed, i.e., the dot is at the far right
      • getClosure

        public java.util.Collection<AssemblyParseStateItem> getClosure​(AssemblyGrammar grammar)
        "Fill" one step out to close a state containing this item To compute the full closure, you must continue stepping out until no new items are generated
        Parameters:
        grammar - the grammar containing the production
        Returns:
        a subset of items in the closure of a state containing this item
      • equals

        public boolean equals​(java.lang.Object that)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • completed

        public boolean completed()
        Check if this item is completed The item is completed if all symbols have been matched, i.e., the dot is at the far right of the production.
        Returns:
        true iff the item is completed
      • getPos

        public int getPos()
        Get the position of the dot The position is the number of symbols to the left of the dot.
        Returns:
      • getProduction

        public AssemblyProduction getProduction()
        Get the production associated with this item
        Returns:
        the production