GnuCOBOLというフリーのコンパイラが使えます。
インストール
Homebrewを使います。
$ brew install gnucobol
インストール後バージョンを確認します。
$ cobc --version
cobc (GnuCOBOL) 3.2.0
Copyright (C) 2023 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 Jul 28 2023 18:42:18
Packaged Jul 28 2023 17:02:56 UTC
C version "Apple LLVM 15.0.0 (clang-1500.0.40.1)"
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!