/*-----------------------------------------------------------*/ /*--- Constructor(s) ----------------------------------------*/ /*-----------------------------------------------------------*/ /** Full constructor. * @param prod production this item uses. * @param pos position of the "dot" within the item. */ public lr_item_core(production prod, int pos) { production_part part; if (prod == null) { throw new internal_error( "Attempt to create an lr_item_core with a null production"); } _the_production = prod; if (pos < 0 || pos > _the_production.rhs_length()) { throw new internal_error( "Attempt to create an lr_item_core with a bad dot position"); } _dot_pos = pos; /* compute and cache hash code now */ _core_hash_cache = 13 * _the_production.GetHashCode() + pos; /* cache the symbol after the dot */ if (_dot_pos < _the_production.rhs_length()) { part = _the_production.rhs(_dot_pos); if (!part.is_action()) { _symbol_after_dot = ((symbol_part)part).the_symbol(); } } }
/*-----------------------------------------------------------*/ /*--- Constructor(s) ----------------------------------------*/ /*-----------------------------------------------------------*/ /** Full constructor. * @param prod production this item uses. * @param pos position of the "dot" within the item. */ public lr_item_core(production prod, int pos) { production_part part; if (prod == null) throw new internal_error( "Attempt to create an lr_item_core with a null production"); _the_production = prod; if (pos < 0 || pos > _the_production.rhs_length()) throw new internal_error( "Attempt to create an lr_item_core with a bad dot position"); _dot_pos = pos; /* compute and cache hash code now */ _core_hash_cache = 13*_the_production.GetHashCode() + pos; /* cache the symbol after the dot */ if (_dot_pos < _the_production.rhs_length()) { part = _the_production.rhs(_dot_pos); if (!part.is_action()) _symbol_after_dot = ((symbol_part)part).the_symbol(); } }
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /** Convert to a string (separated out from ToString() so we can call it * from subclass that overrides ToString()). */ public string to_simple_string() { string result; production_part part; if (_the_production.lhs() != null && _the_production.lhs().the_symbol() != null && _the_production.lhs().the_symbol().name() != null) { result = _the_production.lhs().the_symbol().name(); } else { result = "$$NULL$$"; } result += " ::= "; for (int i = 0; i < _the_production.rhs_length(); i++) { /* do we need the dot before this one? */ if (i == _dot_pos) { result += "(*) "; } /* print the name of the part */ if (_the_production.rhs(i) == null) { result += "$$NULL$$ "; } else { part = _the_production.rhs(i); if (part == null) { result += "$$NULL$$ "; } else if (part.is_action()) { result += "{ACTION} "; } else if (((symbol_part)part).the_symbol() != null && ((symbol_part)part).the_symbol().name() != null) { result += ((symbol_part)part).the_symbol().name() + " "; } else { result += "$$NULL$$ "; } } } /* put the dot after if needed */ if (_dot_pos == _the_production.rhs_length()) { result += "(*) "; } return(result); }