GnuCOBOLというフリーのコンパイラを使ってLinuxでもCOBOLが使えます。
GnuCOBOLのインストール
aptでインストールします。
$ sudo apt update
$ sudo apt install gnucobol
インストールできたか確認しましょう。
$ cobc --version
cobc (GnuCOBOL) 3.1.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
Built Apr 14 2024 07:59:15
Packaged Dec 23 2020 12:04:58 UTC
C version "13.2.0"
$ which cobc
/usr/bin/cobc
VSCodeの拡張機能を入れる
「COBOL」と検索し、以下の拡張機能を入れるとシンタックスハイライトされたり、カラム位置の縦線が入ったりします。
Hello World
HELLO.cbl
という名前のファイルに以下を記入します(カラム位置に注意)。
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
PROCEDURE DIVISION.
DISPLAY "Hello World!"
STOP RUN.
END PROGRAM HELLO.
コンパイルと連係編集を以下のコマンドで行います。
$ cobc -x ./HELLO.cbl
すると実行可能ファイルHELLO
ができるのでこれを実行します。
$ ./HELLO
Hello World!