I need to write a program that will read in a line of java (input by user) and transform it/return it to pseudocode - or just normal english basically! In order to do this, I THINK, i need to be able to convert basic java text like int, double, =, + and expressions like total = num1 + num2 in to english. I just have NO idea where to start or even what java to use in order to convert something... ANY help at all would be REALLY REALLY appreaciated, I'm new to all this! Thanks
Create a method that returns a Vector of String representations of your data. Use a StringTokenizer to traverse the line
public Vector parseLine(String line){ Vector vec = new Vector(); StringTokenizer tok = new StringTokenizer(line); while(tok.hasMoreTokens()){ String temp = ""; // Use Java API to replace isAlphabetic String temp2 = tok.nextToken(); if(temp2.isAlphabetic()) temp = temp + temp2; if(temp.equals("int")){ temp = "whatEverStringUWantToRepInt"; vec.add(temp); } else if(...) ... ... ... else if(temp.equals("+")){ temp = "PLUS"; vec.add(temp); } } return vec; }
call this method from whereever you want to use it passing in the java line to parse and traverse the vector printing it out with a vec(i).toString() where i is your iteration upto the size of the vector.