A friend made a joking reference to COBOL yesterday, which reminded me of the time I tried to write a COBOL interpreter. In college, I took a one-credit class in 80286 assembly language and for my course project I decided I’d implement a Tiny COBOL, which sounded like a great oxymoron in and of itself. Also, I was a big fan of Grace Murray Hopper (shown above). But I really picked Tiny COBOL instead of Tiny BASIC so I wouldn’t have to implement parentheses and order of operations in assembler (e.g., evaluating expressions like 5+(6-X)*7). Turns out I had underestimated how difficult even a Tiny COBOL was, and all I ended up implementing was a command-line-only interpreter.

Here was the language I supported:

ADD term TO var
SUBTRACT term FROM var
MULTIPLY term BY var
DIVIDE term BY var
WRITE term

A term was either a variable or a signed integer (-32768 to 32767). In fact, my lasting memory of the course is that I spent most of the time in the lab working out how to display signed integers in decimal and implementing WRITE took most of my time.

The only variables were A through Z (one-letter names), with a default value of zero. To initialize a value to something else, you had to use ADD:

ADD 7 TO A

Note that COBOL gives you lots of other ways to use these math commands. I went for simplicity and ease of parsing.

Speaking of parsing, the parser wasn’t very smart, so all you needed to do was to match the first letter of the keyword, while the prepositions (TO, FROM, BY) were interchangeable and didn’t have to match the command (e.g., ADD – TO, SUBTRACT –  FROM, DIVIDE – BY).

So…

ADAM 7 BATMAN ROBIN

…would get interpreted as ADD 7 BY R.

Hey, it was a 1-credit course.