/**共有三个类**①主类Op.java*②处理算法的关键类GetFL.java*③读取信息类ReadInfo.java从TXT文件中读取文法**
/*
* author:Ack訾
* Date:15/11/2012
* Attention:
*/
package com.algorithm;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class OP {
/**
* @param args
*/
public static void main(String[] args)throws IOException {
String fileName="H:\\大三实验课\\编译原理\\实验3\\input.txt";
ReadInfo ri=new ReadInfo();
String[][] ll = ri.gettext(fileName);
GetFL fl=new GetFL(ll);
//①读取的文法放在ll[][]二维数组中,可根据下面的注释语句进行打印
System.out.println(" 文法G"+"["+ll[0][0]+"]"+":");
System.out.println(" "+ll[0][0]+"'"+"->"+"#"+ll[0][0]+"#");
for(int i=0;i<ll[0].length;i++){
System.out.print(" "+ll[0][i]);
System.out.print("->");
System.out.println(ll[1][i]);
}
System.out.println(" ");
//②终结符放在NT[]中(not terminate)可通过下面注释语句进行打印
String[]NT = fl.getNT();
System.out.print(" 非终结符集:");System.out.print("{");
for(int i=0;i<NT.length;i++){
//if(NT[i]=="\\'"){System.out.print("亲!咱解决不了含有“‘”的文法");}
if(NT.length-1==i)
System.out.print(NT[i]);
else
System.out.print(NT[i]+",");
}
System.out.println("}");
//③终结符放在T[]中(teminate) 可通过下面注释语句进行打印
String[]T = fl.getT();
System.out.print(" 终结符集:");System.out.print("{");
for(int i=0;i<T.length;i++){
if(T.length-1 ==i)
System.out.print(T[i]);
else
System.out.print(T[i]+",");
}
System.out.println("}");
System.out.println(" ");
//④FIRSTVT求解过程
String[][] FirstVT = fl.getFirstVT();
System.out.println(" FIRSTVT集:");
System.out.println(" LASTVT("+FirstVT[0][0]+"'"+")"+"="+"{"+"#"+"}");
for(int i=0;i<FirstVT[0].length;i++){
System.out.print(" FIRSTVT("+FirstVT[0][i]+")"+"="+"{");
//System.out.println(FirstVT[1][i]);
//if(NT[i]=="\\'"){System.out.print("亲!咱解决不了含有“‘”的文法");}
char[] ch=FirstVT[1][i].toCharArray();
for(int j=0;j<ch.length;j++){
if(ch.length-1 ==j)
System.out.print(ch[j]);
else System.out.print(ch[j]+",");
}
System.out.println("}");
}
System.out.println(" ");
//⑤LASTVT求解过程
String[][] LastVT = fl.getLastVT();
System.out.println(" LASTVT集:");
System.out.println(" LASTVT("+LastVT[0][0]+"'"+")"+"="+"{"+"#"+"}");
for(int i=0;i<LastVT[0].length;i++){
System.out.print(" LASTVT("+LastVT[0][i]+")"+"="+"{");
//System.out.println(FirstVT[1][i]);
//if(NT[i]=="\\'"){System.out.print("亲!咱解决不了含有“‘”的文法");}
char[] ch=LastVT[1][i].toCharArray();
for(int j=0;j<ch.length;j++){
if(ch.length-1 ==j)
System.out.print(ch[j]);
else System.out.print(ch[j]+",");
}
System.out.println("}");
}
System.out.println();
//⑥求解算符优先矩阵
System.out.println("算符优先关系矩阵");
System.out.println("-------------------------------------------------------------------");
System.out.print("\t");
for(int i=0;i<T.length;i++){
System.out.print(T[i]+"\t");
}
System.out.println();
System.out.println("-------------------------------------------------------------------");
String[][] Op=fl.getMatrix();
for(int i=0;i<Op[0].length;i++){
System.out.print(" "+T[i]);
for(int j=0;j<Op[0].length;j++)