LoginSignup
21
16

More than 5 years have passed since last update.

MacにCobolを入れていじってみた話

Posted at

今までの仕事とはぜんぜん違う言語を扱いそうなので、予め勉強してみようの巻。

MacでCobolを使う準備

どうやらopen-cobol(gnu-cobol)というのを使えばいいというのを聞いたので、macで使うにはどうしたらいいか調べてみた。

http://www.opencobol.org/
http://jp.opencobol.org/

するとhomebrewに存在したので、それを使うことにする。

% brew info open-cobol
open-cobol: stable 1.1
http://www.opencobol.org/
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/open-cobol.rb
==> Dependencies
Required: gmp, berkeley-db

インストールは通常通りこんな感じで。

% brew install open-cobol
==> Installing dependencies for open-cobol: gmp, berkeley-db
==> Installing open-cobol dependency: gmp
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/gmp-6.0.0a.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring gmp-6.0.0a.mavericks.bottle.tar.gz
  /usr/local/Cellar/gmp/6.0.0a: 15 files, 3.2M
==> Installing open-cobol dependency: berkeley-db
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/berkeley-db-5.3.28.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring berkeley-db-5.3.28.mavericks.bottle.tar.gz
  /usr/local/Cellar/berkeley-db/5.3.28: 5271 files, 105M
==> Installing open-cobol
==> Downloading https://downloads.sourceforge.net/project/open-cobol/open-cobol/1.1/open-cobol-1.1.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/open-cobol/1.1 --infodir=/usr/local/Cellar/open-cobol/1.1/share/info
==> make install
  /usr/local/Cellar/open-cobol/1.1: 35 files, 1.1M, built in 27 seconds

HelloWorldしてみる

http://dotinstall.com/lessons/basic_cobol
これを参考にやってみた。

       IDENTIFICATION DIVISION.
       PROGRAM-ID. HELLO.
       PROCEDURE DIVISION.
       MAIN SECTION.
           DISPLAY 'HELLO WORLD!!'.
           STOP RUN.

こんな感じのコードを書いてコンパイル。
コマンドはcobcで、実行形式のファイルを作るオプション-xと自由書式を使うオプション--freeを指定する。

% cobc -x --free hello.cob
% ls
hello*     hello.cob

helloが実行ファイルなので、それを実行してみる。

% ./hello
HELLO WORLD!!

でたー。

Cobolの印象

コード内にもPROCEDUREと入っているだけあって、PLSQLなどストアドプロシージャなどと似ている印象。
昔は手書きでコーディングしていたなどと説明あったけど、信じられない。

正直これをかなりの行数を読まないといけないとなると、やや不安。
でも、知らない言語とか学べるのは楽しいでしょう!
がんばろう。

21
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
16