Class AssemblyParseStateItem

java.lang.Object
ghidra.app.plugin.assembler.sleigh.parse.AssemblyParseStateItem
All Implemented Interfaces:
Comparable<AssemblyParseStateItem>

public class AssemblyParseStateItem extends Object implements 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 Details

    • 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 Details

    • 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 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(Object that)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(AssemblyParseStateItem that)
      Specified by:
      compareTo in interface Comparable<AssemblyParseStateItem>
    • hashCode

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

      public String toString()
      Overrides:
      toString in class 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