Home | History | Annotate | Download | only in java_cup
      1 
      2 package java_cup;
      3 
      4 /** This class serves as the base class for entries in a parse action table.
      5  *  Full entries will either be SHIFT(state_num), REDUCE(production), or ERROR.
      6  *  Objects of this base class will default to ERROR, while the other two
      7  *  types will be  represented by subclasses.
      8  *
      9  * @see     java_cup.reduce_action
     10  * @see     java_cup.shift_action
     11  * @version last updated: 11/25/95
     12  * @author  Scott Hudson
     13  */
     14 
     15 public class parse_action {
     16 
     17   /*-----------------------------------------------------------*/
     18   /*--- Constructor(s) ----------------------------------------*/
     19   /*-----------------------------------------------------------*/
     20 
     21   /** Simple constructor. */
     22   public parse_action()
     23     {
     24       /* nothing to do in the base class */
     25     }
     26 
     27 
     28   /*-----------------------------------------------------------*/
     29   /*--- (Access to) Static (Class) Variables ------------------*/
     30   /*-----------------------------------------------------------*/
     31 
     32   /** Constant for action type -- error action. */
     33   public static final int ERROR = 0;
     34 
     35   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
     36 
     37   /** Constant for action type -- shift action. */
     38   public static final int SHIFT = 1;
     39 
     40   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
     41 
     42   /** Constants for action type -- reduce action. */
     43   public static final int REDUCE = 2;
     44 
     45   /*-----------------------------------------------------------*/
     46   /*--- General Methods ---------------------------------------*/
     47   /*-----------------------------------------------------------*/
     48 
     49   /** Quick access to the type -- base class defaults to error. */
     50   public int kind() {return ERROR;}
     51 
     52   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
     53 
     54   /** Equality test. */
     55   public boolean equals(parse_action other)
     56     {
     57       /* we match all error actions */
     58       return other != null && other.kind() == ERROR;
     59     }
     60 
     61   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
     62 
     63   /** Generic equality test. */
     64   public boolean equals(Object other)
     65     {
     66       if (other instanceof parse_action)
     67     return equals((parse_action)other);
     68       else
     69     return false;
     70     }
     71   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
     72 
     73   /** Compute a hash code. */
     74   public int hashCode()
     75     {
     76       /* all objects of this class hash together */
     77       return 0xCafe123;
     78     }
     79 
     80   /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
     81 
     82   /** Convert to string. */
     83   public String toString() {return "ERROR";}
     84 
     85   /*-----------------------------------------------------------*/
     86 };
     87 
     88