1
0
notes/website/2017-12-05-tigersay.md

3.8 KiB

Tigersay

The dOvs Course

This last semester I've been following my university's course on writing a compiler from scratch. The course uses the classic Modern Compiler Implementation in ML, and thus our input language is something called Tiger, a toy language designed specifically for the book. The joke goes that Tiger is one of the least used programming languages, but one of the most supported. It is also weird. It's like if C and Standard ML had a deformed baby: Mutually inductive data types and functions? Sure! Primitives for both functional and imperative coding styles? Great idea! Type inference for variables, but not for functions. Perfect! A way to determine the size of arrays at runtime? No, absolutely not!

A small piece of Tiger code, demonstrating an implementation of a
linked list.

The reason for these weird idiosyncrasies is obvious: nobody is supposed to write actual programs in Tiger. The features of Tiger are designed to illustrate how to implement them, not necessarily to form a coherent whole.

That said, some of the features work together to allow a strange elegance in the way some programs can be written. Recursive functions and structure types allow one to express linked lists and maps using relatively little code. See the example code above, for an implementation of a linked list, and a function for finding the sum of the list, using a recursive helper function. I could just as easily have implemented it using an imperative style.

While following the course, my group used a testing framework, containing many programs similar in style to the above code sniplet, ensuring our compiler's compliance with the language. These tests were small, and rarely tested more than a few features at once. The question "Is our compiler actually capable of translating a real program?" arose, and this lead me down the road of actually writing a "real" program in Tiger, using its weird feature set.

Tigersay

A badly drawn tiger explains its own existence: "Once upon a time,
there was a programming language named Tiger, and nobody used it. Then
some stupid student made a clone of cowsay, and that is how I was
born"

Tigersay is an implementation of the classic Perl program Cowsay, written in the Tiger programming language, a toy language originating from the Modern Compiler Implementation in ML/C/Java series of books.

It does not come compiled, nor does it come with a Tiger compiler. The only way to experience the wonder that is Tigersay is to use your own Tiger compiler. (Or find one on the internet, but that's cheating.)

The standard version of Tiger is limited in its ability to interact with the command-line, and as a result, so is Tigersay. The only way to interact with Tigersay is to pipe the desired text into Tigersay:

echo "Hello World" | tigersay

Unfortunately this also means Tigersay only supports a single face, the default tiger one, due to having no support for command-line arguments.

Tigersay responds to certain strings in silly ways, the most useful ones being help and version. Additionally it interfaces nicely with [fortune](https://en.wikipedia.org/wiki/Fortune_(Unix)).

The badly drawn tiger exclaim: "I never made a mistake in my life.
I thought I did once, but I was wrong. -- Lucy Van
Pelt"

If you'd like to play around with Tigersay yourself, you can find the source code in the Gitfub repository