Top Description Fields Constructors Methods
java_cup

public Class lalr_item_set

extends Object
Class Inheritance
Imports
java.util.Hashtable, .Enumeration

This class represents a set of LALR items. For purposes of building these sets, items are considered unique only if they have unique cores (i.e., ignoring differences in their lookahead sets).

This class provides fairly conventional set oriented operations (union, sub/super-set tests, etc.), as well as an LALR "closure" operation (see compute_closure()).

Author
Scott Hudson
Version
last updated: 3/6/96
See Also
java_cup.lalr_item, java_cup.lalr_state

Field Summary

Modifier and TypeField and Description
protected Hashtable<K, V>
_all

A hash table to implement the set.

protected Integer
hashcode_cache

Cached hashcode for this set.

Constructor Summary

AccessConstructor and Description
public
lalr_item_set()

Constructor for an empty set.

public
lalr_item_set(lalr_item_set
indicates set we should copy from.
other
)

Constructor for cloning from another set.

Method Summary

Modifier and TypeMethod and Description
public lalr_item
add(lalr_item
the item being added.
itm
)

Add a singleton item, merging lookahead sets if the item is already part of the set.

public void
add(lalr_item_set
the set to be added.
other
)

Add a complete set, merging lookaheads where items are already in the set

public Enumeration<E>
all()

Access to all elements of the set.

public void
compute_closure()

Compute the closure of the set using the LALR closure rules.

public boolean
contains(lalr_item
the item in question.
itm
)

Does the set contain a particular item?

public boolean
equals(lalr_item_set other)

Equality comparison.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Generic equality comparison.
public lalr_item
find(lalr_item
the item we are looking for.
itm
)

Return the item in the set matching a particular item (or null if not found)

public lalr_item
get_one()

Remove and return one item from the set (done in hash order).

public int
hashCode()

Overrides java.lang.Object.hashCode.

Return hash code.
public boolean
is_subset_of(lalr_item_set
the other set in question.
other
)

Is this set an (improper) subset of another?

public boolean
is_superset_of(lalr_item_set
the other set in question.
other
)

Is this set an (improper) superset of another?

protected void
not_null(Object
the object we are testing.
obj
)

Helper function for null test.

public void
remove(lalr_item
the item to remove.
itm
)

Remove a single item if it is in the set.

public void
remove(lalr_item_set
the set to remove.
other
)

Remove (set subtract) a complete set.

public int
size()

Size of the set

public String
toString()

Overrides java.lang.Object.toString.

Convert to string.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

_allback to summary
protected Hashtable<K, V> _all

A hash table to implement the set. We store the items using themselves as keys.

hashcode_cacheback to summary
protected Integer hashcode_cache

Cached hashcode for this set.

Constructor Detail

lalr_item_setback to summary
public lalr_item_set()

Constructor for an empty set.

lalr_item_setback to summary
public lalr_item_set(lalr_item_set other) throws internal_error

Constructor for cloning from another set.

Parameters
other:lalr_item_set

indicates set we should copy from.

Method Detail

addback to summary
public lalr_item add(lalr_item itm) throws internal_error

Add a singleton item, merging lookahead sets if the item is already part of the set. returns the element of the set that was added or merged into.

Parameters
itm:lalr_item

the item being added.

addback to summary
public void add(lalr_item_set other) throws internal_error

Add a complete set, merging lookaheads where items are already in the set

Parameters
other:lalr_item_set

the set to be added.

allback to summary
public Enumeration<E> all()

Access to all elements of the set.

compute_closureback to summary
public void compute_closure() throws internal_error

Compute the closure of the set using the LALR closure rules. Basically for every item of the form:

  [L ::= a *N alpha, l] 
(where N is a a non terminal and alpha is a string of symbols) make sure there are also items of the form:
  [N ::= *beta, first(alpha l)] 
corresponding to each production of N. Items with identical cores but differing lookahead sets are merged by creating a new item with the same core and the union of the lookahead sets (the LA in LALR stands for "lookahead merged" and this is where the merger is). This routine assumes that nullability and first sets have been computed for all productions before it is called.
containsback to summary
public boolean contains(lalr_item itm)

Does the set contain a particular item?

Parameters
itm:lalr_item

the item in question.

equalsback to summary
public boolean equals(lalr_item_set other)

Equality comparison.

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Generic equality comparison.

Parameters
other:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

findback to summary
public lalr_item find(lalr_item itm)

Return the item in the set matching a particular item (or null if not found)

Parameters
itm:lalr_item

the item we are looking for.

get_oneback to summary
public lalr_item get_one() throws internal_error

Remove and return one item from the set (done in hash order).

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Return hash code.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

is_subset_ofback to summary
public boolean is_subset_of(lalr_item_set other) throws internal_error

Is this set an (improper) subset of another?

Parameters
other:lalr_item_set

the other set in question.

is_superset_ofback to summary
public boolean is_superset_of(lalr_item_set other) throws internal_error

Is this set an (improper) superset of another?

Parameters
other:lalr_item_set

the other set in question.

not_nullback to summary
protected void not_null(Object obj) throws internal_error

Helper function for null test. Throws an interal_error exception if its parameter is null.

Parameters
obj:Object

the object we are testing.

removeback to summary
public void remove(lalr_item itm) throws internal_error

Remove a single item if it is in the set.

Parameters
itm:lalr_item

the item to remove.

removeback to summary
public void remove(lalr_item_set other) throws internal_error

Remove (set subtract) a complete set.

Parameters
other:lalr_item_set

the set to remove.

sizeback to summary
public int size()

Size of the set

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Convert to string.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.