/* SCCS - @(#)YYtoken.java 1.2 - 02/28/99 - 12:39:31 */ /* * Copyright (c) 1996 Dennis Heimbigner. email dennis@cs.colorado.edu */ package pp.src.jbf; import java.lang.*; public class YYtoken extends YYnode { // static public NslPreProcessor pp; public int lineno; // 0 based line # public int charno; // 0 based char within line public int charno0; // 0 based char public String text; // of the token public YYtoken(int ttype, String txt, int lno, int chno, int chno0) { super(ttype); text = txt; lineno = lno; charno = chno; charno0 = chno0; //System.out.println("L"+lno+" C"+chno+" T"+ttype+"\t:"+txt); } public YYtoken(int ttype, StringBuffer txt, int lno, int chno, int cno0) { this(ttype,txt.toString(),lno,chno,cno0); } public YYtoken(int ttype, YYlexbuffer txt) { this(ttype,txt.lexeme(),txt.yyline(),txt.yychar(),txt.yychar0()); } public boolean istoken() { return true;} public YYtoken(int kind, String txt) {this(kind,txt,(int)0,(int)0,(int)0);} public YYtoken(int kind) { this(kind,"",(int)0,(int)0,(int)0);} public void settype(int k, String s) {settokentype(k); settext(s);} public void settype(int k, StringBuffer s) {settokentype(k); settext(s);} public void settext(String v) {text = v;} public void settext(StringBuffer v) {text = v.toString();} public void setlineno(int lno) {lineno = lno;} public void setcharno(int chno) {charno = chno;} public void setcharno0(int chno0) {charno0 = chno0;} public void setendpos(int lno, int cno, int cno0) { setlineno(lno); setcharno(cno); setcharno0(cno0); // ok, now modify by the length of the text int l = text.length(); if(lineno < 0) lineno = 0; charno0 = charno0 - l + 1; charno = charno - l + 1; } public String text() {return text;} public int lineno() {return lineno;} public int charno() {return charno;} public int charno0() {return charno0;} public String toString() {return text();} /* Add converters for all the various types */ public boolean boolean_value() {Boolean l = Boolean.valueOf(text); return l.booleanValue();} public char char_value() {return text.charAt(0);} public long long_value() {Long l = Long.valueOf(text); return l.longValue();} public double double_value() {Double l = Double.valueOf(text); return l.doubleValue();} public String string_value() {return text;} // also covers Identifier public void setvalue(boolean v) {text = v?"true":"false";} public void setvalue(char v) {text = String.valueOf(v);} public void setvalue(long v) {text = Long.toString(v);} public void setvalue(double v) {text = Double.toString(v);} public void setvalue(String v) {text = v;} // Add some quoted string processing public void stripquotes() { StringBuffer b = new StringBuffer(text); int l1 = b.length()-1; if(l1 > 0) {for(int i=1;i= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));} public boolean isoctaldigit(char c) {return (c >= '0' && c <= '7');} public int hex2int(char c) {return (c >= '0' && c <= '9')?c - '0': ((c >= 'a' && c <= 'f')?c - 'a':c-'A');} public int octal2int(char c) {return c - '0';} };