terminalpublic class terminal extends symbol This class represents a terminal symbol in the grammar. Each terminal
has a textual name, an index, and a string which indicates the type of
object it will be implemented with at runtime (i.e. the class of object
that will be returned by the scanner and pushed on the parse stack to
represent it). |
Fields Summary |
---|
private int | _precedence_num | private int | _precedence_side | protected static Hashtable | _allTable of all terminals. Elements are stored using name strings as
the key | protected static Hashtable | _all_by_indexTable of all terminals indexed by their index number. | protected static int | next_indexStatic counter to assign unique index. | public static final terminal | EOFSpecial terminal for end of input. | public static final terminal | errorspecial terminal used for error recovery |
Constructors Summary |
---|
public terminal(String nm, String tp, int precedence_side, int precedence_num)Full constructor.
/* superclass does most of the work */
super(nm, tp);
/* add to set of all terminals and check for duplicates */
Object conflict = _all.put(nm,this);
if (conflict != null)
// can't throw an execption here because this is used in static
// initializers, so we do a crash instead
// was:
// throw new internal_error("Duplicate terminal (" + nm + ") created");
(new internal_error("Duplicate terminal (" + nm + ") created")).crash();
/* assign a unique index */
_index = next_index++;
/* set the precedence */
_precedence_num = precedence_num;
_precedence_side = precedence_side;
/* add to by_index set */
_all_by_index.put(new Integer(_index), this);
| public terminal(String nm, String tp)Constructor for non-precedented terminal
this(nm, tp, assoc.no_prec, -1);
| public terminal(String nm)Constructor with default type.
this(nm, null);
|
Methods Summary |
---|
public static java.util.Enumeration | all()Access to all terminals.
return _all.elements();
| public static com.sun.java_cup.internal.terminal | find(java.lang.String with_name)Lookup a terminal by name string.
if (with_name == null)
return null;
else
return (terminal)_all.get(with_name);
| public static com.sun.java_cup.internal.terminal | find(int indx)Lookup a terminal by index.
Integer the_indx = new Integer(indx);
return (terminal)_all_by_index.get(the_indx);
| public boolean | is_non_term()Report this symbol as not being a non-terminal.
/*-----------------------------------------------------------*/
/*--- General Methods ---------------------------------------*/
/*-----------------------------------------------------------*/
return false;
| public static int | number()Total number of terminals.return _all.size();
| public int | precedence_num()get the precedence of a terminal
return _precedence_num;
| public int | precedence_side()
return _precedence_side;
| public void | set_precedence(int p, int new_prec)set the precedence of a terminal
_precedence_side = p;
_precedence_num = new_prec;
| public java.lang.String | toString()Convert to a string.
return super.toString() + "[" + index() + "]";
|
|