Online Cat Interpreter (v 1.3)

Welcome to the JavaScript implementation of the Cat programming language by Christopher Diggins, with contributions from Takashi Yamamiya, and the excellent open-source JavaScript vector graphics library from Walter Zorn. This interpreter only supports a very small subset of the Cat language. Drawing code is known to not work properly on Opera version 5 or 6.

Cat is a postfix language, this means that arithmetic operations are written so that operators follow their operands. For example, where you might normally write: (1 + 2) * 3, in Cat you would write: 1 2 + 3 *. Every time you write a value in Cat it is stored in a data-structure in memory, called the stack. Any data required by instructions are taken from the top of the stack and any data returned from instructions is returned on the stack.

You can also define new instructions in Cat using the following format:

    define add_one { 1 + }
    define times_two { 2 * }
    define square { dup * }
    define swapd { [swap] dip }
    define bury { swap swapd }
    define circle { "green" set_color 100 100 50 50 fill_ellipse }

The best way to learn Cat is to experiment, so have fun! If you are interested in the JavaScript implementation Cat it is public domain (this means acknowledgements would be appreciated but are not required), so feel free to view the source code of this page and reuse whatever you want.

Input
Stack
Output
Instructions
back to the Cat Programming Language home page
copyright Christopher Diggins, 2008