📄 ckeywords.java
字号:
package syntax;
public class CKeyWords {
public static final int SY_BASE = 0;
//define the type of tokens,include the keywords and some special symbols.
public static final int SY_BOOL_NOT = 0 + SY_BASE;
public static final int SY_NE = 1 + SY_BASE;
public static final int SY_REMAINDER = 2 + SY_BASE;
public static final int SY_REMAINDERASS = 3 + SY_BASE;
public static final int SY_AND = 4 + SY_BASE;
public static final int SY_BOOL_AND = 5 + SY_BASE;
public static final int SY_LB2 = 6 + SY_BASE;
public static final int SY_RB2 = 7 + SY_BASE;
public static final int SY_TIMES = 8 + SY_BASE;
public static final int SY_TIMEASS = 9 + SY_BASE;
public static final int SY_PLUS = 10 + SY_BASE;
public static final int SY_PLUSPLUS = 11 + SY_BASE;
public static final int SY_PLUSASS = 12 + SY_BASE;
public static final int SY_COMMA = 13 + SY_BASE;
public static final int SY_MINUS = 14 + SY_BASE;
public static final int SY_MINUSMINUS = 15 + SY_BASE;
public static final int SY_MINUSASS = 16 + SY_BASE;
public static final int SY_POINT = 17 + SY_BASE;
public static final int SY_DIV = 18 + SY_BASE;
public static final int SY_DIVASS = 19 + SY_BASE;
public static final int SY_COLON = 20 + SY_BASE;
public static final int SY_SEMICOLON = 21 + SY_BASE;
public static final int SY_L = 22 + SY_BASE;
public static final int SY_LSHIFT = 23 + SY_BASE;
public static final int SY_LSHIFTASS = 24 + SY_BASE;
public static final int SY_LE = 25 + SY_BASE;
public static final int SY_ASS = 26 + SY_BASE;
public static final int SY_EQ = 27 + SY_BASE;
public static final int SY_G = 28 + SY_BASE;
public static final int SY_GE = 29 + SY_BASE;
public static final int SY_RSHIFT = 30 + SY_BASE;
public static final int SY_RSHIFTASS = 31 + SY_BASE;
public static final int SY_RRSHIFT = 32 + SY_BASE;
public static final int SY_RRSHIFTASS = 33 + SY_BASE;
public static final int SY_QUESTION = 34 + SY_BASE;
public static final int SY_LB3 = 35 + SY_BASE;
public static final int SY_RB3 = 36 + SY_BASE;
public static final int SY_XOR = 37 + SY_BASE;
public static final int SY_XORASS = 38 + SY_BASE;
public static final int SY_ABSTRACT = 39 + SY_BASE;
public static final int SY_BOOLEAN = 40 + SY_BASE;
public static final int SY_BREAK = 41 + SY_BASE;
public static final int SY_BYTE = 42 + SY_BASE;
public static final int SY_CASE = 43 + SY_BASE;
public static final int SY_CATCH = 44 + SY_BASE;
public static final int SY_CHAR = 45 + SY_BASE;
public static final int SY_CLASS = 46 + SY_BASE;
public static final int SY_CONST = 47 + SY_BASE;
public static final int SY_CONTINUE = 48 + SY_BASE;
public static final int SY_DEFAULT = 49 + SY_BASE;
public static final int SY_DO = 50 + SY_BASE;
public static final int SY_DOUBLE = 51 + SY_BASE;
public static final int SY_ELSE = 52 + SY_BASE;
public static final int SY_EXTENDS = 53 + SY_BASE;
public static final int SY_FINAL = 54 + SY_BASE;
public static final int SY_FINALLY = 55 + SY_BASE;
public static final int SY_FLOAT = 56 + SY_BASE;
public static final int SY_FOR = 57 + SY_BASE;
public static final int SY_GOTO = 58 + SY_BASE;
public static final int SY_IF = 59 + SY_BASE;
public static final int SY_IMPLEMENTS = 60 + SY_BASE;
public static final int SY_IMPORT = 61 + SY_BASE;
public static final int SY_INSTANCEOF = 62 + SY_BASE;
public static final int SY_INT = 63 + SY_BASE;
public static final int SY_INTERFACE = 64 + SY_BASE;
public static final int SY_LONG = 65 + SY_BASE;
public static final int SY_NATIVE = 66 + SY_BASE;
public static final int SY_NEW = 67 + SY_BASE;
public static final int SY_PACKAGE = 68 + SY_BASE;
public static final int SY_PRIVATE = 69 + SY_BASE;
public static final int SY_PROTECTED = 70 + SY_BASE;
public static final int SY_PUBLIC = 71 + SY_BASE;
public static final int SY_RETURN = 72 + SY_BASE;
public static final int SY_SHORT = 73 + SY_BASE;
public static final int SY_STATIC = 74 + SY_BASE;
public static final int SY_STRICTFP = 75 + SY_BASE;
public static final int SY_SUPER = 76 + SY_BASE;
public static final int SY_SWITCH = 77 + SY_BASE;
public static final int SY_SYNCHRONIZED = 78 + SY_BASE;
public static final int SY_THIS = 79 + SY_BASE;
public static final int SY_THROW = 80 + SY_BASE;
public static final int SY_THROWS = 81 + SY_BASE;
public static final int SY_TRANSIENT = 82 + SY_BASE;
public static final int SY_TRY = 83 + SY_BASE;
public static final int SY_VOID = 84 + SY_BASE;
public static final int SY_VOLATILE = 85 + SY_BASE;
public static final int SY_WHILE = 86 + SY_BASE;
public static final int SY_LB1 = 87 + SY_BASE;
public static final int SY_OR = 88 + SY_BASE;
public static final int SY_BOOL_OR = 89 + SY_BASE;
public static final int SY_RB1 = 90 + SY_BASE;
public static final int SY_NOT = 91 + SY_BASE;
public static final int EOF = 92 + SY_BASE;
public static final int SY_NUMBERLITERAL = 100 + SY_BASE;
public static final int SY_STRINGLITERAL = 101 + SY_BASE;
public static final int SY_CHARLITERAL = 102 + SY_BASE;
public static final int SY_IDENTIFIER = 103 + SY_BASE;
//the table used to look up the keywords, and some symbols.
private static final String Keys[] = {
"!", // 0
"!=", // 1
"%", // 2
"%=", // 3
"&", // 4
"&&", // 5
"(", // 6
")", // 7
"*", // 8
"*=", // 9
"+", // 10
"++", // 11
"+=", // 12
",", // 13
"-", // 14
"--", // 15
"-=", // 16
".", // 17
"/", // 18
"/=", // 19
":", // 20
";", // 21
"<", // 22
"<<", // 23
"<<=", // 24
"<=", // 25
"=", // 26
"==", // 27
">", // 28
">=", // 29
">>", // 30
">>=", // 31
">>>", // 32
">>>=", // 33
"?", // 34
"[", // 35
"]", // 36
"^", // 37
"^=", // 38
"abstract", // 39
"boolean", // 40
"break", // 41
"byte", // 42
"case", // 43
"catch", // 44
"char", // 45
"class", // 46
"const", // 47
"continue", // 48
"default", // 49
"do", // 50
"double", // 51
"else", // 52
"extends", // 53
"final", // 54
"finally", // 55
"float", // 56
"for", // 57
"goto", // 58
"if", // 59
"implements", // 60
"import", // 61
"instanceof", // 62
"int", // 63
"interface", // 64
"long", // 65
"native", // 66
"new", // 67
"package", // 68
"private", // 69
"protected", // 70
"public", // 71
"return", // 72
"short", // 73
"static", // 74
"strictfp", // 75
"super", // 76
"switch", // 77
"synchronized", // 78
"this", // 79
"throw", // 80
"throws", // 81
"transient", // 82
"try", // 83
"void", // 84
"volatile", // 85
"while", // 86
"{", // 87
"|", // 88
"||", // 89
"}", // 90
"~", // 91
"$" // 92
};
//use the index sy to return the relative token type,
public static String getText (int sy) {
if (sy >= 0 && sy <=EOF)
return Keys[sy];
switch (sy) {
case SY_NUMBERLITERAL: return "number";
case SY_STRINGLITERAL: return "string";
case SY_CHARLITERAL: return "char";
case SY_IDENTIFIER: return "id";
default: return "?????";
}
}
//use the binary search to find the index of token,
public static int search (String name ) {
int u = 0, o = Keys.length - 1;
while (u <= o) {
int m = (u + o) / 2;
if (name.compareTo (Keys[m]) < 0)
o = m - 1;
else if (name.compareTo (Keys[m]) > 0)
u = m + 1;
else
return m;
}
return -1;
}
private static void selftest () {
for (int i = 0; i < Keys.length; i++)
if (search (Keys[i]) < 0)
System.err.println ("Error: name " + Keys[i] + " not found");
}
public static void main (String args[]) {
selftest ();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -