资源简介
对如下文法进行非递归预测分析
E→E+T | E-T | T
T→T*F | T/F |F
F→(E) | i
代码片段和文件信息
import java.util.ArrayList;
import java.util.Stack;
public class Test {
private static ArrayList nlist = new ArrayList();//非终结符
private static ArrayList tlist = new ArrayList();//终结符
private static String[][] state = new String[5][8];//分析表
private static Stack stack = new Stack();//状态栈
private static ArrayList input = new ArrayList();//输入串
public static void init() {
nlist.add(‘E‘);
nlist.add(‘e‘);
nlist.add(‘T‘);
nlist.add(‘t‘);
nlist.add(‘F‘);
tlist.add(‘i‘);
tlist.add(‘+‘);
tlist.add(‘-‘);
tlist.add(‘*‘);
tlist.add(‘/‘);
tlist.add(‘(‘);
tlist.add(‘)‘);
tlist.add(‘$‘);
//error表示出错;ε用““表示;T‘ E‘分别用t e表示
state[0][0] = “Te“;
state
评论
共有 条评论