Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: java_cup/symbol_part.java


1   package java_cup;
2   
3   /** This class represents a part of a production which is a symbol (terminal
4    *  or non terminal).  This simply maintains a reference to the symbol in 
5    *  question.
6    *
7    * @see     java_cup.production
8    * @version last updated: 11/25/95
9    * @author  Scott Hudson
10   */
11  public class symbol_part extends production_part {
12  
13    /*-----------------------------------------------------------*/
14    /*--- Constructor(s) ----------------------------------------*/
15    /*-----------------------------------------------------------*/
16  
17    /** Full constructor. 
18     * @param sym the symbol that this part is made up of.
19     * @param lab an optional label string for the part.
20     */
21    public symbol_part(symbol sym, String lab) throws internal_error
22      {
23        super(lab);
24  
25        if (sym == null)
26    throw new internal_error(
27      "Attempt to construct a symbol_part with a null symbol");
28        _the_symbol = sym;
29      }
30  
31    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
32  
33    /** Constructor with no label. 
34     * @param sym the symbol that this part is made up of.
35     */
36    public symbol_part(symbol sym) throws internal_error
37      {
38        this(sym,null);
39      }
40  
41    /*-----------------------------------------------------------*/
42    /*--- (Access to) Instance Variables ------------------------*/
43    /*-----------------------------------------------------------*/
44  
45    /** The symbol that this part is made up of. */
46    protected symbol _the_symbol;
47  
48    /** The symbol that this part is made up of. */
49    public symbol the_symbol() {return _the_symbol;}
50  
51    /*-----------------------------------------------------------*/
52    /*--- General Methods ---------------------------------------*/
53    /*-----------------------------------------------------------*/
54  
55    /** Respond that we are not an action part. */
56    public boolean is_action() { return false; }
57  
58    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
59  
60    /** Equality comparison. */
61    public boolean equals(symbol_part other)
62      {
63        return other != null && super.equals(other) && 
64         the_symbol().equals(other.the_symbol());
65      }
66  
67    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
68  
69    /** Generic equality comparison. */
70    public boolean equals(Object other)
71      {
72        if (!(other instanceof symbol_part))
73    return false;
74        else
75    return equals((symbol_part)other);
76      }
77  
78    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
79  
80    /** Produce a hash code. */
81    public int hashCode()
82      {
83        return super.hashCode() ^ 
84         (the_symbol()==null ? 0 : the_symbol().hashCode());
85      }
86  
87    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
88  
89    /** Convert to a string. */
90    public String toString()
91      {
92        if (the_symbol() != null)
93    return super.toString() + the_symbol();
94        else
95    return super.toString() + "$$MISSING-SYMBOL$$";
96      }
97  
98    /*-----------------------------------------------------------*/
99  
100 }