1 package polyglot.lex; 2 3 import polyglot.util.Position; 4 5 6 public abstract class Token { 7 Position position; 8 int symbol; 9 10 public Token(Position position, int symbol) 11 { 12 this.position = position; 13 this.symbol = symbol; 14 } 15 16 public Position getPosition() 17 { 18 return position; 19 } 20 21 public java_cup.runtime.Symbol symbol() { 22 return new java_cup.runtime.Symbol(symbol, this); 23 } 24 25 protected static String escape(String s) { 26 StringBuffer sb = new StringBuffer (); 27 for (int i=0; i<s.length(); i++) 28 switch(s.charAt(i)) { 29 case '\t': sb.append("\\t"); break; 30 case '\f': sb.append("\\f"); break; 31 case '\n': sb.append("\\n"); break; 32 default: 33 if ((int)s.charAt(i)<0x20 || 34 ((int)s.charAt(i) > 0x7e && (int)s.charAt(i) < 0xFF)) 35 sb.append("\\"+Integer.toOctalString((int)s.charAt(i))); 36 else 37 sb.append(s.charAt(i)); 38 } 39 return sb.toString(); 40 } 41 } 42 | Popular Tags |