Re: Converting a string to reals



On Mar 29, 3:30 pm, "psycho_dad" <s.nesse...@xxxxxxxxx> wrote:
Hi all,
I have the following problem in f90 for which I would like some help.
I would like to know
how can I convert a string, say "b**2" to a variable so given the
value b=2. the outcome will be 4.?

Imagine that there may be more complex functions like "exp(b**2)" etc
which I would like to be
able to convert them from strings to variables and given a value for b
get a real result.

Can anyone help me?

Cheers,
psycho_dad

write a script file, shell out to an interpreter with standard output
redurected to a file, then read the file

assuming you are on windows and have gwbasic.exe in your path (compile
with g77):

open(8,file='foo.bas')
write(8,*)'10 b=2'
write(8,*)'20 print b^2'
write(8,*)'30 system'
close(8)
call system('gwbasic foo >foo.txt')
open(9,file='foo.txt')
read(9,*)b
close(9)
print *,b
end

or the equivalent on some other system

or you cound write you own interpreter in Fortran :-(.

-- elliot


.



Relevant Pages

  • Re: Creating an operating system
    ... If your interpreter uses some intermediate representation of the line ... Another option is to compile on-the-fly to an instruction format - ... faster execution on subsequent passes. ... I can imagine this being done for a language, ...
    (comp.programming)
  • Re: Creating an operating system
    ... If your interpreter uses some intermediate representation of the line ... Another option is to compile on-the-fly to an instruction format - ... faster execution on subsequent passes. ... I can imagine this being done for a language, ...
    (comp.os.linux.development.system)
  • Re: Purpose of the LAMBDA keyword?
    ... Actually it is possible to compile dynamic scoping as well, ... compiled lexical scope is more efficient. ... I can't recommend "The Art of the Interpreter" more highly. ...
    (comp.lang.scheme)
  • Re: load and use a ".o" file?
    ... like "true object oriented language". ... (defun foo (l r) ... ;;; unconditionally compile and load the file. ... CMUCL) _only_ have native compilers - no interpreter at all. ...
    (comp.lang.ada)
  • Re: A simple interpreter
    ... >>> It's not actually an interpreter but rather a compiler, ... >>> shows well how to embed a different language in Common Lisp. ... >> I think there's a difference between Common Lisp and Scheme here. ... >> need you may as well compile the expression I would have thought. ...
    (comp.lang.lisp)