LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   string evaluation: FORTRAN OR C .. (https://www.linuxquestions.org/questions/programming-9/string-evaluation-fortran-or-c-128302/)

slackie1000 12-23-2003 03:42 AM

string evaluation: FORTRAN OR C ..
 
Hi guys,

how can we evaluate/convert the string in this case...

a = ' x + y ' - as string!!
x=3.2
y=2.1
How can I make "a" return 5.3???
I work with FORTRAN, but a solution in C is also welcome ...

Regards

Slackie1000

kev82 12-23-2003 07:20 AM

what you need amongst other things is a parser, not the easiest thing to write, theres a c++ book at www.relisoft.com that talks you through the implementation of one but they use a lot of c++ concepts. i seem to remember reading an article by jack crenshaw about building a compiler in pascal, its hosted on a comp.compilers mirror somewhere, the majority of that would be quite useful and being in pascal should be easy to port. if your not interested in writing one but just using one im sure you could grab something off sourceforge and link it into your program.

eric.r.turner 12-23-2003 10:09 AM

Quote:

Originally posted by kev82
what you need amongst other things is a parser, not the easiest thing to write...
Last year I wrote a recursive descent parser to correctly evaluate simple arithmetic expressions. When parsing input, the parser builds a parse tree which is later evaluated. The math functions used to do the evaluation are called via RPC, but you could easily change those to make them local functions. I suppose what you would need to do in C++ is overload the = operator to take a string and use my code to evaluate the string. If you want the source code, let me know at eric.r.turner(at)bitbreather(dot)com.

slackie1000 12-23-2003 10:18 AM

exact....
the target is that... i need to find the "=" symbol and then evaluate the expression..
i would like to implement that also...
anyway it will be very useful if I could see your code..
i will contact you..
thx...
Regards
Slackie1000


All times are GMT -5. The time now is 04:20 AM.