in reply to Re^3: Parsing and converting Fortran expression
in thread Parsing and converting Fortran expression [solved]

f2c seems to make all sorts of assumptions about variables, functions and expected output, many of which turn out to be wrong (e.g. by default, it interprets the statement "a = foo(1,2)" as if foo were a function, so it turns that into "a = foo_(&c__1, &c__2)"

I've used Fortran exactly twice, for "hello world" class programs, and that was about 20 years ago. But I think this is how Fortran actually works. If there is no matching array in the current scope, it must be a function call. And so on.

What is the context in which you need to parse / translate Fortran expressions? I.e. what problem are you actually trying to solve? My guess is that Fortran expressions should be quite rare outside a Fortran program, hence f2c.

"The program f2c is a horror, based on ancient code and hacked unmercifully. Users are only supposed to look at its C output, not at its appalling inner workings."

How desperate are you? Real world old code almost always looks ugly and has been hacked into a state where at least parts of it "just works, probably by pure magic". f2c looks quite small, so it should not be that hard to find and understand the relevant parts.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
  • Comment on Re^4: Parsing and converting Fortran expression

Replies are listed 'Best First'.
Re^5: Parsing and converting Fortran expression
by kikuchiyo (Hermit) on Aug 26, 2015 at 19:02 UTC

    what problem are you actually trying to solve? My guess is that Fortran expressions should be quite rare outside a Fortran program, hence f2c.

    This guess is unfortunately false. As to the actual problem: ugly old proprietary program at $work that uses Fortran-style expressions in certain contexts needs to be ported to a different framework that required generation of C code.

    Real world old code almost always looks ugly and has been hacked into a state where at least parts of it "just works, probably by pure magic". f2c looks quite small, so it should not be that hard to find and understand the relevant parts.

    Believe me, I've seen more real world old code than I'd have liked. "I've seen things you humans wouldn't believe" and so on. And luckily, a better, or at least easier, solution appeared in this thread.