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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read an equation from a source file????

Status
Not open for further replies.

nkcfjg

Technical User
Dec 6, 2003
3
GR
i would like to read an equation of the type : (15**2-d**2)**0.5 with the variable d, with the command READ(7,*)C and it gives me an error message.Do i have to state that d is a variable???how???Any ideas?It is kind of urgent,because i have to deliver my homework at school...
 
You'll have to write a parser for that. You can't just read an expression in and expect the system to interpret it.

You could read in the value of d and get the program to compute the value though. Is that what's required?
 
I thought there might have been a command to do that..Anyway the EQUATION must NOT be read from the source file, it must be read from e.g. input.txt .That means that if i want to calculate the value of d**10 instead of the equation above, i could simply do that by changing the equation in the file input.txt.I do not know what a parser is, but it doesn't sound like something that can easily be taught
 
Fortran is a compiled language. There is no any compiler when your program runs. It's machine instructions compiled from your source code plus library modules. Executable code has no idea about
Code:
d
variable: it has machine word and its address - that's all.
The simplest expression parser in Fortran? Why not, but it contains more than 100 lines of code (some handreds, I think). But this parser don't know your code d variable too (see above)...
 
Thanks anyway...Do you know any site that might have the parser i want??? Or something close to that, so that i can modify it?Are ther any sites with parsers? thanks for all the help. I appreciate that you answered to my question
 
I haven't seen any sites with parsers for arithmetic expressions in Fortran. Most of them are in C/C++, possibly using lex and yacc.
 
You can see a simplest expression parser example in the excellent book "The C++ Programming Language" by Bjarne Stroustrup (calculator example). It's not so hard to rewrite it in modern (90/95, with recursion etc) Fortran (additionally you can see what Fortran borrowed from C++;)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top