2023-01-16

Higher Order Calculator 1993 to 2023

tags: software

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:

Function prototypes

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.

upgrade some variables to 64 Bit

(not) ignoring a return value

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.

TODO

Conclusion

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.

https://git.sr.ht/~ew/ew.hoc/

Cheers,

~ew

[a] Brian W. Kernighan, Rob Pike --- The UNIX Programming Environment, 1984 Prentice Hall, ISBN 0-13-937681-X

Home