💾 Archived View for ew.srht.site › en › 2023 › 20230116-hoc-revival.gmi captured on 2024-06-19 at 22:52:46. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-06-16)
-=-=-=-=-=-=-
Some time around 1993 I retraced the creation and transformation of the Higher Order Calculator program presented in "The UNIX Programming Environment" by Brian W. Kernighan and Rob Pike. I did explore a number of additional features back then, I did use it daily for quite some time. Eventually I replaced it with emacs/calc. However, these days I was playing with redo and I remembered that using bison/yacc to generate C code from a description of the grammar actually produces two files, y.tab.h and y.tab.c in one call --- a challenge for any build system. But 30 years later, addresses on my machine are 64 bit wide, and gcc has grown rather picky about acceptable code. So I set out to bring this piece of code to newer times.
Just quickly looking at the error messages of gcc did not get me going, so I did the retrace again through the six stages of the program. This slow pace made it actually enjoyable. So this is what I had to change:
The original code is basically lacking almost any function prototypes. While they were long supported when I learned C in 1990 or so, gcc would happily consume the code and produce a working executable --- in this particular case, that is.
The function "pop()" found in code.c returns an argument, however, in two places in the code this value is simply ignored, much to the dismay of gcc. So I created a variant of this function named "drop()", which will move the pointer on the stack, but will refrain from returning the value of the top location.
I was a nice side project. I might fix the above short comings. I added a number of tests and a simple Makefile. The code is available for your enjoyment and wonder.
Cheers,
~ew
[a] Brian W. Kernighan, Rob Pike --- The UNIX Programming Environment, 1984 Prentice Hall, ISBN 0-13-937681-X