LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-23-2003, 03:42 AM   #1
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
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
 
Old 12-23-2003, 07:20 AM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
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.
 
Old 12-23-2003, 10:09 AM   #3
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint
Posts: 216

Rep: Reputation: 31
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.
 
Old 12-23-2003, 10:18 AM   #4
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Original Poster
Rep: Reputation: 46
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
does linux fortran compiler in fedora 4 support VAX FORTRAN? terrence Programming 17 08-31-2005 08:59 AM
expression evaluation sharadgana Programming 1 01-10-2005 03:38 PM
9.2 Evaluation --Unrunnable for me 1kyle SUSE / openSUSE 7 10-31-2004 11:24 AM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM
complete string conversion - without parts evaluation slackie1000 Programming 9 01-06-2004 01:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration