Ratforプレプロセッサー -- 変換の実例2017年08月16日 20:29

Ratforが動き出しましたので、実際に、Ratforデーコーディングしたコードが、 そのように、変換されるかをご紹介します。

Software Toolsで最初に紹介されている、copyはどのようになるでしょうか。 まずは、元となるRatforのコードをしめします。

# copy.r4 -- copy input characters to output
include ratfor.mac
program copy
character getc
character c

while (getc(c) != EOF)
    call putc(c)
stop
end

これを、include、macro、ratforを等した結果は、以下のようになります。

      programcopy
      integer*1getc
      integer*1c
      continue
50000 if (.not. (getc(c) .ne. -1)) goto 50001
      callputc(c)
      goto 50000
50001 continue
      stop
      end

いくつか注意すべき点があります。"programcopy"、"callputc"は、コンパイルエラーになりそうですが、 そうはなりません。それぞれ、"program copy"、"call putc"とWATCOM Fortran 77コンパイラーは、 解釈しますので、コンパイルエラーを生じません。

この程度の変換では、返還後のコードを人が解釈するには、抵抗を感じませんが、複雑になると抵抗を 感じます。たとえば、getfns.r4を見てみますと、

getfns.r4は以下の通りですが、

# getfns.r4 -- get file names into fname, check for duplicates
include ratfor.mac
subroutine getfns()
integer equal,getarg,i,j
character junk(2)
include carch

errcnt = 0
for (i = 1; i <= MAXFILES; i = i + 1)
     if (getarg(i+2,fname(1,i),NAMESIZE) == EOF)
         break
nfiles = i - 1
if (i > MAXFILES)
    if (getarg(i+2,junk,2) != EOF)
        call error('too many files.')
for (i = 1; i <= nfiles; i = i + 1)
    fstat(i) = NO
for (i = 1; i < nfiles; i = i + 1)
    for (j = i + 1; j <= nfiles; j = j + 1)
        if (equal(fname(1,i),fname(1,j)) == YES) {
            call putlin(fname(1,i),ERROUT)
            call error(': duplicate file name.')
            }
return
end

返還後はの要になります。

      subroutinegetfns()
      integerequal,getarg,i,j
      integer*1junk(2)
      common/carch/fname(81,20),fstat(20),nfiles,errcnt
      integer*1fname
      integerfstat
      integernfiles
      integererrcnt
      errcnt=0
      continue
      i=1
50000 if (.not. (i .le. 20))goto 50001
      if (.not. (getarg(i+2,fname(1,i),81) .eq. -1)) goto 50003
      goto 50001
50003 continue
50002 continue
      i=i+1
      goto 50000
50001 continue
      nfiles=i-1
      if (.not. (i .gt. 20)) goto 50005
      if (.not. (getarg(i+2,junk,2) .ne. -1)) goto 50007
      callerror(15Htoo many files.)
50007 continue
50005 continue
      continue
      i=1
50009 if (.not. (i .le. nfiles))goto 50010
      fstat(i)=0
50011 continue
      i=i+1
      goto 50009
50010 continue
      continue
      i=1
50012 if (.not. (i .lt. nfiles))goto 50013
      continue
      j=i+1
50015 if (.not. (j .le. nfiles))goto 50016
      if (.not. (equal(fname(1,i),fname(1,j)) .eq. 1)) goto 50018
      callputlin(fname(1,i),6)
      callerror(22H: duplicate file name.)
50018 continue
50017 continue
      j=j+1
      goto 50015
50016 continue
50014 continue
      i=i+1
      goto 50012
50013 continue
      return
      end

この程度になると、読む気が起きません。印刷して鉛筆でジャンプ先に印をつける必要があるようです。

コメント

_ Can you lose weight by doing yoga? ― 2017年08月31日 20:28

Have you ever considered creating an ebook or guest authoring on other websites?
I have a blog centered on the same subjects you discuss and would really like to have you share some stories/information. I know my viewers would value your work.
If you are even remotely interested, feel free to send me
an e-mail.

_ shoe lifts ― 2018年01月06日 16:39

Very nice post. I just stumbled upon your blog and wished to say that I&#39;ve
truly enjoyed surfing around your blog posts.
After all I&#39;ll be subscribing to your feed and I hope you
write again very soon!

_ chocolate ― 2018年04月30日 14:47

There is definately a great deal to find out about this subject.
I love all the points you made.

コメントをどうぞ

※メールアドレスとURLの入力は必須ではありません。 入力されたメールアドレスは記事に反映されず、ブログの管理者のみが参照できます。

名前:
メールアドレス:
URL:
コメント:

トラックバック

このエントリのトラックバックURL: http://kida.asablo.jp/blog/2017/08/16/8648460/tb