Ratforプリプロセッサー -- コード生成 "do"2017年06月20日 18:06

Ratforのdo文にであったら、doの限界指定部を取り出して、ラベルL、L+1を 作りだし、

          do L 限界指定部
を出力します。そして、doの終わりに達したら、
        L continue
      L+1 continue
を出力します。ここで、ラベルL+1は、breakに出会ったときの行き先になります。また、ラベルLは、 do分のループの終わりを示すとともに、nextに出会った時の行き先になります。 具体的には、docode()でdo文のはじめを生成します。

docode()のRatofor版は以下の通り。

# docode.r4 -- generate code for beginning of do
      include ratfor.def
      subroutine docode(lab)
      integer lab

      integer labgen
      string(dostr,"do")

      call outtab
      call outstr(dostr)
      call outch(BLANK)
      lab = labgen(2)
      call outnum(lab)
      call outch(BLANK)
      call eatup
      call outdon

      return
      end

WATCOM Fortran77版は以下の通り。

c docode.f -- generate code for beginning of do
      include ratfor.def
      subroutine docode(lab)
      integer lab

      integer labgen
      string(dostr,"do")

      call outtab
      call outstr(dostr)
      call outch(BLANK)
      lab = labgen(2)
      call outnum(lab)
      call outch(BLANK)
      call eatup
      call outdon

      return
      end

eatup()は、まだ取り込んでいない部分を継続行を含めて処理します。

eatup()のRatofor版は以下の通り。

# eatup.r4 -- process rest of statement; interpret continuations
      include ratfor.def
      subroutine eatup
      character gtoken
      character ptoken(MAXTOK),t,token(MAXTOK)
      integer nlpar

      nlpar = 0
      repeat `
          t = gtoken(token,MAXTOK)
          if (t == SEMICOL | t == NEWLINE)
              break
          if (t == LBRACE) {
              call pbstr(token)
              break
              }
          if (t == RBRACE | t == EOF) {
              call synerr('unexpected brace or EOF.')
              call pbstr(token)
              break
              }
          if (t == COMMA) {
              if (gtoken(ptoken,MAXTOK) != NEWLINE)
                  call pbstr(ptoken)
              }
          else if (t == LPAREN)
              nlpar = nlpar + 1
          else if (t == RPAREN)
              nlpar = nlpar - 1
          call outstr(token)
          } until (nlpar < 0)
      if (nlpar != 0)
          call synerr('unbalanced parentheses.')
      return
      end

WATCOM Fortran77版は以下の通り。

c eatup.f -- process rest of statement; interpret continuations
      include ratfor.def
      subroutine eatup
      integer*1 gtoken
      integer*1 ptoken(MAXTOK),t,token(MAXTOK)
      integer nlpar

      nlpar = 0
      loop
          t = gtoken(token,MAXTOK)
          if ((t .eq. SEMICOL) .or. (t .eq. NEWLINE)) then
              exit
          end if
          if (t .eq. LBRACE) then
              call pbstr(token)
              exit
          end if
          if ((t .eq. RBRACE) .or. (t .eq. EOF)) then
              call synerr('unexpected brace or EOF.')
              call pbstr(token)
              exit
          end if
          if (t .eq. COMMA) then
              if (gtoken(ptoken,MAXTOK) .ne. NEWLINE) then
                  call pbstr(ptoken)
              end if  
          else if (t .eq. LPAREN) then
              nlpar = nlpar + 1
          else if (t .eq. RPAREN) then
              nlpar = nlpar - 1
          end if
          call outstr(token)
      until (nlpar .lt. 0)
      if (nlpar .ne. 0) then
          call synerr('unbalanced parentheses.')
      end if
      return
      end

doの終わりのコードは、dostat()で生成します。

dostat()のRatofor版は以下の通り。

# dostat.r4 -- generate code for end of do statement
      subroutine dostat(lab)
      integer lab

      call outcon(lab)
      call outcon(lab+1)
      return
      end

WATCOM Fortran77版は以下の通り。

c dostat.f -- generate code for end of do statement
      subroutine dostat(lab)
      integer lab

      call outcon(lab)
      call outcon(lab+1)
      return
      end

コメント

_ tangibleaborigi2.snack.ws ― 2017年07月30日 10:56

I am regular visitor, how are you everybody? This article posted at this site
is actually nice.

コメントをどうぞ

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

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

トラックバック

このエントリのトラックバックURL: http://kida.asablo.jp/blog/2017/06/20/8601152/tb