/** Test to see if this non terminal currently looks nullable. */ protected boolean looks_nullable() throws internal_error { /* look and see if any of the productions now look nullable */ for (Enumeration e = productions(); e.hasMoreElements(); ) /* if the production can go to empty, we are nullable */ if (((production)e.nextElement()).check_nullable()) return true; /* none of the productions can go to empty, so we are not nullable */ return false; }
/** Equality comparison for the core only. This is separate out because we * need separate access in a super class. */ public boolean core_equals(lr_item_core other) { return other != null && _the_production.equals(other._the_production) && _dot_pos == other._dot_pos; }
/** Compute a hash code. */ public int hashCode() { /* use the hash code of the production we are reducing with */ return reduce_with().hashCode(); }
/** Convert to a string. */ public String toString() { String result; /* catch any internal errors */ try { result = "production [" + index() + "]: "; result += ((lhs() != null) ? lhs().toString() : "$$NULL-LHS$$"); result += " :: = "; for (int i = 0; i<rhs_length(); i++) result += rhs(i) + " "; result += ";"; if (action() != null && action().code_string() != null) result += " {" + action().code_string() + "}"; if (nullable_known()) if (nullable()) result += "[NULLABLE]"; else result += "[NOT NULLABLE]"; } catch (internal_error e) { /* crash on internal error since we can't throw it from here (because superclass does not throw anything. */ e.crash(); result = null; } return result; }
/** Convert to a simpler string. */ public String to_simple_string() throws internal_error { String result; result = ((lhs() != null) ? lhs().the_symbol().name() : "NULL_LHS"); result += " ::= "; for (int i = 0; i < rhs_length(); i++) if (!rhs(i).is_action()) result += ((symbol_part)rhs(i)).the_symbol().name() + " "; return result; }
all_prods = new production[production.number()]; for (Enumeration p = production.all(); p.hasMoreElements(); ) all_prods[prod.index()] = prod; short[][] prod_table = new short[production.number()][2]; for (int i = 0; i<production.number(); i++) prod_table[i][0] = (short) prod.lhs().the_symbol().index(); prod_table[i][1] = (short) prod.rhs_length();
declare_str = declare_labels( rhs_parts, rightlen, action_str); _rhs_length = merge_adjacent_actions(rhs_parts, _rhs_length); tail_action = strip_trailing_action(rhs_parts, _rhs_length); if (tail_action != null) _rhs_length--; remove_embedded_actions();
for (e=production.all(); e.hasMoreElements(); ) prod.set_nullable(prod.check_nullable());
/** 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) throws internal_error { symbol after_dot = null; 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.hashCode() + 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(); } }
for (part=0; part<rhs_length(); part++) if (!rhs(part).is_action()) sym = ((symbol_part)rhs(part)).the_symbol(); return first_set();
for (p=production.all(); p.hasMoreElements(); ) System.err.print(prod.lhs().the_symbol().name() + " ::= "); for (int i=0; i<prod.rhs_length(); i++) if (prod.rhs(i).is_action()) System.err.print("{action} "); else System.err.print( ((symbol_part)prod.rhs(i)).the_symbol().name() + " "); System.err.println();
action_str = translate_labels( rhs_parts, rhs_l, action_str, lhs_sym.stack_type()); _rhs_length = merge_adjacent_actions(rhs_parts, _rhs_length); tail_action = strip_trailing_action(rhs_parts, _rhs_length); if (tail_action != null) _rhs_length--; remove_embedded_actions();
/** Convert to string. */ public String toString() { return "REDUCE(with prod " + reduce_with().index() + ")"; }
/** Determine if a character can be in a label id. * @param c the character in question. */ protected static boolean is_id_char(char c) { return is_id_start(c) || (c >= '0' && c <= '9'); }
prod_first = prod.check_first_set();
/** Add a production to our set of productions. */ public void add_production(production prod) throws internal_error { /* catch improper productions */ if (prod == null || prod.lhs() == null || prod.lhs().the_symbol() != this) throw new internal_error( "Attempt to add invalid production to non terminal production table"); /* add it to the table, keyed with itself */ _productions.put(prod,prod); }
if (!is_id_char(buffer[pos])) label_translate(id_str, act_pos, label_map,label_types)); if (is_id_start(buffer[pos]))
_first_set.add(((non_terminal)sym).first_set());
/** Convert to a string. */ public String toString() { String result; /* catch any internal errors */ try { result = "production [" + index() + "]: "; result += ((lhs() != null) ? lhs().toString() : "$$NULL-LHS$$"); result += " :: = "; for (int i = 0; i<rhs_length(); i++) result += rhs(i) + " "; result += ";"; if (action() != null && action().code_string() != null) result += " {" + action().code_string() + "}"; if (nullable_known()) if (nullable()) result += "[NULLABLE]"; else result += "[NOT NULLABLE]"; } catch (internal_error e) { /* crash on internal error since we can't throw it from here (because superclass does not throw anything. */ e.crash(); result = null; } return result; }
all_prods = new production[production.number()]; for (Enumeration p = production.all(); p.hasMoreElements(); ) all_prods[prod.index()] = prod; short[][] prod_table = new short[production.number()][2]; for (int i = 0; i<production.number(); i++) prod_table[i][0] = (short) prod.lhs().the_symbol().index(); prod_table[i][1] = (short) prod.rhs_length();