1 8 9 package beaver; 10 11 14 public class Symbol 15 { 16 static private final int COLUMN_FIELD_BITS = 12; 17 static private final int COLUMN_FIELD_MASK = (1 << COLUMN_FIELD_BITS) - 1; 18 19 22 static public int makePosition(int line, int column) 23 { 24 return line << COLUMN_FIELD_BITS | column; 25 } 26 27 30 static public int getLine(int position) 31 { 32 return position >>> COLUMN_FIELD_BITS; 33 } 34 35 38 static public int getColumn(int position) 39 { 40 return position & COLUMN_FIELD_MASK; 41 } 42 43 46 public final Object value; 47 48 51 protected short id; 52 53 56 protected int start; 57 58 61 protected int end; 62 63 public Symbol(short id) 64 { 65 this.id = id; 66 this.value = null; 67 } 68 69 public Symbol(short id, Object value) 70 { 71 this.id = id; 72 this.value = value; 73 } 74 75 public Symbol(short id, int start, int end) 76 { 77 this.id = id; 78 this.value = null; 79 this.start = start; 80 this.end = end; 81 } 82 83 public Symbol(short id, int left, int right, Object value) 84 { 85 this.id = id; 86 this.value = value; 87 this.start = left; 88 this.end = right; 89 } 90 91 public Symbol(short id, int start_line, int start_column, int length) 92 { 93 this.id = id; 94 this.value = null; 95 this.start = makePosition(start_line, start_column); 96 this.end = makePosition(start_line, start_column + length - 1); 97 } 98 99 public Symbol(short id, int start_line, int start_column, int length, Object value) 100 { 101 this.id = id; 102 this.value = value; 103 this.start = makePosition(start_line, start_column); 104 this.end = makePosition(start_line, start_column + length - 1); 105 } 106 107 112 public Symbol(Object value) 113 { 114 this.value = value; 115 } 116 117 124 protected Symbol() 125 { 126 this.value = this; 127 } 128 129 139 public short getId() 140 { 141 return id; 142 } 143 144 149 public int getStart() 150 { 151 return start; 152 } 153 154 159 public int getEnd() 160 { 161 return end; 162 } 163 } 164 | Popular Tags |