Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String to Executable Code

Status
Not open for further replies.

THEMAN101

Programmer
Apr 29, 2003
44
US
I have a string variable, that holds a mathematical equation such as 4+5-6/(9+3) now i would like to be able to take this string variable and have the java compiler execute a line of code.

Such as

if i wanted to execute this command to store it in a var, but dont want to have the user pick the equation then i would do:

sum = 4+5-6/(9+3);

and sum woul equal 8.5.

now what if it was like this:

String equation;
equation = textFeild.getText();

sum = // Now what would i put here

Hope this explains it.

If you need more explination just post.
Thanks all.
 
I think you cannot do it as simple as you want, instead you have to use a parser generator as prosper said before, I suggest you to use JavaCC it is somehow easy to learn and use,

I hope this helps,

You can find information about it on

Oscar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top