1 package com.sun.java_cup.internal; 2 3 import com.sun.java_cup.internal.assoc; 4 import java.util.Hashtable ; 5 import java.util.Enumeration ; 6 7 16 public class terminal extends symbol { 17 18 19 20 21 22 26 public terminal(String nm, String tp, int precedence_side, int precedence_num) 27 { 28 29 super(nm, tp); 30 31 32 Object conflict = _all.put(nm,this); 33 if (conflict != null) 34 (new internal_error("Duplicate terminal (" + nm + ") created")).crash(); 39 40 41 _index = next_index++; 42 43 44 _precedence_num = precedence_num; 45 _precedence_side = precedence_side; 46 47 48 _all_by_index.put(new Integer (_index), this); 49 } 50 51 52 53 55 56 public terminal(String nm, String tp) 57 { 58 this(nm, tp, assoc.no_prec, -1); 59 } 60 61 62 63 66 public terminal(String nm) 67 { 68 this(nm, null); 69 } 70 71 72 73 74 75 private int _precedence_num; 76 private int _precedence_side; 77 78 79 80 81 82 85 protected static Hashtable _all = new Hashtable (); 86 87 88 public static Enumeration all() {return _all.elements();} 89 90 91 public static terminal find(String with_name) 92 { 93 if (with_name == null) 94 return null; 95 else 96 return (terminal)_all.get(with_name); 97 } 98 99 100 101 102 103 protected static Hashtable _all_by_index = new Hashtable (); 104 105 106 public static terminal find(int indx) 107 { 108 Integer the_indx = new Integer (indx); 109 110 return (terminal)_all_by_index.get(the_indx); 111 } 112 113 114 115 116 public static int number() {return _all.size();} 117 118 119 120 121 protected static int next_index = 0; 122 123 124 125 126 public static final terminal EOF = new terminal("EOF"); 127 128 129 130 131 public static final terminal error = new terminal("error"); 132 133 134 135 136 137 138 public boolean is_non_term() 139 { 140 return false; 141 } 142 143 144 145 146 public String toString() 147 { 148 return super.toString() + "[" + index() + "]"; 149 } 150 151 152 153 154 public int precedence_num() { 155 return _precedence_num; 156 } 157 public int precedence_side() { 158 return _precedence_side; 159 } 160 161 162 public void set_precedence(int p, int new_prec) { 163 _precedence_side = p; 164 _precedence_num = new_prec; 165 } 166 167 168 169 } 170 | Popular Tags |