Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A basic read/"eval"/print loop...in COBOL!
*>>SOURCE FORMAT IS FIXED
*> This is an include (or a "copybook" in COBOL parlance)
*> and pretty much won't run without some context.
perform
display ' welcome to'
display ' ~=X WHERE THE FUCK AM I: THE VIDEO GAME X=~'
display ' programmed entirely in'
display ' jesusabdullah''s bedroom.'
display ''
end-perform
18:43 josh@onix /home/josh/dev/hello-cobol
% cobc -x repl.cob
/tmp/cob9345_0.c: In function ‘repl_’:
/tmp/cob9345_0.c:75:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob9345_0.c:76:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob9345_0.c:77:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob9345_0.c:89:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob9345_0.c:216:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
18:44 josh@onix /home/josh/dev/hello-cobol
% ./repl
welcome to
~=X WHERE THE FUCK AM I: THE VIDEO GAME X=~
programmed entirely in
jesusabdullah's bedroom.
(Mash ctrl-c to quit!)
You are in someone's living room. It's way
too early in the morning, and you were also up
way too late last night. You think? It's all
a blur.
Shouldn't you be at work?
?
Sit up
No way, Jose. Your head is pounding like you had
a few too many beers last night. And, I mean,
let's face it, you kinda did.
Anyways, you put your head back down for
"just five more minutes." You know how it goes.
You are in someone's living room. It's way
too early in the morning, and you were also up
way too late last night. You think? It's all
a blur.
Shouldn't you be at work?
?
YES I SHOULD BE AT WORK
No way, Jose. Your head is pounding like you had
a few too many beers last night. And, I mean,
let's face it, you kinda did.
Anyways, you put your head back down for
"just five more minutes." You know how it goes.
You are in someone's living room. It's way
too early in the morning, and you were also up
way too late last night. You think? It's all
a blur.
Shouldn't you be at work?
?
^C
18:44 josh@onix /home/josh/dev/hello-cobol
%
*>>SOURCE FORMAT IS FIXED
*> ***************************************************************
*> Totally sweet repl example, brah, with a few other tweaks
*> thrown in for lulz. Also has some notes on the finer points of
*> COBOL.
*>
*> ***************************************************************
identification division.
program-id. repl.
*> You can actually define your own encodings here, if your computer sucks
*> and doesn't support ascii OR ebcdic (and that would have to be a pretty
*> fucking shitty computer, but whatever!
environment division.
configuration section.
input-output section.
*> file-control.
*> select
*> assign to
*> organization is
*> .
data division.
*> file section.
*> fd .
*> 01 .
working-storage section.
*> You describe your variables using these "pic" representations.
*> You can make other variables refer to substrings of this using
*> the structure-like thing cobol has.
*> This one is 80 characters long.
01 SomeInput pic X(80).
local-storage section.
*> fyi it seems like 80s versions of cobol basically had built-ins
*> isam-based datatypes. In a sense, cobol and files were what people had
*> before and while databases were being invented, and in fact the same
*> people that made cobol also specified a spec for a pioneering
*> database type that was largely superceded by relational models in
*> the 80s.
*>
*> FYI
linkage section.
screen section.
*> You can actually do, like, terminal-based configuration in here.
*> VIEWS HERE LOL ;)
*> ***************************************************************
procedure division.
*> Straight up include of some displays in a perform XD
copy banner.
display '(Mash ctrl-c to quit!)'.
display ''.
*> USE CTRL C TO BREAK OLOLO
perform with test after until 1 equal 0
display 'You are in someone''s living room. It''s way',
display 'too early in the morning, and you were also up',
display 'way too late last night. You think? It''s all',
display 'a blur.'
*> Prompt the user.
display '',
display 'Shouldn''t you be at work?',
display '',
display '?',
accept SomeInput
*> Respond.
*> If you use the --fdebugging-line flag these will print, otherwise
*> they're ignored.
D display '',
D display 'You said:' space SomeInput
display '',
display 'No way, Jose. Your head is pounding like you had',
display 'a few too many beers last night. And, I mean,',
display 'let''s face it, you kinda did. '
display 'Anyways, you put your head back down for '
display '"just five more minutes." You know how it goes.'
display ''
end-perform.
goback.
end program repl.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment