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

📄 testtheprocess.java

📁 词法和语法分析器
💻 JAVA
字号:
package cminusCompiler;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.ListIterator;

/**
 * @author tanfei E-mail:tanfei158876110@163.com
 * @version Create Time:2007-12-7 下午09:39:42 description:
 */
public class TestTheProcess {

	private LinkedList<Nonterminal> nonterminal;

	private HashMap<Integer, String> terminal;

	public TestTheProcess(LinkedList<Nonterminal> n, HashMap<Integer, String> t) {
		nonterminal = n;
		terminal = t;
	}

	public void testForRP() {
		Nonterminal nont;
		LinkedList<LinkedList<String>> follow;
		LinkedList elementList;
		System.out
				.println("********************testForRP**********************");
		System.out.println("The follow list is the nonterminal element:");
		for (ListIterator i = nonterminal.listIterator(); i.hasNext();) {
			nont = (Nonterminal) i.next();
			System.out.println(nont.getName() + ": ");
			follow = nont.getFollowElement();
			// System.out.println("The follow size is: " + follow.size());
			for (ListIterator j = follow.listIterator(); j.hasNext();) {
				elementList = (LinkedList) j.next();
				// System.out.println("The flollow set size is:" +
				// elementList.size());
				for (ListIterator k = elementList.listIterator(); k.hasNext();) {
					String temp = (String) k.next();
					System.out.print(temp + "  ");
				}
				System.out.println();
			}
			System.out
					.println("-----------------------------------------------");
		}
		System.out.println("The follow list is the terminal element:");
		int n = terminal.size();
		for (int i = 0; i < n; i++) {
			System.out.println(terminal.get(i));
		}

		System.out
				.println("*****************End-testForRP********************");
	}

	public void testForFirstSet() {
		Nonterminal nont;
		String element;
		LinkedList<String> tempList;
		System.out
				.println("*****************testForFirstSet*******************");
		System.out.println("The following is the First set:");
		for (ListIterator i = nonterminal.listIterator(); i.hasNext();) {
			nont = (Nonterminal) i.next();
			System.out.println(nont.getName() + ":");
			tempList = nont.getFirstSet();
			for (ListIterator j = tempList.listIterator(); j.hasNext();) {
				element = (String) j.next();
				System.out.print(element + " ");
			}
			System.out.println();
			System.out
					.println("-----------------------------------------------");
		}
		System.out
				.println("*************End--testForFirstSet*******************");
	}

	public void testForFollowSet() {
		Nonterminal nont;
		String element;
		LinkedList<String> tempList;
		System.out
				.println("*****************testForFollowSet*******************");
		System.out.println("The following is the Follow set:");
		for (ListIterator i = nonterminal.listIterator(); i.hasNext();) {
			nont = (Nonterminal) i.next();
			System.out.println(nont.getName() + ":");
			tempList = nont.getFollowSet();
			for (ListIterator j = tempList.listIterator(); j.hasNext();) {
				element = (String) j.next();
				System.out.print(element + " ");
			}
			System.out.println();
			System.out
					.println("-----------------------------------------------");
		}
		System.out
				.println("*************End--testForFollowtSet*******************");
	}

	@SuppressWarnings("unchecked")
	public void testForLL1Table(HashMap<Integer, String> nont,
			HashMap<Integer, String> ter, LinkedList table[][]) {
		int i, j;
		boolean temp;
		LinkedList<String> tempList;
		String element;
		System.out
				.println("*****************testForLL1Table*******************");
		System.out.println();
		for (i = 0; i < nont.size(); i++) {
			for (j = 0; j < ter.size() + 1; j++) {
				if(j == ter.size()){
				System.out.println(nont.get(i) + " -> $");
				}else if(table[i][j].size() > 0){
					System.out.println(nont.get(i) + "[" + i +"] -> " + ter.get(j) + "[" + j + "]");
				}
				tempList = table[i][j];
				temp = false;
				for (ListIterator k = tempList.listIterator(); k.hasNext();) {
					element = (String) k.next();
					System.out.print(element + " ");
					temp = true;
				}
				if(temp){
					//System.out.print("No element!!!");
					System.out.println();
				}
				//System.out.println();
				//System.out.println("------------------------------------------");
			}
		}
		System.out
				.println("*************End--testForLL1Table*******************");

	}

}

⌨️ 快捷键说明

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