/** Add a complete set, merging lookaheads where items are already in * the set * @param other the set to be added. */ public void add(lalr_item_set other) throws internal_error { not_null(other); /* walk down the other set and do the adds individually */ for (Enumeration e = other.all(); e.hasMoreElements(); ) add((lalr_item)e.nextElement()); }
/** Is this set an (improper) subset of another? * @param other the other set in question. */ public boolean is_subset_of(lalr_item_set other) throws internal_error { not_null(other); /* walk down our set and make sure every element is in the other */ for (Enumeration e = all(); e.hasMoreElements(); ) if (!other.contains((lalr_item)e.nextElement())) return false; /* they were all there */ return true; }
/** Generic equality comparison. */ public boolean equals(Object other) { if (!(other instanceof lalr_item_set)) return false; else return equals((lalr_item_set)other); }
/** Is this set an (improper) superset of another? * @param other the other set in question. */ public boolean is_superset_of(lalr_item_set other) throws internal_error { not_null(other); return other.is_subset_of(this); }
/** Remove (set subtract) a complete set. * @param other the set to remove. */ public void remove(lalr_item_set other) throws internal_error { not_null(other); /* walk down the other set and do the removes individually */ for (Enumeration e = other.all(); e.hasMoreElements(); ) remove((lalr_item)e.nextElement()); }
start_items = new lalr_item_set(); start_items.add(itm); kernel = new lalr_item_set(start_items); start_items.compute_closure(); for (i = st.items().all(); i.hasMoreElements(); ) linked_items = new lalr_item_set(); new_items = new lalr_item_set(); for (i = st.items().all(); i.hasMoreElements();) new_items.add(itm.shift()); linked_items.add(itm); kernel = new lalr_item_set(new_items); new_items.compute_closure(); for (fix = linked_items.all(); fix.hasMoreElements(); ) existing = new_st.items().find(new_itm);
consider = new lalr_item_set(this); while (consider.size() > 0) itm = consider.get_one(); add_itm = add(new_itm); consider.add(new_itm);
/** Equality comparison. */ public boolean equals(lalr_item_set other) { if (other == null || other.size() != size()) return false; /* once we know they are the same size, then improper subset does test */ try { return is_subset_of(other); } catch (internal_error e) { /* can't throw error from here (because superclass doesn't) so crash */ e.crash(); return false; } }
/** Remove and return one item from the set (done in hash order). */ public lalr_item get_one() throws internal_error { Enumeration the_set; lalr_item result; the_set = all(); if (the_set.hasMoreElements()) { result = (lalr_item)the_set.nextElement(); remove(result); return result; } else return null; }
/** Convert to string. */ public String toString() { StringBuffer result = new StringBuffer(); result.append("{\n"); for (Enumeration e=all(); e.hasMoreElements(); ) { result.append(" " + (lalr_item)e.nextElement() + "\n"); } result.append("}"); return result.toString(); } /*-----------------------------------------------------------*/
consider = new lalr_item_set(this); itm = consider.get_one(); add_itm = add(new_itm); consider.add(new_itm);
/** Produce a hash code. */ public int hashCode() { /* just use the item set hash code */ return items().hashCode(); }
start_items = new lalr_item_set(); start_items.add(itm); kernel = new lalr_item_set(start_items); start_items.compute_closure(); for (i = st.items().all(); i.hasMoreElements(); ) linked_items = new lalr_item_set(); new_items = new lalr_item_set(); for (i = st.items().all(); i.hasMoreElements();) new_items.add(itm.shift()); linked_items.add(itm); kernel = new lalr_item_set(new_items); new_items.compute_closure(); for (fix = linked_items.all(); fix.hasMoreElements(); ) existing = new_st.items().find(new_itm);
consider = new lalr_item_set(this); while (consider.size() > 0) itm = consider.get_one(); add_itm = add(new_itm); consider.add(new_itm);
/** Remove (set subtract) a complete set. * @param other the set to remove. */ public void remove(lalr_item_set other) throws internal_error { not_null(other); /* walk down the other set and do the removes individually */ for (Enumeration e = other.all(); e.hasMoreElements(); ) remove((lalr_item)e.nextElement()); }
/** Is this set an (improper) superset of another? * @param other the other set in question. */ public boolean is_superset_of(lalr_item_set other) throws internal_error { not_null(other); return other.is_subset_of(this); }
/** Equality comparison. */ public boolean equals(lalr_item_set other) { if (other == null || other.size() != size()) return false; /* once we know they are the same size, then improper subset does test */ try { return is_subset_of(other); } catch (internal_error e) { /* can't throw error from here (because superclass doesn't) so crash */ e.crash(); return false; } }
/** Remove and return one item from the set (done in hash order). */ public lalr_item get_one() throws internal_error { Enumeration the_set; lalr_item result; the_set = all(); if (the_set.hasMoreElements()) { result = (lalr_item)the_set.nextElement(); remove(result); return result; } else return null; }
/** Convert to string. */ public String toString() { StringBuffer result = new StringBuffer(); result.append("{\n"); for (Enumeration e=all(); e.hasMoreElements(); ) { result.append(" " + (lalr_item)e.nextElement() + "\n"); } result.append("}"); return result.toString(); } /*-----------------------------------------------------------*/
/** Produce a hash code. */ public int hashCode() { /* just use the item set hash code */ return items().hashCode(); }