/** Produce a (semi-) human readable dump of the complete viable prefix * recognition state machine. */ public static void dump_machine() { lalr_state ordered[] = new lalr_state[lalr_state.number()]; /* put the states in sorted order for a nicer display */ for (Enumeration s = lalr_state.all(); s.hasMoreElements(); ) { lalr_state st = (lalr_state)s.nextElement(); ordered[st.index()] = st; } System.err.println("===== Viable Prefix Recognizer ====="); for (int i = 0; i<lalr_state.number(); i++) { if (ordered[i] == start_state) System.err.print("START "); System.err.println(ordered[i]); System.err.println("-------------------"); } }
/** Generic equality comparison. */ public boolean equals(Object other) { if (!(other instanceof lalr_state)) return false; else return equals((lalr_state)other); }
/** Compute a hash code. */ public int hashCode() { /* use the hash code of the state we are shifting to */ return shift_to().hashCode(); }
/** Propagate lookahead sets through the constructed viable prefix * recognizer. When the machine is constructed, each item that results in the creation of another such that its lookahead is included in the other's will have a propagate link set up for it. This allows additions to the lookahead of one item to be included in other items that it was used to directly or indirectly create. */ protected static void propagate_all_lookaheads() throws internal_error { /* iterate across all states */ for (Enumeration st = all(); st.hasMoreElements(); ) { /* propagate lookaheads out of that state */ ((lalr_state)st.nextElement()).propagate_lookaheads(); } }
/** Convert to a string. */ public String toString() { String result; lalr_transition tr; /* dump the item set */ result = "lalr_state [" + index() + "]: " + _items + "\n"; /* do the transitions */ for (tr = transitions(); tr != null; tr = tr.next()) { result += tr; result += "\n"; } return result; }
start_state = new lalr_state(start_items); work_stack.push(start_state); for (i = st.items().all(); i.hasMoreElements(); ) for (i = st.items().all(); i.hasMoreElements();) new_st = new lalr_state(new_items); existing = new_st.items().find(new_itm); st.add_transition(sym, new_st); propagate_all_lookaheads();
start_state = lalr_state.build_machine(emit.start_production); action_table = new parse_action_table(); reduce_table = new parse_reduce_table(); for (Enumeration st = lalr_state.all(); st.hasMoreElements(); ) lst.build_table_entries( action_table, reduce_table);
/** Convert to a string. */ public String toString() {return "SHIFT(to state " + shift_to().index() + ")";}
start_state = lalr_state.build_machine(emit.start_production); lst.build_table_entries( action_table, reduce_table);
/** Constructor for building a state from a set of items. * @param itms the set of items that makes up this state. */ public lalr_state(lalr_item_set itms) throws internal_error { /* don't allow null or duplicate item sets */ if (itms == null) throw new internal_error( "Attempt to construct an LALR state from a null item set"); if (find_state(itms) != null) throw new internal_error( "Attempt to construct a duplicate LALR state"); /* assign a unique index */ _index = next_index++; /* store the items */ _items = itms; /* add to the global collection, keyed with its item set */ _all.put(_items,this); }
start_state = new lalr_state(start_items); work_stack.push(start_state); for (i = st.items().all(); i.hasMoreElements(); ) for (i = st.items().all(); i.hasMoreElements();) new_st = new lalr_state(new_items); existing = new_st.items().find(new_itm); st.add_transition(sym, new_st); propagate_all_lookaheads();
start_state = lalr_state.build_machine(emit.start_production); action_table = new parse_action_table(); reduce_table = new parse_reduce_table(); for (Enumeration st = lalr_state.all(); st.hasMoreElements(); ) lst.build_table_entries( action_table, reduce_table);
/** Propagate lookahead sets through the constructed viable prefix * recognizer. When the machine is constructed, each item that results in the creation of another such that its lookahead is included in the other's will have a propagate link set up for it. This allows additions to the lookahead of one item to be included in other items that it was used to directly or indirectly create. */ protected static void propagate_all_lookaheads() throws internal_error { /* iterate across all states */ for (Enumeration st = all(); st.hasMoreElements(); ) { /* propagate lookaheads out of that state */ ((lalr_state)st.nextElement()).propagate_lookaheads(); } }
/** Convert to a string. */ public String toString() { String result; lalr_transition tr; /* dump the item set */ result = "lalr_state [" + index() + "]: " + _items + "\n"; /* do the transitions */ for (tr = transitions(); tr != null; tr = tr.next()) { result += tr; result += "\n"; } return result; }
/** Convert to a string. */ public String toString() {return "SHIFT(to state " + shift_to().index() + ")";}
/** Constructor for building a state from a set of items. * @param itms the set of items that makes up this state. */ public lalr_state(lalr_item_set itms) throws internal_error { /* don't allow null or duplicate item sets */ if (itms == null) throw new internal_error( "Attempt to construct an LALR state from a null item set"); if (find_state(itms) != null) throw new internal_error( "Attempt to construct a duplicate LALR state"); /* assign a unique index */ _index = next_index++; /* store the items */ _items = itms; /* add to the global collection, keyed with its item set */ _all.put(_items,this); }