/** Constructor with default position and empty lookahead set. * @param prod the production for the item. */ public lalr_item(production prod) throws internal_error { this(prod,0,new terminal_set()); }
/** Determine if the set is empty. */ public boolean empty() { return equals(EMPTY); }
/** Determine if this set is an (improper) superset of another. * @param other the set we are testing against. */ public boolean is_superset_of(terminal_set other) throws internal_error { not_null(other); return other.is_subset_of(this); }
parse_action act, other_act; symbol sym; terminal_set conflict_set = new terminal_set(); if (!itm.lookahead().contains(t)) continue; conflict_set.add(term); conflict_set.add(terminal.find(sym.index())); if (!conflict_set.empty()) report_conflicts(conflict_set);
conflict_set = new terminal_set(); if (compare.lookahead().intersects(itm.lookahead())) if (itm.lookahead().contains((terminal)shift_sym)) conflict_set.add((terminal)shift_sym); if (conflict_set.contains(t)) report_shift_reduce(itm,t);
/** Propagate incoming lookaheads through this item to others need to * be changed. * @params incoming symbols to potentially be added to lookahead of this item. */ public void propagate_lookaheads(terminal_set incoming) throws internal_error { boolean change = false; /* if we don't need to propagate, then bail out now */ if (!needs_propagation && (incoming == null || incoming.empty())) return; /* if we have null incoming, treat as an empty set */ if (incoming != null) { /* add the incoming to the lookahead of this item */ change = lookahead().add(incoming); } /* if we changed or need it anyway, propagate across our links */ if (change || needs_propagation) { /* don't need to propagate again */ needs_propagation = false; /* propagate our lookahead into each item we are linked to */ for (int i = 0; i < propagate_items().size(); i++) ((lalr_item)propagate_items().elementAt(i)) .propagate_lookaheads(lookahead()); } }
if (!prod_first.is_subset_of(nt._first_set)) nt._first_set.add(prod_first);
if (compare.lookahead().intersects(itm.lookahead())) if (conflict_set.contains(t) && lookahead.contains(t)) report_shift_reduce(itm,t);
result = new terminal_set(); result.add((terminal)sym); return result; result.add(((non_terminal)sym).first_set()); result.add(lookahead_after); return result;
/** Determine if this set intersects another. * @param other the other set in question. */ public boolean intersects(terminal_set other) throws internal_error { not_null(other); return _elements.intersects(other._elements); }
/** 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. * @param itm the item being added. */ public lalr_item add(lalr_item itm) throws internal_error { lalr_item other; not_null(itm); /* see if an item with a matching core is already there */ other = (lalr_item)_all.get(itm); /* if so, merge this lookahead into the original and leave it */ if (other != null) { other.lookahead().add(itm.lookahead()); return other; } /* otherwise we just go in the set */ else { /* invalidate cached hashcode */ hashcode_cache = null; _all.put(itm,itm); return itm; } }
parse_action act, other_act; symbol sym; terminal_set conflict_set = new terminal_set(); if (!itm.lookahead().contains(t)) continue; conflict_set.add(term); conflict_set.add(terminal.find(sym.index())); if (!conflict_set.empty()) report_conflicts(conflict_set);
/** Propagate incoming lookaheads through this item to others need to * be changed. * @params incoming symbols to potentially be added to lookahead of this item. */ public void propagate_lookaheads(terminal_set incoming) throws internal_error { boolean change = false; /* if we don't need to propagate, then bail out now */ if (!needs_propagation && (incoming == null || incoming.empty())) return; /* if we have null incoming, treat as an empty set */ if (incoming != null) { /* add the incoming to the lookahead of this item */ change = lookahead().add(incoming); } /* if we changed or need it anyway, propagate across our links */ if (change || needs_propagation) { /* don't need to propagate again */ needs_propagation = false; /* propagate our lookahead into each item we are linked to */ for (int i = 0; i < propagate_items().size(); i++) ((lalr_item)propagate_items().elementAt(i)) .propagate_lookaheads(lookahead()); } }
if (!prod_first.is_subset_of(nt._first_set)) nt._first_set.add(prod_first);
if (compare.lookahead().intersects(itm.lookahead())) if (conflict_set.contains(t)) report_shift_reduce(itm,t);
result = new terminal_set(); result.add((terminal)sym); return result; result.add(((non_terminal)sym).first_set()); result.add(lookahead_after); return result;
/** Constructor for cloning from another set. * @param other the set we are cloning from. */ public terminal_set(terminal_set other) throws internal_error { not_null(other); _elements = (BitSet)other._elements.clone(); }
/** 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. * @param itm the item being added. */ public lalr_item add(lalr_item itm) throws internal_error { lalr_item other; not_null(itm); /* see if an item with a matching core is already there */ other = (lalr_item)_all.get(itm); /* if so, merge this lookahead into the original and leave it */ if (other != null) { other.lookahead().add(itm.lookahead()); return other; } /* otherwise we just go in the set */ else { /* invalidate cached hashcode */ hashcode_cache = null; _all.put(itm,itm); return itm; } }