majing seal

Michael Marking


Start Here

Bionic Buffalo
Buffalo Bull

  Public Keys
  Social Media
  Web Site

What's New home > software > cats precompiler > history

History of the Cats Pre-Compiler

Cats started with my annoyance at the amount of code required to do certain simple things in C. For instance, in Perl, I could write

$animal =~ s/horse/zebra/g ;

which changes all instances of "horse" to "zebra" in the string $animal. In C, using the PCRE library, about a dozen lines of code are needed to do the same thing. The PCRE setup and calls are routine, but C's macro facility is inadequate to create a string substitution syntax as Perl has. In fact, the arbitrary quotation characters available in Perl are enough, by themselves, to choke the C preprocessor.

I decided to create a preprocessor, which became more complicated and quickly became a pre-compiler, which would recognize some of these constructs, and convert them into C. Then I could write a statement such as

char * animal;
animal =~ s/horse/zebra/g ;

and embed it directly into a program which was otherwise standard C. Then I thought, it would be nice to have a string data type in the language. Some other types were added, and eventually other features were added to the language, which I called "Cats", for "C, and then some".

The task turned out more difficult than first anticipated, because the only way to get it right was to have the pre-compiler understand much of what was going on in a C program. For instance, strings needed to be released when leaving the block in which they were defined, so the Cats pre-compiler had to understand the block structure of a C program, and so on.

By creating standard C, I didn't have to write a real compiler: there are C compilers for almost every platform. Also, I could write in Cats for customers who wanted C, and just give them the C output. Finally, C is, in practice, more or less a high-level assembly language, with portability, so I could do almost anything I could do in assembler, without much loss of efficiency.

Cats reached version 3, but that implementation was never finished. There is a Cats 3 manual.

After adding a lot of features, I'm still not completely satisfied with the language. Now I'm working on version 4, and am tempted to discard backward compatibility. My current list of features to be added includes:

  • clean up the representation of objects, so that the value of a variable might represent, transparently, either a local or a remote object
  • a working eval operator, so that code can be created and executed at run-time; this may be limited to more simple expressions, and disallow complications such as loops and other control structures
  • allow more dynamic definition, such as adding new operators on the fly
  • bring into compliance with the C201x specification

Another idea, which isn't close to the head of the queue and may be rejected completely, is to generate Java instead of C, to accomodate platforms which prefer Java. Ignoring the Cats extensions, it would become a C to Java converter.

Copyright 2018 Michael Marking. All Rights Reserved. last modified Sunday, 29-Jul-2012 21:28:25 GMT
Accessed Friday, 19-Oct-2018 05:51:28 GMT from
Tatanka, Bionic Buffalo, sysjinn, and sysjinni are trademarks of Michael Marking.