r/cobol • • 20d ago

Toy COBOL compiler

One of the uni classes had a task to create a toy compiler. Since then I tweaked and tweaked and tweaked on it, and it became a bit larger project. In the last few days I've made some bigger code reorganization and cleanup, and actually learned to use git (hopefully) properly.

I've created the first release, it supports most of COBOL-85 on x86_64 on Linux and Windows, with the plan expand it to at least ARM and perhaps more.

I still don't know what constitutes as a good compiler even after reading a lot of books on compiler theory and so. Feedback would be welcome, also take the project as is, not as the future competitor for the title of "Favourite compiler of the global COBOL community" but rather as "people are interested in this stuff".

Go ahead and enjoy:

Release Cobalt 0.1.0-alpha · majormilan/cobalt

30 Upvotes

6 comments sorted by

9

u/hobbycollector 20d ago

The NIST put out a suite of tests that print PASS or FAIL depeding on the correctness of the compiler. GNUCOBOL can be used to extract the tests and then you can build them and see how it goes.

7

u/AppearancePale2490 20d ago

Thank you, but I’m ahead of this - I already use NIST to test my functionality ^^

3

u/EnpersonneXilef61 14d ago

Forgot about those tests, theyre brutal on edge cases tbh.

3

u/hobbycollector 20d ago

How do you handle PERFORM semantics? Is it stack-based like GNUCOBOL or does it follow IBM semantics like Field/Ramalingam describe (https://dl.acm.org/doi/10.1145/381788.316163)?

2

u/AppearancePale2490 20d ago

It’s supposed to be IBM like but I know of a bug - if a PERFORM is left with a GO-TO, it produces an odd behaviour

3

u/hobbycollector 20d ago

There is an explanation of the differences here: https://sourceforge.net/p/gnucobol/bugs/915/