Re: Fortran to VB translator - an update

"Nick Roberts" <nick.roberts@acm.org>
9 Aug 2004 01:11:50 -0400

          From comp.compilers

Related articles
Fortran to VB translator - an update postmaster@paul.washington.dc.us (Paul Robinson) (2004-08-05)
Fortran to VB translator - an update postmaster@paul.washington.dc.us (Paul Robinson) (2004-08-09)
Re: Fortran to VB translator - an update nick.roberts@acm.org (Nick Roberts) (2004-08-09)
| List of all articles for this month |
From: "Nick Roberts" <nick.roberts@acm.org>
Newsgroups: comp.compilers
Date: 9 Aug 2004 01:11:50 -0400
Organization: Compilers Central
References: 04-08-025
Keywords: translator, comment
Posted-Date: 09 Aug 2004 01:11:50 EDT

On 5 Aug 2004 14:24:01 -0400, Paul Robinson
<postmaster@paul.washington.dc.us> wrote:


> A few weeks ago I mentioned I am working on a Fortran to VB translator
> because of a contract I accepted. Some people commented to me (in a
> polite way) that I was crazy for taking on an impossible task (since
> the first Fortran compiler took 18 man years), someone pointed out
> that the current program around doing Fortran is something like 27,000
> lines of C code, and some said if I'm doing this comprehensive a
> project I should be charging hundreds of thousands of dollars based on
> the time involved.
> ...
> Maybe it goes to show that sometimes when you don't know it's
> impossible you can get some really great things done!


I'm impressed, and I think you can take it for granted that everyone
else reading this news group is, too.


This is the kind of project I would use a language such as Prolog to
solve.


The basic approach, I think, would be to write two (hopefully quite
simple) programs in an imperative language (e.g. BASIC): (a)
translates the input source (FORTRAN programs) into a series of Prolog
terms; (b) reads a series of Prolog terms and translates them into the
output (VB programs).


This then provides the basis to write a Prolog program which reads
terms from (a), does all the necessary manipulation (using a set of
rules), and outputs the result to (b).


        Fortran --> (a) --> Prolog --> (b) --> VB


The Fortran:


            DO I 1,10,100
            X = X + A(I)
100 ...


might be serilaised into the terms:


keyword("DO")
identifier("I")
number("1")
symbol(",")
...


then there might be a Prolog rule:


        forloop(LoopVar,InitVal,EndVal,Body) -->
              keyword("DO"),
              identifier(LoopVar),
              ...


and maybe:


        toVB(
              forloop(LoopVar,InitVal,EndVal,Body),
              [keyword("FOR"),identifier(LoopVar),...] ).


which might then generate the terms*:


keyword("FOR")
identifier("I")
symbol("=")
...


which would then be output as:


        FOR I = 1 TO 10
        ...
        NEXT I


Hopefully this gives a flavour. Just musing really.


--
Nick Roberts


*To be honest, the output might be uglier than this, but it doesn't
matter.
[I'd probably do it in perl. Fortran and VB are semantically close enough
that you can often transliterate expressions and get away with it. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.