net.sourceforge.chaperon.build
Class ItemSet

java.lang.Object
  extended bynet.sourceforge.chaperon.build.ItemSet

public class ItemSet
extends java.lang.Object

This class represents a set of items, which means positions of production, in production and lookahead symbols. These item sets were used to decribes states.

Version:
CVS $Id: ItemSet.java,v 1.17 2003/12/09 19:55:52 benedikta Exp $
Author:
Stephan Michels

Constructor Summary
ItemSet(Grammar grammar, FirstSetCollection firstsets)
          Create an empty set of items.
 
Method Summary
 boolean addItem(int production, int position, Symbol lookahead)
          Add a item to this set.
 boolean addItem(int production, int position, SymbolSet lookaheads)
           
 boolean addItemSet(ItemSet I)
          Add the items from another itemset to this set.
 ItemSet closure()
          Calculate the closure for this item set.
 boolean contains(ItemSet itemset)
          Test, if all items from a other state exists in this state
 boolean equals(java.lang.Object o)
          Compares two item sets.
 boolean equalsCore(java.lang.Object o)
          Compares the core of two item sets.
 int getItemCount()
          Returns the count of items in this set.
 Error getNextError()
           
 SymbolSet getNextNonterminals()
           
 SymbolSet getNextTerminals()
           
 IntegerSet getReduceProductions()
          Returns the list of productions, which could be reduced.
 IntegerSet getReduceProductions(Symbol lookahead)
          Returns the list of productions, which a special symbol reduce.
 SymbolSet getReduceSymbols()
          Return all symbols, which reduce productions in this state.
 SymbolSet getShiftSymbols()
          Returns all symbols, which forces a transition.
 int getTransition(Symbol symbol)
          Returns the destination state of a transition.
 boolean isEmpty()
          Returns true, if this set is empty.
 ItemSet jump(Symbol symbol)
          Calculates the next state by a transition through the symbol X.
 void setTransition(Symbol symbol, int state)
          Add a transition to this state.
 java.lang.String toString()
          Return a string representation of this item set.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ItemSet

public ItemSet(Grammar grammar,
               FirstSetCollection firstsets)
Create an empty set of items.

Parameters:
grammar - Grammar.
firstsets - The first sets.
Method Detail

addItem

public boolean addItem(int production,
                       int position,
                       Symbol lookahead)
Add a item to this set.

Parameters:
production - Production.
position - Position in this production.
lookahead - Lookahead symbol.
Returns:
True, if this item was added

addItem

public boolean addItem(int production,
                       int position,
                       SymbolSet lookaheads)

addItemSet

public boolean addItemSet(ItemSet I)
Add the items from another itemset to this set. If this set changed the method will return true.

Parameters:
I - ItemSet, which should be addded.
Returns:
True, if this set was changed

contains

public boolean contains(ItemSet itemset)
Test, if all items from a other state exists in this state

Parameters:
itemset - Other item set.
Returns:
True, if the state contains all items.

getItemCount

public int getItemCount()
Returns the count of items in this set.

Returns:
Count of items of the core.

isEmpty

public boolean isEmpty()
Returns true, if this set is empty.

Returns:
True, if this set is empty.

equals

public boolean equals(java.lang.Object o)
Compares two item sets.

Parameters:
o - Other itemset.
Returns:
True, if the item sets are equal.

equalsCore

public boolean equalsCore(java.lang.Object o)
Compares the core of two item sets.

Parameters:
o - Other itemset.
Returns:
True, if the core of the itemsets are equal.

getNextTerminals

public SymbolSet getNextTerminals()

getNextNonterminals

public SymbolSet getNextNonterminals()

getNextError

public Error getNextError()

closure

public ItemSet closure()
Calculate the closure for this item set.

Returns:
Closure of the item set

jump

public ItemSet jump(Symbol symbol)
Calculates the next state by a transition through the symbol X.

Parameters:
symbol - A Symbol, which can be a terminal or a nonterminal symbol.
Returns:
The next state, represented by an item set.

setTransition

public void setTransition(Symbol symbol,
                          int state)
Add a transition to this state.

Parameters:
symbol - Symbol, which forces a transition into another state.
state - Destination state.

getTransition

public int getTransition(Symbol symbol)
Returns the destination state of a transition.

Parameters:
symbol - Symbol, which force the transition.
Returns:
Destination state.

getShiftSymbols

public SymbolSet getShiftSymbols()
Returns all symbols, which forces a transition.

Returns:
List of symbols.

getReduceProductions

public IntegerSet getReduceProductions()
Returns the list of productions, which could be reduced.

Returns:
List of indicies for the productions.

getReduceProductions

public IntegerSet getReduceProductions(Symbol lookahead)
Returns the list of productions, which a special symbol reduce.

Parameters:
lookahead - Symbol, which the productions reduce.
Returns:
Set of indicies from the productions.

getReduceSymbols

public SymbolSet getReduceSymbols()
Return all symbols, which reduce productions in this state.

Returns:
Set of symbols.

toString

public java.lang.String toString()
Return a string representation of this item set.

Returns:
String representation of this item set.


Copyright ? 2003 Chaperon project. All Rights Reserved.