Fields Summary |
---|
protected static Hashtable | _allTable of all non-terminals -- elements are stored using name strings
as the key |
protected static Hashtable | _all_by_indexTable of all non terminals indexed by their index number. |
protected static int | next_indexStatic counter to assign unique indexes. |
protected static int | next_ntStatic counter for creating unique non-terminal names |
public static final non_terminal | START_ntspecial non-terminal for start symbol |
public boolean | is_embedded_actionflag non-terminals created to embed action productions |
protected Hashtable | _productionsTable of all productions with this non terminal on the LHS. |
protected boolean | _nullableNullability of this non terminal. |
protected terminal_set | _first_setFirst set for this non-terminal. |
Methods Summary |
---|
public void | add_production(production prod)Add a production to our set of productions.
/* 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);
|
public static java.util.Enumeration | all()Access to all non-terminals.
return _all.elements();
|
public static void | compute_first_sets()Compute first sets for all non-terminals. This assumes nullability has
already computed.
boolean change = true;
Enumeration n;
Enumeration p;
non_terminal nt;
production prod;
terminal_set prod_first;
/* repeat this process until we have no change */
while (change)
{
/* look for a new change */
change = false;
/* consider each non-terminal */
for (n = all(); n.hasMoreElements(); )
{
nt = (non_terminal)n.nextElement();
/* consider every production of that non terminal */
for (p = nt.productions(); p.hasMoreElements(); )
{
prod = (production)p.nextElement();
/* get the updated first of that production */
prod_first = prod.check_first_set();
/* if this going to add anything, add it */
if (!prod_first.is_subset_of(nt._first_set))
{
change = true;
nt._first_set.add(prod_first);
}
}
}
}
|
public static void | compute_nullability()Compute nullability of all non-terminals.
boolean change = true;
non_terminal nt;
Enumeration e;
production prod;
/* repeat this process until there is no change */
while (change)
{
/* look for a new change */
change = false;
/* consider each non-terminal */
for (e=all(); e.hasMoreElements(); )
{
nt = (non_terminal)e.nextElement();
/* only look at things that aren't already marked nullable */
if (!nt.nullable())
{
if (nt.looks_nullable())
{
nt._nullable = true;
change = true;
}
}
}
}
/* do one last pass over the productions to finalize all of them */
for (e=production.all(); e.hasMoreElements(); )
{
prod = (production)e.nextElement();
prod.set_nullable(prod.check_nullable());
}
|
static com.sun.java_cup.internal.non_terminal | create_new(java.lang.String prefix)Method for creating a new uniquely named hidden non-terminal using
the given string as a base for the name (or "NT$" if null is passed). /* added 24-Mar-1998, CSA */
/*-----------------------------------------------------------*/
/*--- Static Methods ----------------------------------------*/
/*-----------------------------------------------------------*/
if (prefix == null) prefix = "NT$";
return new non_terminal(prefix + next_nt++);
|
static com.sun.java_cup.internal.non_terminal | create_new()static routine for creating a new uniquely named hidden non-terminal
return create_new(null);
|
public static com.sun.java_cup.internal.non_terminal | find(java.lang.String with_name)lookup a non terminal by name string
if (with_name == null)
return null;
else
return (non_terminal)_all.get(with_name);
|
public static com.sun.java_cup.internal.non_terminal | find(int indx)Lookup a non terminal by index.
Integer the_indx = new Integer(indx);
return (non_terminal)_all_by_index.get(the_indx);
|
public terminal_set | first_set()First set for this non-terminal.
return _first_set;
|
public boolean | is_non_term()Indicate that this symbol is a non-terminal.
return true;
|
protected boolean | looks_nullable()Test to see if this non terminal currently looks nullable.
/* 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;
|
public boolean | nullable()Nullability of this non terminal.return _nullable;
|
public int | num_productions()Total number of productions with this non terminal on the LHS.return _productions.size();
|
public static int | number()Total number of non-terminals.return _all.size();
|
public java.util.Enumeration | productions()Access to productions with this non terminal on the LHS.
return _productions.elements();
|
public java.lang.String | toString()convert to string
return super.toString() + "[" + index() + "]" + (nullable() ? "*" : "");
|