Home | History | Annotate | Download | only in java_cup
      1 
      2 package java_cup;
      3 
      4 /** This class represents a reduce action within the parse table.
      5  *  The action simply stores the production that it reduces with and
      6  *  responds to queries about its type.
      7  *
      8  * @version last updated: 11/25/95
      9  * @author  Scott Hudson
     10  */
     11 public class reduce_action extends parse_action {
     12 
     13   /*-----------------------------------------------------------*/
     14   /*--- Constructor(s) ----------------------------------------*/
     15   /*-----------------------------------------------------------*/
     16 
     17   /** Simple constructor.
     18    * @param prod the production this action reduces with.
     19    */
     20   public reduce_action(production prod ) throws internal_error
     21     {
     22       /* sanity check */
     23       if (prod == null)
     24     throw new internal_error(
     25       "Attempt to create a reduce_action with a null production");
     26 
     27       _reduce_with = prod;
     28     }
     29 
     30   /*-----------------------------------------------------------*/
     31   /*--- (Access to) Instance Variables ------------------------*/
     32   /*-----------------------------------------------------------*/
     33 
     34   /** The production we reduce with. */
     35   protected production _reduce_with;
     36 
     37   /** The production we reduce with. */
     38   public production reduce_with() {return _reduce_with;}
     39 
     40   /*-----------------------------------------------------------*/
     41   /*--- General Methods ---------------------------------------*/
     42   /*-----------------------------------------------------------*/
     43 
     44   /** Quick access to type of action. */
     45   public int kind() {return REDUCE;}
     46 
     47   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
     48 
     49   /** Equality test. */
     50   public boolean equals(reduce_action other)
     51     {
     52       return other != null && other.reduce_with() == reduce_with();
     53     }
     54 
     55   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
     56 
     57   /** Generic equality test. */
     58   public boolean equals(Object other)
     59     {
     60       if (other instanceof reduce_action)
     61     return equals((reduce_action)other);
     62       else
     63        return false;
     64     }
     65 
     66   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
     67 
     68   /** Compute a hash code. */
     69   public int hashCode()
     70     {
     71       /* use the hash code of the production we are reducing with */
     72       return reduce_with().hashCode();
     73     }
     74 
     75 
     76   /** Convert to string. */
     77   public String toString()
     78     {
     79       return "REDUCE(" + reduce_with().index() + ")";
     80     }
     81 
     82   /*-----------------------------------------------------------*/
     83 
     84 };
     85