package cmmCompiler;

public class Token {
	int type;
	String text;
	int lineNo;
	int column;
	long filePosition;

	boolean verbose = true;
	public Token(	int type,	String text, int lineNo,int column,long filePosition)
	{
		this. type = type;
		this. text = text;
		this. lineNo = lineNo;
		this. column = column;
		this. filePosition = filePosition;

	}
	public String toString(){
		if (!verbose) return text;
		return "<"+tokenName(type)+" line:"+lineNo+" col:"+column+" type="+type+"> "+text+" </"+tokenName(type)+">";
	}
	//USED KEYWORDS
	//String[] usedKeyWords = {"else",  "if",  "int",  "return",  "void",  "while"}
	//ALL RESERVED WORDS
	static String[] reservedWords = {
		"boolean",  "break",  "byte",  "case",  "catch",  "char",  "class",  "const",  "continue",
		"default",  "do",  "double",  "else",  "enum",  "final",  "finally",  "float",  "for",  "goto",
		"if",  "int",  "long",  "new",  "private",  "protected",  "public",  "return",
		"short",  "switch",  "this",  "throw",  "throws",  "try",  "void",  "while"
	};

	static String[] seperators = {
		"(", ")", "{", "}", "[", "]", ";", ",", "."
	};
	static String[] operators = {
		"=", ">", "<", "!", "~", "?", ":", "==", "<=", ">=", "!=",
		"&&", "||", "++", "--",
		"+", "-", "*", "/", "&", "|", "^", "%", "<<", ">>", ">>>",
		"+=", "-=", "*=", "/=", "&=", "|=", "^=", "%=",
		"<<=", ">>=", ">>>="
	};


	static String[] tokenSymbol = {
			"EOF",
			"Number",
			"ID",
			"(", ")", "{", "}", "[", "]", ";", ",", ".",

			"boolean",  "break",  "byte",  "case",  "catch",  "char",  "class",  "const",  "continue",
			"default",  "do",  "double",  "else",  "enum",  "final",  "finally",  "float",  "for",  "goto",
			"if",  "int",  "long",  "new",  "private",  "protected",  "public",  "return",
			"short",  "switch",  "this",  "throw",  "throws",  "try",  "void",  "while",

			"=", ">", "<", "!", "~", "?", ":", "==", "<=", ">=", "!=",
			"&&", "||", "++", "--",
			"+", "-", "*", "/", "&", "|", "^", "%", "<<", ">>", ">>>",
			"+=", "-=", "*=", "/=", "&=", "|=", "^=", "%=",
			"<<=", ">>=", ">>>="
	};


	public static String tokenName(int type)
	{
		if (type > tokenSymbol.length) return "unknown";
		return tokenNames[type];
	}
	static String[] tokenNames = {
		"EOF",                            //   = 	0; 	// $
		"NUMBER",                         //   = 	1; 	// Number
		"ID",                             //   = 	2; 	// ID
		"OPEN_PAREN",                     //   = 	3; 	// (
		"CLOSE_PAREN",                    //   = 	4; 	// )
		"OPEN_CURLY",                     //   = 	5; 	// {
		"CLOSE_CURLY",                    //   = 	6; 	// }
		"OPEN_BRACKET",                   //   = 	7; 	// [
		"CLOSE_BRACKET",                  //   = 	8; 	// ]
		"SEMI",                           //   = 	9; 	// ;
		"COMMA",                          //   = 	10; 	// ,
		"DOT",                            //   = 	11; 	// .
		"BOOLEAN",                        //   = 	12; 	// boolean
		"BREAK",                          //   = 	13; 	// break
		"BYTE",                           //   = 	14; 	// byte
		"CASE",                           //   = 	15; 	// case
		"CATCH",                          //   = 	16; 	// catch
		"CHAR",                           //   = 	17; 	// char
		"CLASS",                          //   = 	18; 	// class
		"CONST",                          //   = 	19; 	// const
		"CONTINUE",                       //   = 	20; 	// continue
		"DEFAULT",                        //   = 	21; 	// default
		"DO",                             //   = 	22; 	// do
		"DOUBLE",                         //   = 	23; 	// double
		"ELSE",                           //   = 	24; 	// else
		"ENUM",                           //   = 	25; 	// enum
		"FINAL",                          //   = 	26; 	// final
		"FINALLY",                        //   = 	27; 	// finally
		"FLOAT",                          //   = 	28; 	// float
		"FOR",                            //   = 	29; 	// for
		"GOTO",                           //   = 	30; 	// goto
		"IF",                             //   = 	31; 	// if
		"INT",                            //   = 	32; 	// int
		"LONG",                           //   = 	33; 	// long
		"NEW",                            //   = 	34; 	// new
		"PRIVATE",                        //   = 	35; 	// private
		"PROTECTED",                      //   = 	36; 	// protected
		"PUBLIC",                         //   = 	37; 	// public
		"RETURN",                         //   = 	38; 	// return
		"SHORT",                          //   = 	39; 	// short
		"SWITCH",                         //   = 	40; 	// switch
		"THIS",                           //   = 	41; 	// this
		"THROW",                          //   = 	42; 	// throw
		"THROWS",                         //   = 	43; 	// throws
		"TRY",                            //   = 	44; 	// try
		"VOID",                           //   = 	45; 	// void
		"WHILE",                          //   = 	46; 	// while
		"ASSIGN",                         //   = 	47; 	// =
		"OP_GT",                          //   = 	48; 	// >
		"OP_LT",                          //   = 	49; 	// <
		"OP_NOT",                         //   = 	50; 	// !
		"OP_BITCOMP",                     //   = 	51; 	// ~
		"OP_IIF",                         //   = 	52; 	// ?
		"OP_COLON",                       //   = 	53; 	// :
		"OP_EQ",                          //   = 	54; 	// ==
		"OP_LE",                          //   = 	55; 	// <=
		"OP_GE",                          //   = 	56; 	// >=
		"OP_NE",                          //   = 	57; 	// !=
		"OP_AND",                         //   = 	58; 	// &&
		"OP_OR",                          //   = 	59; 	// ||
		"OP_INC",                         //   = 	60; 	// ++
		"OP_DEC",                         //   = 	61; 	// --
		"OP_PLUS",                        //   = 	62; 	// +
		"OP_MINUS",                       //   = 	63; 	// -
		"OP_MUL",                         //   = 	64; 	// *
		"OP_DIV",                         //   = 	65; 	// /
		"OP_BITAND",                      //   = 	66; 	// &
		"OP_BITOR",                       //   = 	67; 	// |
		"OP_BITXOR",                      //   = 	68; 	// ^
		"OP_REM",                         //   = 	69; 	// %
		"OP_RSHIFT",                      //   = 	70; 	// <<
		"OP_LSHIFT",                      //   = 	71; 	// >>
		"OP_ROTLEFT",                     //   = 	72; 	// >>>
		"OP_PLUSEQ",                      //   = 	73; 	// +=
		"OP_MINUSEQ",                     //   = 	74; 	// -=
		"OP_MULEQ",                       //   = 	75; 	// *=
		"OP_DIVEQ",                       //   = 	76; 	// /=
		"OP_BITANDEQ",                    //   = 	77; 	// &=
		"OP_BITOREQ",                     //   = 	78; 	// |=
		"OP_BITXOREQ",                    //   = 	79; 	// ^=
		"OP_MODEQ",                       //   = 	80; 	// %=
		"OP_RSHIFTEQ",                    //   = 	81; 	// <<=
		"OP_LSHIFTEQ",                    //   = 	82; 	// >>=
		"OP_ROTLEQ",                      //   = 	83; 	// >>>=
	};	

//CODE THAT GENERATED TOKEN CONSTANTS FROM THE NAMES ARRAY ABOVE
//THIS MAKES IT EASIER TO UPDATE IF WE ADD TO IT	
//	static public void main(String[] args){
//	  dump();
//}
//	static void dump()
//	{
//		//generates Token Constants
//		for (int i = 0; i < tokenNames.length; i++)
//		{
//			String s = tokenNames[i];
//			System.out.println(
//				"public static final int "+
//				(s.toUpperCase()+"                ").substring(0,10)+ " = \t" + i +
//				"; \t// " + tokenSymbol[i]
//			);
//		}
//	}

	public static final int EOF      	= 	0; 	// $
	public static final int NUMBER   	= 	1; 	// Number
	public static final int ID       	= 	2; 	// ID
	public static final int OPEN_PAREN  = 	3; 	// (
	public static final int CLOSE_PAREN = 	4; 	// )
	public static final int OPEN_CURLY  = 	5; 	// {
	public static final int CLOSE_CURLY = 	6; 	// }
	public static final int OPEN_BRACKET = 	7; 	// [
	public static final int CLOSE_BRACKET = 8; 	// ]
	public static final int SEMI     	= 	9; 	// ;
	public static final int COMMA    	= 	10; 	// ,
	public static final int DOT      	= 	11; 	// .
	public static final int BOOLEAN  	= 	12; 	// boolean
	public static final int BREAK    	= 	13; 	// break
	public static final int BYTE     	= 	14; 	// byte
	public static final int CASE     	= 	15; 	// case
	public static final int CATCH    	= 	16; 	// catch
	public static final int CHAR     	= 	17; 	// char
	public static final int CLASS    	= 	18; 	// class
	public static final int CONST    	= 	19; 	// const
	public static final int CONTINUE 	= 	20; 	// continue
	public static final int DEFAULT  	= 	21; 	// default
	public static final int DO       	= 	22; 	// do
	public static final int DOUBLE   	= 	23; 	// double
	public static final int ELSE     	= 	24; 	// else
	public static final int ENUM     	= 	25; 	// enum
	public static final int FINAL    	= 	26; 	// final
	public static final int FINALLY  	= 	27; 	// finally
	public static final int FLOAT    	= 	28; 	// float
	public static final int FOR      	= 	29; 	// for
	public static final int GOTO     	= 	30; 	// goto
	public static final int IF       	= 	31; 	// if
	public static final int INT      	= 	32; 	// int
	public static final int LONG     	= 	33; 	// long
	public static final int NEW      	= 	34; 	// new
	public static final int PRIVATE  	= 	35; 	// private
	public static final int PROTECTED	= 	36; 	// protected
	public static final int PUBLIC   	= 	37; 	// public
	public static final int RETURN   	= 	38; 	// return
	public static final int SHORT    	= 	39; 	// short
	public static final int SWITCH   	= 	40; 	// switch
	public static final int THIS     	= 	41; 	// this
	public static final int THROW    	= 	42; 	// throw
	public static final int THROWS   	= 	43; 	// throws
	public static final int TRY      	= 	44; 	// try
	public static final int VOID     	= 	45; 	// void
	public static final int WHILE    	= 	46; 	// while
	public static final int ASSIGN   	= 	47; 	// =
	public static final int OP_GT      	= 	48; 	// >
	public static final int OP_LT       = 	49; 	// <
	public static final int OP_NOT     	= 	50; 	// !
	public static final int OP_BITCOMP  = 	51; 	// ~
	public static final int OP_IIF    	= 	52; 	// ?
	public static final int OP_COLON    = 	53; 	// :
	public static final int OP_EQ    	= 	54; 	// ==
	public static final int OP_LE       = 	55; 	// <=
	public static final int OP_GE       = 	56; 	// >=
	public static final int OP_NE       = 	57; 	// !=
	public static final int OP_AND      = 	58; 	// &&
	public static final int OP_OR       = 	59; 	// ||
	public static final int OP_INC      = 	60; 	// ++
	public static final int OP_DEC      = 	61; 	// --
	public static final int OP_PLUS     = 	62; 	// +
	public static final int OP_MINUS    = 	63; 	// -
	public static final int OP_MUL     	= 	64; 	// *
	public static final int OP_DIV      = 	65; 	// /
	public static final int OP_BITAND   = 	66; 	// &
	public static final int OP_BITOR    = 	67; 	// |
	public static final int OP_BITXOR   = 	68; 	// ^
	public static final int OP_REM      = 	69; 	// %
	public static final int OP_RSHIFT   = 	70; 	// <<
	public static final int OP_LSHIFT   = 	71; 	// >>
	public static final int OP_ROTLEFT  = 	72; 	// >>>
	public static final int OP_PLUSEQ   = 	73; 	// +=
	public static final int OP_MINUSEQ  = 	74; 	// -=
	public static final int OP_MULEQ   	= 	75; 	// *=
	public static final int OP_DIVEQ    = 	76; 	// /=
	public static final int OP_BITANDEQ = 	77; 	// &=
	public static final int OP_BITOREQ  = 	78; 	// |=
	public static final int OP_BITXOREQ = 	79; 	// ^=
	public static final int OP_MODEQ    = 	80; 	// %=
	public static final int OP_RSHIFTEQ = 	81; 	// <<=
	public static final int OP_LSHIFTEQ = 	82; 	// >>=
	public static final int OP_ROTLEQ   = 	83; 	// >>>=

}
