001: package ro.infoiasi.donald.compiler.parser;
002:
003: import ro.infoiasi.donald.compiler.cfg.*;
004:
005: public class Token {
006: public static final int UNKNOWN_LINE = -1;
007: public static final int UNKNOWN_COLUMN = -1;
008: public static final int UNKNOWN_NCHAR = -1;
009: public static final int UNKNOWN_LENGTH = -1;
010:
011: public Token(Terminal a, int line, int column, int nchar,
012: int length, Object value) {
013: this .a = a;
014: this .line = line;
015: this .column = column;
016: this .nchar = nchar;
017: this .length = length;
018: this .value = value;
019: }
020:
021: public Token(Terminal a, int line, int column, int nchar, int length) {
022: this (a, line, column, nchar, length, null);
023: }
024:
025: public Token(Terminal a, int line, int column) {
026: this (a, line, column, UNKNOWN_NCHAR, UNKNOWN_LENGTH);
027: }
028:
029: public Token(Terminal a) {
030: this (a, UNKNOWN_LINE, UNKNOWN_COLUMN, UNKNOWN_NCHAR,
031: UNKNOWN_LENGTH);
032: }
033:
034: public Terminal getSymbol() {
035: return a;
036: }
037:
038: public int getLine() {
039: return line;
040: }
041:
042: public int getColumn() {
043: return column;
044: }
045:
046: public int getCharNumber() {
047: return nchar;
048: }
049:
050: public int getLength() {
051: return length;
052: }
053:
054: public Object getValue() {
055: return value;
056: }
057:
058: public void setSymbol(Terminal a) {
059: this .a = a;
060: }
061:
062: public void setLine(int line) {
063: this .line = line;
064: }
065:
066: public void setColumn(int column) {
067: this .column = column;
068: }
069:
070: public void setCharNumber(int nchar) {
071: this .nchar = nchar;
072: }
073:
074: public void setLength(int length) {
075: this .length = length;
076: }
077:
078: public void setValue(Object value) {
079: this .value = value;
080: }
081:
082: public String toString() {
083: StringBuffer sb = new StringBuffer(a.toString());
084: if (line != UNKNOWN_LINE) {
085: sb.append("[line=" + line + "]");
086: }
087: if (column != UNKNOWN_COLUMN) {
088: sb.append("[column=" + column + "]");
089: }
090: if (nchar != UNKNOWN_NCHAR) {
091: sb.append("[nchar=" + nchar + "]");
092: }
093: if (length != UNKNOWN_LENGTH) {
094: sb.append("[length=" + length + "]");
095: }
096: if (value != null) {
097: sb.append("[value=" + value + "]");
098: }
099: return sb.toString();
100: }
101:
102: private Terminal a;
103: private int line, column, nchar, length;
104: private Object value;
105: }
|