Reading List

The Selfish Gene
The Psychopath Test: A Journey Through the Madness Industry
Bad Science
The Feynman Lectures on Physics
The Theory of Everything: The Origin and Fate of the Universe


ifknot's favorite books »

Saturday, 24 October 2026

C SNOBOL do SNOBOL

Two 80-column punched cards forming a SNOBOL4 program that prints C SNOBOL DO SNOBOL

†

I've wanted to do this since 1988!

SNO is a small C99 library that brings the pattern matching of SNOBOL4 to C, as described in The SNOBOL4 Programming Language, 2nd edition, by R. E. Griswold, J. F. Poage and I. P. Polonsky (Prentice-Hall, 1971), better known as "The Green Book". The code is on GitHub [link to repo], and this post is the story of how it came to be the shape it is.

Where it started

I used SNOBOL at university and, quirks and all, parsing files with it was a breeze. However, and at the time, I loved C and wanted a C version of SNOBOL but the task was clearly a daunting one and so I carried on hand coding my parsing needs ad-hoc. (I still do love C btw warts and all!)

After decades of ad-hoc, but still SNOBOL inspired, C parsing using some ersatz and ultimately unsatisfying snobol-esque functions - the time has come to do the job "properly".

So the naive idea was: take the Green Book, work through it chapter by chapter, and turn each SNOBOL4 function into a C function. LEN becomes sno_len, ANY becomes sno_any, job done.

It was not job done. Almost every chapter turned up a place where SNOBOL and C disagree about something fundamental - what a string is, what failure is, what an error is, even what a column is. This post is about those clashes and how each one was resolved - the resolutions became the library.