import java.io.*; import java.util.*; public class Project1a { private String filename = ""; public Project1a(String fn) { filename = fn; } public static char[] strToCharArray(String temp) { char[] array = temp.toCharArray(); return array; } public static void printCharArray(char[] temp) { for(int i = 0; i < temp.length; i++) { System.out.println("Char> " + temp[i]); } } public static Vector stripeWhiteSpace(char[] temp) { Vector v = new Vector(); for(int i = 0; i < temp.length; i++) { String s = temp[i] + ""; if(!(s.equalsIgnoreCase(" "))) { v.add(s); } } return v; } //x11 = 3 * 2 + x11 + 2; //x11:=3*2+x11+2; public static boolean isThere(String tempstr) { String[] operator = {"+","-","/","*",">","<",":","="}; boolean there = false; for(int i = 0; i < operator.length; i++) { if(tempstr.equalsIgnoreCase(operator[i])) { there = true; } } return there; } public static void parseIt(Vector v) { //x11 = 3 * 2 + x11 + 2; //x11>=3*2+x11+2; boolean opFound = false; boolean strFound = false; RealOP rp = new RealOP("C:\\Johnny\\school\\compilers\\relop.txt"); ID_NUM_Check idnum = new ID_NUM_Check(); String tempstr = ""; String tempop = ""; for(int i = 0; i < v.size(); i++) { String currstr = (String)v.get(i); if( currstr.equalsIgnoreCase("+")||currstr.equalsIgnoreCase("-")||currstr.equalsIgnoreCase("*")|| currstr.equalsIgnoreCase("=")||currstr.equalsIgnoreCase(":")||currstr.equalsIgnoreCase("/")|| currstr.equalsIgnoreCase("<")||currstr.equalsIgnoreCase(">") ) { //System.out.println("Operator: " + currstr); opFound = true; strFound = false; tempop = tempop + currstr; } else { //System.out.println("String : " + currstr); tempstr = tempstr + currstr; opFound = false; strFound = true; } if((!tempstr.equalsIgnoreCase("")) && (opFound)) { String strnum = idnum.whatIsIt(tempstr); System.out.println("String >> " + tempstr + " is a " + strnum); tempstr = ""; } if((!tempop.equalsIgnoreCase(""))&& (strFound)) { System.out.print("Operator>> " + tempop + " "); rp.findRealOP(tempop); tempop = ""; } }//for if(!(tempstr.equalsIgnoreCase(""))) { System.out.println("Must be a semicolon"); } } public static void main(String args[]) { String fn = "C:\\Johnny\\school\\compilers\\file.txt"; Project1a p = new Project1a(fn); String line = ""; int exceed = 72; int i = 0; try { BufferedReader br = new BufferedReader(new FileReader(p.filename)); while((line = br.readLine()) != null) { if(line.length() <= 72) { System.out.println(i + ") Line> " + line); char[] array = strToCharArray(line); //printCharArray(array); Vector v = stripeWhiteSpace(array); System.out.println(v); parseIt(v); } else { System.out.println("Line Exceeded " + exceed + " characters"); } System.out.println(); i++; } } catch(IOException e) { System.out.println("Error: " + e); } } }