Help me improve parsing trick?

A

Aaron Fude

Hi,

I use this trick for parsing mathematical expressions, that when a user
enters sin(x) + cos(x) my program pastes that line into a java class
"template", writes the code to some file, runs a shell command to compile it
and then loads the class. There are several advantages over something like
"JEP". First, I can use any java expression. Second, compiled code then runs
much faster.

This works but takes too long. Is there a way to speed this up by doing
everything in memory and avoid writing to files and running compilation
scripts.

Many thanks in advance,

Aaron Fude
 
A

Andrew Thompson

This works but takes too long. Is there a way to speed this up by doing
everything in memory and avoid writing to files and running compilation
scripts.

You can avoid the last part by invoking javac from within Java itself.

( But I do not know if that will be any 'quicker'. )
 
A

Aaron Fude

Andrew Thompson said:
You can avoid the last part by invoking javac from within Java itself.

( But I do not know if that will be any 'quicker'. )

Can you give an example of how to do it?
 
A

Andrew Thompson

Andrew Thompson said:
....
Thank you. But is there a way to avoid writing the code to a file but
compile it directly from a String?

Not that I know of, though I heard some rumble of perhaps
accepting String or other arguments in 1.6 assuming Sun
makes the compilation classes public, as opposed to not
supporting direct compilation from within Java.
 
B

bugbear

Aaron said:
Hi,

I use this trick for parsing mathematical expressions, that when a user
enters sin(x) + cos(x) my program pastes that line into a java class
"template", writes the code to some file, runs a shell command to compile it
and then loads the class. There are several advantages over something like
"JEP". First, I can use any java expression. Second, compiled code then runs
much faster.

How often is the expression evaluated?

BugBear
 
R

Rogan Dawes

Aaron said:
Hi,

I use this trick for parsing mathematical expressions, that when a user
enters sin(x) + cos(x) my program pastes that line into a java class
"template", writes the code to some file, runs a shell command to compile it
and then loads the class. There are several advantages over something like
"JEP". First, I can use any java expression. Second, compiled code then runs
much faster.

This works but takes too long. Is there a way to speed this up by doing
everything in memory and avoid writing to files and running compilation
scripts.

Many thanks in advance,

Aaron Fude

Surely it would be a LOT simpler just to use something like beanshell?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top