⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tokens.java

📁 java语言开发的基于tiny语言的编译器
💻 JAVA
字号:


package jeex.tiny;
/**
 * Tokens list all tokens used by parser.
 */
interface Tokens {
	//key words
	int IF 		= 0;
	int THEN 	= 1;
	int ELSE		= 2;
	int END 		= 3;
	int REPEAT 	= 4;
	int UNTIL 	= 5;
	int READ 	= 6;
	int WRITE 	= 7;
	//operator
	int LT 		= 10;
	int EQ 		= 11;
	int PLUS 	= 12;
	int MINUS 	= 13;
	int MUL 		= 14;
	int DIV 		= 15;
	int ASSIGN 	= 16;
	int LPAREN	= 17;
	int RPAREN	= 18;
	int SEMI		= 19;
	int DOT		= 20;	
	//an identifier
	int IDENT 	= 30;
	//a number
	int NUMBER 	= 31;
	
	int ERROR	= 40;
	int EOF		= 41;

}
/**
 * Utility class for token related helper function
 */
class TokenUtil implements Tokens {
   /** 
    * Convert token to readable string
    * @param token - token to be converted
    */
	static String tokenToString(int token) {
		switch (token) {
			case IF: return "if";
			case THEN: return "then";
			case ELSE: return "else";
			case END: return "end";
			case REPEAT: return "repeat";
			case UNTIL: return "until";
			case READ: return "read";
			case WRITE: return "write";
			
			case LT: return "<";
			case EQ: return "=";
			case PLUS: return "+";
			case MINUS: return "-";
			case MUL: return "*";
			case DIV: return "/";
			case ASSIGN: return ":=";
			case LPAREN:	return "(";
			case RPAREN:	return ")";
			case SEMI: return ";";
			case DOT: return ".";
			
			case IDENT: return "IDENT";
			case NUMBER: return "NUMBER";
			
			case EOF: return "EOF";
			case ERROR: return "ERROR";
		}
		return "Unkown Token";
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -