For Programmers: Free Programming Magazines  


Home > Archive > Fortran > March 2008 > Fortran 77 parser









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Fortran 77 parser
Jon Harrop

2008-03-09, 7:28 pm


I'd like to automatically translate a legacy codebase from F77 to a new
language. Are there any freely available Fortran 77 parsers out there or
programs that can dump the AST to an easy-to-parse format like XML?

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?u
William Clodius

2008-03-09, 7:28 pm

Jon Harrop <usenet@jdh30.plus.com> wrote:

> I'd like to automatically translate a legacy codebase from F77 to a new
> language. Are there any freely available Fortran 77 parsers out there or
> programs that can dump the AST to an easy-to-parse format like XML?

see
http://groups.google.com/group/comp...rm/thread/5ca5c
a150a878578/e0be2773100b0ade?lnk=gst&q=wclodius#e0be2773100b0ade

However, parsing F77 is only part of the problem. Getting the semantics
right to transfom automatically and successfully to another language is
roughly equivalent to writing the back end (and run time library) of a
compiler. That is typically a far more compicated task than simply
parsing the language. If the language is a low level imperative language
with many similar constructs, and you are not too demanding in terms of
optimization, the back end will be simpler than that for many
microprocessors, see F2C, but the code will almost certainly be
illegible and difficult to maintain in the new form, see F2C again.
Unless you have an extremely good reason, i.e., the code is to be used
on a processor for which a Fortran compiler is unavailable (but how many
processor are not addressed by gcc and gfortran?) such translations are
rarely advisable. If the translation is to be automated you will either
have to spend a hell of a lot of time writing the translating code, or
pay someone a lot of money to do it. (Unless the language is C, in which
case use F2C.) I suggest instead either

1. Writing a wrapper code to call the Fortran routines through the other
language, using the F2003 C interface, and using the appropriate
language's C interface if available. (Many language's define such an
interface). Note the F2003 C interfac is available on many compilers.

2. Use a three layer interface Fortrab-> Ada -> D using Ada's
definitions for those interfaces.

3. Use Python as a wrapper (SWIG?) for the Fortan code.

4. Output the Fortran results to a file that is read by your other
language.

5. Translate by hand only the few most critical routines, and rewrite
the rest of the code by scratch.
Craig Dedo

2008-03-10, 7:52 pm

"Jon Harrop" <usenet@jdh30.plus.com> wrote in message
news:13t8pjdr4sqmbe0@corp.supernews.com...
>
> I'd like to automatically translate a legacy codebase from F77 to a new
> language. Are there any freely available Fortran 77 parsers out there or
> programs that can dump the AST to an easy-to-parse format like XML?
>
> --
> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
> http://www.ffconsultancy.com/products/?u


Why do you want to translate the F77 to another language? Why not upgrade
it to F95? FWIW, there are several good quality Fortran restructuring tools.
Perhaps restructuring the Fortran code to more modern structure would be the
best approach.

--
Craig Dedo
17130 W. Burleigh Place
P. O. Box 423
Brookfield, WI 53008-0423
Voice: (262) 783-5869
Fax: (262) 783-5928
Mobile: (414) 412-5869
E-mail: <cdedo@wi.rr.com> or <craig@ctdedo.com>

Beliavsky

2008-03-10, 7:52 pm

On Mar 10, 9:19=A0am, "Craig Dedo" <cd...@wi.rr.com> wrote:
> "Jon Harrop" <use...@jdh30.plus.com> wrote in message
>
> news:13t8pjdr4sqmbe0@corp.supernews.com...
>
>
>
[color=darkred]
>
>
> =A0 =A0 Why do you want to translate the F77 to another language? =A0Why n=

ot upgrade
> it to F95? =A0FWIW, there are several good quality Fortran restructuring t=

ools.
> Perhaps restructuring the Fortran code to more modern structure would be t=

he
> best approach.


If you read past messages of Mr. Harrop you will recognize that it
would be equally fruitful to give this advice to a rock.
Jon Harrop

2008-03-10, 7:52 pm

Craig Dedo wrote:
> Why do you want to translate the F77 to another language?


To call the code transparently from another language. FFI to native Fortran
would impose security privileges upon my library that I do not want.
Performance will be slightly worse but more than adequate.

> Why not upgrade it to F95?


That offers no relevant benefits. Interop with F95 code would be just as bad
as interop with F77 code.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?u
Gordon Sande

2008-03-10, 7:52 pm

On 2008-03-10 11:48:27 -0300, Jon Harrop <usenet@jdh30.plus.com> said:

> Craig Dedo wrote:
>
> To call the code transparently from another language. FFI to native Fortran
> would impose security privileges upon my library that I do not want.
> Performance will be slightly worse but more than adequate.
>
>
> That offers no relevant benefits. Interop with F95 code would be just as bad
> as interop with F77 code.


The GNU Fortran has its syntax tree as debugging output. You could use
that to satisfy your original request for an AST.

All you need to do is act like a GCC backend and runtime support to
generate OCaml or F# or whatever it is your intent. There are some Fortrans
that claim to support .net directly which may also be of interest to you.


Jon Harrop

2008-03-10, 7:52 pm

Gordon Sande wrote:
> The GNU Fortran has its syntax tree as debugging output. You could use
> that to satisfy your original request for an AST.


I have had a look at this already, using --dump-parse-tree, but I can make
no sense of the output. For example:

$ gfortran --dump-parse-tree zgeev.f

Namespace: A-H: (REAL 4) I-N: (INTEGER 4) O-Z: (REAL 4)
procedure name = zgeev
symtree: __convert_c8_i4 Ambig 0
symbol __convert_c8_i4 (INTEGER 4)(PROCEDURE UNKNOWN-INTENT
UNKNOWN-ACCESS UNKNOWN-PROC UNKNOWN FUNCTION ELEMENTAL PURE)

symtree: __convert_i4_c8 Ambig 0
symbol __convert_i4_c8 (COMPLEX 8)(PROCEDURE UNKNOWN-INTENT
UNKNOWN-ACCESS UNKNOWN-PROC UNKNOWN FUNCTION ELEMENTAL PURE)

It doesn't seem any easier to parse than F77. Is there a better intermediate
representation that I can get my hands on?

> All you need to do is act like a GCC backend and runtime support to
> generate OCaml or F# or whatever it is your intent. There are some
> Fortrans that claim to support .net directly which may also be of interest
> to you.


Excellent idea! Any recommendations for a free Fortran .NET compiler?

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?u
FX

2008-03-10, 7:52 pm

> I have had a look at this already, using --dump-parse-tree, but I can make
> no sense of the output.


I think what what Gordon was referring to is the output of
-fdump-tree-original. I wouldn't advise it either, as it's is present for
debugging purposes and probably isn't a good intermediate representation.

--
FX
Ken Plotkin

2008-03-11, 4:47 am

On Mon, 10 Mar 2008 08:19:53 -0500, "Craig Dedo" <cdedo@wi.rr.com>
wrote:


> Why do you want to translate the F77 to another language? Why not upgrade
>it to F95?

[snip]

Wouldn't that count as translation to another language? :-)
Tom Micevski

2008-03-11, 7:23 pm

Jon Harrop wrote:
>
> Excellent idea! Any recommendations for a free Fortran .NET compiler?


see if ftn95 satisfies you:
http://www.silverfrost.com/11/ftn95...for_windows.asp
Jon Harrop

2008-03-11, 7:23 pm

Tom Micevski wrote:
> see if ftn95 satisfies you:
> http://www.silverfrost.com/11/ftn95...for_windows.asp


Fantastic. I'll check it out, thanks!

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?u
Jon Harrop

2008-03-11, 10:17 pm

Tom Micevski wrote:
> Jon Harrop wrote:
>
> see if ftn95 satisfies you:
> http://www.silverfrost.com/11/ftn95...for_windows.asp


Alas, that produces pointer-heavy code that is entirely unsafe (thus
breaking the security guarantees that I need).

I'll try writing my own compiler to see how hard it is...

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?u
Steven G. Kargl

2008-03-12, 4:46 am

In article <13teehkmbm5rr39@corp.supernews.com>,
Jon Harrop <usenet@jdh30.plus.com> writes:
> Tom Micevski wrote:
>
> Alas, that produces pointer-heavy code that is entirely unsafe (thus
> breaking the security guarantees that I need).
>
> I'll try writing my own compiler to see how hard it is...
>


If all you really care about is Fortran 77, then grab f2c
from netlib. Otherwise, I think you severely under estimate
the difficult involved with one person writing a Fortran 77
compiler.

--
Steve
Lunke

2008-03-16, 7:37 am

Jessica Simpson , 20 Ebony Pics!

http://www.CheapVideoBlog.com/b?movie=726648
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com