📄 yufafenxi.java
字号:
package com;
//import java.util.Stack;
//import com.*;
class yufafenxi {
String evaluate1[] = {"i","=","+","*","(",")","#"};
String evaluate2 = "E";
String conExp1[] = {"i",">","<","=","#"};
String conExp2[] = {"E"};
int Matrix1[][]={
{1 ,-1 ,-1 ,-1 ,-1 ,-1 ,-1},
{-1 ,2 ,-1 ,-1 ,-1 ,-1 ,-1},
{5 ,-1 ,-1 ,-1 ,4 ,-1 ,-1},
{-1 ,-1 ,6 ,7 ,-1 ,-1 ,0},
{-1 ,-1 ,24 ,24 ,-1 ,24 ,24},
{5 ,-1 ,-1 ,-1 ,4 ,-1 ,-1},
{5 ,-1 ,-1 ,-1 ,4 ,-1 ,-1},
{-1 ,-1 ,6 ,7 ,-1 ,11 ,-1},
{-1 ,-1 ,21 ,7 ,-1 ,21 ,21},
{-1 ,-1 ,22 ,22 ,-1 ,22 ,22},
{-1 ,-1 ,23 ,23 ,-1 ,23 ,23},
};
int Matrix2[] = {-1,-1,3,-1,8,-1,9,10,-1,-1,-1,-1};
LRStack s = new LRStack();
public void yufafenxi1(String[] ci)
{
//LRStack s = new LRStack();
int point = 0;
String[] di = ci;
System.out.print("st"+" "+"sy"+" "+"AC"+" "+"GO"+"\n");
//System.out.print(s.peekState()+" "+s.peekSymbol()+" "+"ACTION"+" "+"GOTO"+"\n");
System.out.print(s.peekState()+" ");
System.out.print(s.peekSymbol()+" ");
System.out.print("\n");
while (point < di.length)
{
int col1 = index(di[point]);
int sta = s.peekState();
int act = Matrix1[sta][col1];
if((sta ==3)&&(col1 == 6))
{
System.out.println("ACC");
return; //acc接受
}
else if (act != 0)
{
if (act < 20)
{
s.pushState(act);
s.pushSymbol("di[point]");
/*while(!(s.state.empty()))
{
System.out.print(s.state.peek());
}
while(!(s.symbol.empty()))
{
System.out.print(s.symbol.peek());
}
System.out.print("\n");*/
}//移进
else
{
if (act !=24)
s.pop(3);
else s.pop(1);
s.pushSymbol("E");
s.pushState(Matrix2[s.peekState()]);
}
}
else
{
System.out.println("语法错误");
break;
}
point++;
}
}
int index(String c){
String s[]={"i","=","+","*","(",")","#"};
for(int i=0;i<s.length;i++){
if(c!=null&&c.equals(s[i])){
//System.out.println(c);
return i;
}
}
return -1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -