1 2 package java_cup; 3 4 /** This class represents a shift action within the parse table. 5 * The action simply stores the state that it shifts to and responds 6 * to queries about its type. 7 * 8 * @version last updated: 11/25/95 9 * @author Scott Hudson 10 */ 11 public class shift_action extends parse_action { 12 13 /*-----------------------------------------------------------*/ 14 /*--- Constructor(s) ----------------------------------------*/ 15 /*-----------------------------------------------------------*/ 16 17 /** Simple constructor. 18 * @param shft_to the state that this action shifts to. 19 */ 20 public shift_action(lalr_state shft_to) throws internal_error 21 { 22 /* sanity check */ 23 if (shft_to == null) 24 throw new internal_error( 25 "Attempt to create a shift_action to a null state"); 26 27 _shift_to = shft_to; 28 } 29 30 /*-----------------------------------------------------------*/ 31 /*--- (Access to) Instance Variables ------------------------*/ 32 /*-----------------------------------------------------------*/ 33 34 /** The state we shift to. */ 35 protected lalr_state _shift_to; 36 37 /** The state we shift to. */ 38 public lalr_state shift_to() {return _shift_to;} 39 40 /*-----------------------------------------------------------*/ 41 /*--- General Methods ---------------------------------------*/ 42 /*-----------------------------------------------------------*/ 43 44 /** Quick access to type of action. */ 45 public int kind() {return SHIFT;} 46 47 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ 48 49 /** Equality test. */ 50 public boolean equals(shift_action other) 51 { 52 return other != null && other.shift_to() == shift_to(); 53 } 54 55 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ 56 57 /** Generic equality test. */ 58 public boolean equals(Object other) 59 { 60 if (other instanceof shift_action) 61 return equals((shift_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 state we are shifting to */ 72 return shift_to().hashCode(); 73 } 74 75 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ 76 77 /** Convert to a string. */ 78 public String toString() {return "SHIFT(" + shift_to().index() + ")";} 79 80 /*-----------------------------------------------------------*/ 81 82 }; 83