Acme-Cow-Interpreter

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


# ABSTRACT

This module implements an interpreter for the Cow programming language.

# DESCRIPTION

This module implements an interpreter for the Cow programming language. The
Cow programming language is a so-called esoteric programming language, with
only 12 commands.

# METHODS

- new()

    Return a new Cow interpreter.

- init()

    Initialize an object instance. Clears the memory and register and sets the
    memory pointer to zero. Also, the internally stored program source is
    cleared.

- copy()

    Copy (clone) an Acme::Cow::Interpreter object.

- parse\_string( STRING )

    Parses the given string and stores the resulting list of codes in the
    object.  The return value is the object itself.

- parse\_file( FILENAME )

    Parses the contents of the given file and stores the resulting list of codes
    in the object. The return value is the object itself.

- dump\_mem()

    Returns a nicely formatted string showing the current memory state.

- dump\_obj()

    Returns a text version of object structure.

- execute()

    Executes the source code. The return value is the object itself.

# NOTES

## The Cow Language

The Cow language has 12 instruction. The commands and their corresponding
code numbers are:

- moo (0)

    This command is connected to the **MOO** command. When encountered during
    normal execution, it searches the program code in reverse looking for a
    matching **MOO** command and begins executing again starting from the found
    **MOO** command. When searching, it skips the command that is immediately
    before it (see **MOO**).

- mOo (1)

    Moves current memory position back one block.

- moO (2)

    Moves current memory position forward one block.

- mOO (3)

    Execute value in current memory block as if it were an instruction. The
    command executed is based on the instruction code value (for example, if the
    current memory block contains a 2, then the **moO** command is executed). An
    invalid command exits the running program. Value 3 is invalid as it would
    cause an infinite loop.

- Moo (4)

    If current memory block has a 0 in it, read a single ASCII character from
    the standard input and store it in the current memory block. If the current
    memory block is not 0, then print the ASCII character that corresponds to
    the value in the current memory block to the standard output.

- MOo (5)

    Decrement current memory block value by 1.

- MoO (6)

    Increment current memory block value by 1.

- MOO (7)

    If current memory block value is 0, skip next command and resume execution
    after the next matching **moo** command. If current memory block value is not
    0, then continue with next command. Note that the fact that it skips the
    command immediately following it has interesting ramifications for where the
    matching **moo** command really is. For example, the following will match the
    second and not the first **moo**: **OOO** **MOO** **moo** **moo**

- OOO (8)

    Set current memory block value to 0.

- MMM (9)

    If no current value in register, copy current memory block value. If there
    is a value in the register, then paste that value into the current memory
    block and clear the register.

- OOM (10)

    Print value of current memory block to the standard output as an integer.

- oom (11)

    Read an integer from the standard input and put it into the current memory



( run in 0.532 second using v1.01-cache-2.11-cpan-98e64b0badf )