GnuCOBOL


GnuCOBOL is a free implementation of the COBOL programming language. Originally designed by Keisuke Nishida, lead development was taken up by Roger While. Latest developments are now led by Simon Sobisch, Ron Norman, Edward Hart, Sergey Kashyrin and many others.

History

While working with Rildo Pragana on TinyCOBOL, Keisuke decided to attempt a COBOL compiler suitable for integration with gcc. This soon became the OpenCOBOL project. Keisuke worked as the lead developer until 2005 and version 0.31. Roger then took over as lead and released OpenCOBOL 1.0 on 27 December 2007. Work on the OpenCOBOL 1.1 pre-release continued until February 2009. In May 2012, active development was moved to SourceForge, and the pre-release of February 2009 was marked as a release. In late September 2013, OpenCOBOL was accepted as a GNU Project, renamed to GNU Cobol, and then finally to GnuCOBOL in September 2014. Ron Norman has added a Report Writer module as a branch of GnuCobol 2.0, and Sergey Kashyrin has developed a version that uses C++ intermediates instead of C.
Latest current release is now v3.1 Final, issued 7 July 2020.
Transfer of copyrights to the Free Software Foundation over GnuCOBOL source code was finalized on 17 June 2015.

Philosophy

While striving to keep in line with COBOL Standards up to the current COBOL 2014 specification, and also to include features common in existing compilers, the developers do not claim any level of standards conformance. Even so, the 2.2 Final release passes over 9,688 of the tests included in the NIST COBOL 85 test suite, out of 9,708.
GnuCOBOL translates a COBOL program into a C program. The C program can then be compiled into the actual code used by the computer or into a library where other programs can call it. Under UNIX and similar operating systems the GNU C compiler is used. For Windows, Microsoft’s Visual Studio Express package provides the C compiler. The two step compilation is usually performed by a single command, but an option exists to allow the programmer to stop compilation after the C code has been generated.

Documentation

The opencobol.org site was the official home of the development team from 2002 until 2012, and was the best source of upstream development information. However, all recent developments are now taking place within a SourceForge project space at http://sourceforge.net/projects/open-cobol/ and this project space also hosts the latest GnuCOBOL documentation and information.
The OpenCOBOL Programmer's Guide, by Gary Cutler, was published under the GNU Free Documentation License.
It has been updated to include GnuCOBOL with Report Writer and is listed in the GnuCOBOL documentation overview page with latest versions in the code tree.

Example programs

Historical


000100* HELLO.COB GnuCOBOL example
000200 IDENTIFICATION DIVISION.
000300 PROGRAM-ID. hello.
000400 PROCEDURE DIVISION.
000500 DISPLAY "Hello, world!".
000600 STOP RUN.

Compilation and execution:

$ cobc -x HELLO.COB
$./HELLO
Hello, world!

Modern, free format


id division.
program-id. hello.
procedure division.
display "Hello, world!" end-display
goback.

Compilation and execution:

$ cobc -x -free hello.cob
$./hello
Hello, world!

Shortest

The shortest valid COBOL program, with the relaxed syntax option in GnuCOBOL 2.0, is a blank file. Compilation and execution:

$ cobc -x -frelax-syntax./empty.cob
./empty.cob: 1: Warning: PROGRAM-ID header missing - assumed
$./empty
$

For earlier versions and with relaxed syntax:

display"Hello, world!".

Compilation and execution:

$ cobc -x -frelax-syntax -free hello.cob
hello.cob: 1: Warning: PROGRAM-ID header missing - assumed
hello.cob: 1: Warning: PROCEDURE DIVISION header missing - assumed
$./hello
Hello, world!

Without relaxed syntax and with any version of GnuCOBOL, GNU Cobol or OpenCOBOL. :

program-id.h.procedure division.display "Hello, world!".

Compilation occurs without errors:

$ cobc -x smallest.cob
$./smallest
Hello, world!

Please note that these trivia listings are not to be regarded as good COBOL form; COBOL was designed to be a readable English programming language.

Implementation

The parser and lexical scanner use Bison and Flex. The GPL licensed compiler and LGPL licensed run-time libraries are written in C and use the C ABI for external program linkage.
Build packaging uses the GNU Build System. Standard tests with make check use Autoconf, ANSI85 testsuite run by make test use Perl scripts.
The configure script that sets up the GnuCOBOL compile has options that include: