Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to write a compiler in COBOL?

This blog post https://stackoverflow.blog/2020/04/20/brush-up-your-cobol-why-is-a-60-year-old-language-suddenly-in-demand/?cb=1 says

"You can’t write a compiler or a kernel module in COBOL"

I'm not a fan of COBOL and I'm not suggesting it would be a good idea but as COBOL is turing-complete then my understanding is that you should be able to write in it any program that any other turing-complete language can write. Which means it should in theory be possible to write a compiler in COBOL, no?

Perhaps the author is just short-cutting saying it's not usual or a good idea to write a compiler in COBOL but it got me wondering.

like image 248
Caltor Avatar asked Apr 21 '20 13:04

Caltor


People also ask

How do you compile in COBOL?

COBOL compile procedure. An example shows a single-step procedure for compiling a source program. The JCL in Figure 1 executes the IGYWC procedure, which is a single-step procedure for compiling a source program. It produces an object deck that will be stored in the SYSLIN data set, as we can see in Figure 2.

What happens when you compile a COBOL program?

In the compilation step, the modified source is compiled and the object module is generated. The compilation is done using the utility IGYCRCTL. The object module is then passed to the link editing step, where object module is link edited and executable load module is generated using IEWL utility.

How do I compile and run a COBOL program in mainframe?

To run your COBOL program in TSO, compile and link-edit the program, and then run it in either with or without ISPF. You must compile and link-edit your COBOL program before you can run it in TSO. After your COBOL program compiles successfully, you can run it with JCL without ISPF.


2 Answers

Micro Focus was founded in 1976. Their first COBOL compiler was bootstrapped using SNOBOL until they had a COBOL compiler written in COBOL. Even the utilities were written in and compiled with COBOL. Later they began incorporating C and C++, but for a while everything was COBOL. [I used Micro Focus COBOL on PCs beginning in 1984.]

In the simplest terms, a standard COBOL program can be written to read and write files one byte-at-a-time. What happens in the PROCEDURE DIVISION determines what type of program it is: editor, compiler, linker, etc.

like image 200
Rick Smith Avatar answered Sep 27 '22 23:09

Rick Smith


What didn't get answered is whether you could write an (OS) kernal in COBOL.

The answer is (drumroll...)

Sure, in exactly the same sense you can write an OS kernal in C. See my Quora article on what it takes to do this: Is it possible to write an operating system kernel without using an assembly language? (No, I'm not going to copy that entire answer here).

You'd probably be considered crazy if you did.

like image 29
Ira Baxter Avatar answered Sep 27 '22 22:09

Ira Baxter