Ratforプリプロセッサー -- RatforからFortranへの変換2017年04月29日 09:51

ここまで、Ratforで書かれたプログラムを手作業でWATCOM Fortran 77でコンパイル できるよう修正してきた。これから、RatforのコードからFortran IVのレベルのコードに変換する プリプロセッサーを紹介する。

これまでに作成したツールとプリプロセッサーを使って、 Ratforで書かれたプログラムを実行可能なプログラムにする手順は、 以下のようになる。

          ,--------------,
          |    Ratfor    |
          | 原プログラム |
          '--------------'
                 |
                 V           .------------.
             [include]<------| Ratfor.def |
                 |           '------------'
                 V
              [macro]
                 |
                 V
              [ratfor]
                 |
                 V
          [Watcom Fortran77]
                 |
                 V
           .------------.
           | 実行可能な |
           { プログラム |
           '------------'

ところで、Ratfor言語の定義をBNFで記述すると以下のようになる。

          プログラム : 文
                     | プログラム 文
          文         : if ( 条件 ) 文
                     | if ( 条件 ) 文 else 文
                     | while ( 条件 ) 文
                     | for ( 初期設定; 条件; 再設定 ) 文
                     | repeat 文
                     | repeat 文 until ( 条件 )
                     | do 限界指定部 文
                     | 数字の列 文
                     | break
                     | next
                     | { プログラム }
                     | その他

Ratfor言語は、10種類程度の文からなっており、"その他"とはRatforが知らない文でFortranの 文が該当する。Ratforは、"if"や"while" などの制御構造を持った文をFortranの"if","go to","continue"などを 使って、制御構造を作りだすのである。

文の変換規則(コード変換規則)は、以下のようになる。

"if" 文

          if ( 条件 ) 文
は、
          if (.not. ( 条件 )) goto L
             文
        L continue

"if--else" 文

          if ( 条件 ) 文1 else 文2
は、
          if (.not. ( 条件 )) goto L
             文1
          go to L1
        L continue
             文2
       L1 continue

"while" 文

          while ( 条件 ) 文
は、
          continue
        L if (.not. ( 条件 )) go to L1
              文
              go to L
       L1 continue

"for" 文

          for ( 初期設定; 条件; 再設定 ) 文
は、
          continue
          初期設定
        L if (.not. ( 条件 )) goto L2
             文
       L1    continue
             再設定
             goto L
       L2    continue

"repeat" 文

          repeat 文
は、
          continue
        L continue
              文
       L1     continue
              go to L
       L2 continue

"repeat-until" 文

          continue
        L continue
             文
       L1    continue
             if (.not. ( 条件 )) go to L
       L2 continue

"do" 文

          do 限界指定部 文
は、
          do L 限界指定部
              文
       L1 continue
        L continue

"break"文は、"while"、"for"、"repeat"、"repeat-until"、"do"のループから抜け出すのに使用できる。 すなわち、ループの次の文に制御が移る。

"next"文は、ループの残りをジャンプして次の繰り返しに制御を移す。 "while"、"repeat-until"、"do"の各ループでは、条件判定部に、 "for"では、再設定に、"repeat"では、ループ本体の先頭に、それぞれ制御が移る。

論理式に使う演算子"<"や"&"等は、変換される。

          Ratforの演算子    Fortranの演算子
          --------------    ---------------
                >                .gt.
                >=               .ge.
                <                .lt.
                <=               .le.
                ==               .eq.
                !=               .ne.
                !                .not.
                &                .and.
                |                .or.

コメント

_ ritabray06.snack.ws ― 2017年05月02日 09:10

For the reason that the admin of this website is
working, no doubt very quickly it will be famous, due to its feature contents.

_ http://giganticvolitio17.hazblog.com/ ― 2017年05月08日 07:29

Because the admin of this web page is working, no question very soon it will be
famous, due to its quality contents.

_ JimmiXzSq ― 2017年05月19日 06:52

_ JimmiXzSq ― 2017年05月21日 19:17

_ JimmiXzSq ― 2017年05月21日 23:11

_ choc ― 2018年05月02日 18:45

Do you mind if I quote a couple of your posts as long as I provide credit and sources back
to your weblog? My blog is in the very same niche as yours and my visitors would genuinely
benefit from some of the information you
provide here. Please let me know if this ok with you.

Many thanks!

コメントをどうぞ

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

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

トラックバック

このエントリのトラックバックURL: http://kida.asablo.jp/blog/2017/04/29/8504780/tb