The Artima Developer Community
Sponsored Link

Java Answers Forum
HELP - converting characters

1 reply on 1 page. Most recent reply: May 23, 2005 1:47 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Elise

Posts: 1
Nickname: zesty
Registered: May, 2005

HELP - converting characters Posted: May 18, 2005 7:13 AM
Reply to this message Reply
Advertisement
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


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: HELP - converting characters Posted: May 23, 2005 1:47 AM
Reply to this message Reply
Here is a quick and dirty solution...

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.


Hope this helps...

Flat View: This topic has 1 reply on 1 page
Topic: copy constructor,Wrapper classes Previous Topic   Next Topic Topic: Problem on Socket Program

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use