FileDocCategorySizeDatePackage
terminal.javaAPI DocJava SE 5 API5060Fri Aug 26 14:54:54 BST 2005com.sun.java_cup.internal

terminal

public 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).
version
last updated: 7/3/96
author
Frank Flannery

Fields Summary
private int
_precedence_num
private int
_precedence_side
protected static Hashtable
_all
Table of all terminals. Elements are stored using name strings as the key
protected static Hashtable
_all_by_index
Table of all terminals indexed by their index number.
protected static int
next_index
Static counter to assign unique index.
public static final terminal
EOF
Special terminal for end of input.
public static final terminal
error
special terminal used for error recovery
Constructors Summary
public terminal(String nm, String tp, int precedence_side, int precedence_num)
Full constructor.

param
nm the name of the terminal.
param
tp the type of the terminal.

      /* 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.

param
nm the name of the terminal.

      this(nm, null);
    
Methods Summary
public static java.util.Enumerationall()
Access to all terminals.


       
      return _all.elements();
public static com.sun.java_cup.internal.terminalfind(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.terminalfind(int indx)
Lookup a terminal by index.


        
      
    
      Integer the_indx = new Integer(indx);

      return (terminal)_all_by_index.get(the_indx);
    
public booleanis_non_term()
Report this symbol as not being a non-terminal.


  /*-----------------------------------------------------------*/
  /*--- General Methods ---------------------------------------*/
  /*-----------------------------------------------------------*/

           
     
    
      return false;
    
public static intnumber()
Total number of terminals.

return _all.size();
public intprecedence_num()
get the precedence of a terminal

    return _precedence_num;
  
public intprecedence_side()

    return _precedence_side;
  
public voidset_precedence(int p, int new_prec)
set the precedence of a terminal

    _precedence_side = p;
    _precedence_num = new_prec;
  
public java.lang.StringtoString()
Convert to a string.

      return super.toString() + "[" + index() + "]";