public class Symbol {
    /** Token kind number of the terminal being represented. */
    public int sym;

    /** Line number at which lexeme was found in input. */
    public int line;

    /** Attribute value associated with symbol, if any. */
    public Object value = null;

    /** Constructor for symbols without attribute values. 
	@param symbol token kind
	@param line line number
    */
    Symbol(int sym, int line) {
	this.sym = sym; this.line = line; 
    }

    /** Constructor for symbols with attribute values. 
	@param sym token kind 
	@param line line number
	@param value attribute value
    */
    Symbol(int sym, int line, Object value) {
	this.sym = sym; this.line = line; this.value = value;
    }

    public String toString() {
	String s = "" + line + ":\t" + toName(sym);
	if (sym == STRING)
	    s += "\t\"" + value + "\"";
	else if (value != null)
	    s += "\t" + value;
	return s;
    }

    /** Enumeration of token kinds.
     *	Order must match name[] array below.
     *	Clients of this class must *NOT* rely on the specific order or
     *     the numeric values of these codes!
     */
    private static int code = 0;     // Make Java do the numbering for us.

    public static final int 
	EOF = code++,
	ID = code++,
	// Literals
	INTEGER = code++,
	REAL = code++,
	STRING = code++,
	// Keywords
	AND = code++,
	ARRAY = code++,
	BEGIN = code++,
	BY = code++,
        DIV = code++,
	DO = code++,
        ELSE = code++,
	ELSIF = code++,
	END = code++,
	EXIT = code++,
	FOR = code++,
	IF = code++,
        IS = code++,
        LOOP = code++,
	MOD = code++,
	NOT = code++,
	OF  = code++, 
	OR  = code++,
	PROCEDURE = code++,
	PROGRAM = code++,
	READ = code++,
	RECORD = code++,
	RETURN = code++,
	THEN  = code++,
	TO = code++,
        TYPE = code++,
	VAR = code++,
	WHILE = code++,
	WRITE = code++,
	// Operators
	ASGN = code++,   // :=
	PLUS = code++,   // +
	MINUS = code++,  // -
	TIMES = code++,  // *
	SLASH = code++,  // /
	LT = code++,     // <
	LEQ = code++,    // <=
	GT = code++,     // >
	GEQ = code++,    // >=
	EQ = code++,     // =
	NEQ = code++,    // <>
	// Delimiters
	COLON = code++,  // :
	SEMI = code++,   // ;
	COMMA = code++,  // ,
	DOT = code++,    // .
	LPAREN = code++, // (
	RPAREN = code++, // )
	LSQBRA = code++, // [
	RSQBRA = code++, // ]
	LCUBRA = code++, // {
	RCUBRA = code++; // }
    public static String toName(int code) {
	return name[code];
    }
    private static final String name[] = {
	"EOF",
	"ID",
	// Literals
	"INTEGER",
	"REAL",
	"STRING",
	// Keywords
	"AND",
	"ARRAY",
	"BEGIN",
	"BY",
        "DIV",
	"DO",
        "ELSE",
	"ELSIF",
	"END",
	"EXIT",
	"FOR",
	"IF",
        "IS",
        "LOOP",
	"MOD",
	"NOT",
	"OF", 
	"OR",
	"PROCEDURE",
	"PROGRAM",
	"READ",
	"RECORD",
	"RETURN",
	"THEN",
	"TO",
        "TYPE",
	"VAR",
	"WHILE",
	"WRITE",
	// Operators
	"ASGN",   // :=
	"PLUS",   // +
	"MINUS",  // -
	"TIMES",  // *
	"SLASH",  // /
	"LT",     // <
	"LEQ",    // <=
	"GT",     // >
	"GEQ",    // >=
	"EQ",     // =
	"NEQ",    // <>
	// Delimiters
	"COLON",  // :
	"SEMI",   // ;
	"COMMA",  // ,
	"DOT",    // .
	"LPAREN", // (
	"RPAREN", // )
	"LSQBRA", // [
	"RSQBRA", // ]
	"LCUBRA", // {
	"RCUBRA" // }
    };
}

	
