Monty is a simple interpreter for a subset of the Monty Bytecode file format. It reads Monty bytecode files (extension .m) and interprets the opcodes contained within them. Monty operates on a stack and allows various operations such as pushing elements onto the stack, popping elements from the stack, performing arithmetic operations, and more.
- Interpretation of Monty Bytecode files.
- Stack-based operations such as push, pop, swap, and more.
- Error handling for various scenarios such as unknown opcodes or empty stacks.
- C compiler (e.g., GCC)
- Compile the Monty interpreter using a C compiler.
gcc -Wall -Werror -Wextra -pedantic *.c -o monty
- Run the interpreter, specifying the Monty bytecode file to interpret.
./monty file.m
- The interpreter will execute the opcodes defined in the Monty bytecode file and display any output or errors encountered during execution.
- Each line in the Monty bytecode file represents a single operation.
- The first word on each line is the opcode, followed by any necessary arguments.
- Comments can be included using the
#
symbol at the beginning of a line.
- If an unknown opcode is encountered, the interpreter will display an error message and exit.
- If an operation requires elements on the stack but the stack is empty, the interpreter will display an error message and exit.
push 1
push 2
push 3
pall
This bytecode file will push the numbers 1, 2, and 3 onto the stack and then print all elements on the stack.
- The interpreter currently does not support all opcodes specified in the Monty Bytecode documentation. It only supports a subset of operations.
- Error messages may not always provide detailed information about the cause of the error.