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

📄 keyword.java

📁 一个C语言子集的编译器
💻 JAVA
字号:
package com.king4solomon.homework.compiler.core;

import javax.swing.text.Segment;

public class Keyword {
	public Keyword() {
	}

	public static boolean isKeyword1(Segment seg) {
		boolean isKey = false;
		for (int i = 0; !isKey && i < KEYWORDS1.length; i++)
			if (seg.count == KEYWORDS1[i].length()) {
				isKey = true;
				for (int j = 0; isKey && j < seg.count; j++)
					if (seg.array[seg.offset + j] != KEYWORDS1[i].charAt(j))
						isKey = false;

			}
		return isKey;
	}

	public static boolean isKeyword2(Segment seg) {
		boolean isKey = false;
		for (int i = 0; !isKey && i < KEYWORDS2.length; i++)
			if (seg.count == KEYWORDS2[i].length()) {
				isKey = true;
				for (int j = 0; isKey && j < seg.count; j++)
					if (seg.array[seg.offset + j] != KEYWORDS2[i].charAt(j))
						isKey = false;

			}
		return isKey;
	}

	public static final String[] KEYWORDS1 = { "break", "case", "const", "continue", "default",
			"do", "else", "for", "goto", "if", "return", "switch", "while", "main" };

	public static final String[] KEYWORDS2 = { "char", "float", "int", "scanf", "printf", "void" };
}

⌨️ 快捷键说明

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