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

📄 forecast.java

📁 这个是java版本的pl0语言的词法分析器,带有图形界面,很好的
💻 JAVA
字号:
package myCompiler;

public class Forecast {
int[][] production={
		{0,0,0,0,0,0,0,0,0,0,0,0},
		{159,24,0,0,0,0,0,0,0,0,0,0},
		{160,163,165,168,0,0,0,0,0,0,0,0},
		{1,161,162,26,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0},
		{31,18,30,0,0,0,0,0,0,0,0,0},
		{25,161,162,0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0},
		{2,31,164,26,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0},
		{25,31,164,0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0},
		{166,159,26,167,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0},
		{3,31,26,0,0,0,0,0,0,0,0,0},
		{166,159,26,167,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0},
		{169,0,0,0,0,0,0,0,0,0,0,0},
		{172,0,0,0,0,0,0,0,0,0,0,0},
		{173,0,0,0,0,0,0,0,0,0,0,0},
		{174,0,0,0,0,0,0,0,0,0,0,0},
		{175,0,0,0,0,0,0,0,0,0,0,0},
		{176,0,0,0,0,0,0,0,0,0,0,0},
		{170,0,0,0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0},
		{31,27,179,0,0,0,0,0,0,0,0,0},
		{10,168,171,11,0,0,0,0,0,0,0,0},
		{26,168,171,0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0},
		{4,9,5,168,0,0,0,0,0,0,0,0},
		{6,178,7,168,0,0,0,0,0,0,0,0},
		{12,31,0,0,0,0,0,0,0,0,0,0},
		{8,28,31,164,29,0,0,0,0,0,0,0},
		{9,28,179,177,29,0,0,0,0,0,0,0},
		{25,179,177,0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0},
		{179,186,179,0,0,0,0,0,0,0,0,0},
		{13,179,0,0,0,0,0,0,0,0,0,0},
		{14,181,180,0,0,0,0,0,0,0,0,0},
		{15,181,180,0,0,0,0,0,0,0,0,0},
		{181,180,0,0,0,0,0,0,0,0,0,0},
	    {184,181,180,0,0,0,0,0,0,0,0,0},
	    {0,0,0,0,0,0,0,0,0,0,0,0},
	    {183,182,0,0,0,0,0,0,0,0,0,0},
	    {185,183,182,0,0,0,0,0,0,0,0,0},
	    {0,0,0,0,0,0,0,0,0,0,0,0},
	    {31,0,0,0,0,0,0,0,0,0,0,0},
	    {30,0,0,0,0,0,0,0,0,0,0,0},
	    {28,179,29,0,0,0,0,0,0,0,0,0},
	    {14,0,0,0,0,0,0,0,0,0,0,0},
	    {15,0,0,0,0,0,0,0,0,0,0,0},
	    {16,0,0,0,0,0,0,0,0,0,0,0},
	    {17,0,0,0,0,0,0,0,0,0,0,0},
	    {18,0,0,0,0,0,0,0,0,0,0,0},
	    {19,0,0,0,0,0,0,0,0,0,0,0},
	    {20,0,0,0,0,0,0,0,0,0,0,0},
	    {21,0,0,0,0,0,0,0,0,0,0,0},
	    {22,0,0,0,0,0,0,0,0,0,0,0},
	    {23,0,0,0,0,0,0,0,0,0,0,0}};

int[][] table={{1,1,1,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1},
		{2,2,2,2,0,2,0,2,2,2,0,2,0,0,0,0,0,0,0,0,0,0,0,2,0,2,0,0,0,0,2},
		{3,4,4,4,0,4,0,4,4,4,0,4,0,0,0,0,0,0,0,0,0,0,0,4,0,4,0,0,0,0,4},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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0,0,0,0,0,0,37,36,36,0,0,0,0,0,0,0,0,0,0,0,0,36,0,36,36},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,38,39,0,0,0,0,0,0,0,0,0,0,0,0,40,0,40,40},
		{0,0,0,0,42,0,42,0,0,0,0,0,0,41,41,0,0,0,0,0,0,0,0,0,42,0,0,0,42,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,0,43,43},
		{0,0,0,0,45,0,45,0,0,0,0,0,0,45,45,44,44,0,0,0,0,0,0,0,45,0,0,0,45,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,0,47,46},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,49,50,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,53,54,55,56,57,58,0,0,0,0,0,0,0,0}};
int[] stack=new int[100];
int top=-1;
int x;
int i;
int j;
GetWords getwords;
SYM sym;
boolean flag=true;
public Forecast(String SourceFileName){
	getwords=new GetWords(SourceFileName);
}
public void getword() {
	getwords.getsym();
	sym = getwords.sym;
	System.out.print(sym.name);
	System.out.println(" " + sym.code);
}
public static void main(String args[]){
	String s = "d:/pl0_1.txt";
	Forecast ff=new Forecast(s);
	ff.forecast();
}
public void forecast(){
	
	stack[++top]=35;
	stack[++top]=158;
	getword();
	while(flag){
		x=stack[top--];
		if(x>=158){
			if(table[x-158][sym.code]!=0){
				i=0;
				while(production[table[x-158][sym.code]][i]!=0){
					i++;
					for (j=i-1;j>0;j--){
						stack[++top]=production[table[x-128][sym.code]][i];
						
					}
					
				}
			}else Error.error(100);
		}
		else if(x<=35)
			if(x==sym.code)
			{
				if(x==35)
					flag=false;
				else 
					getword();
				
			}else Error.error(101);
		else Error.error(102);
	}
	
}


}

⌨️ 快捷键说明

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