Welcome to the Monty project! This repository contains a simple bytecode interpreter for Monty ByteCodes files. Monty 0.98 is a scripting language that is first compiled into byte codes (just like Python). It relies on a specific stack-based virtual machine.
This project implements a bytecode interpreter for Monty ByteCodes files. The interpreter reads bytecode files and executes the corresponding commands. It supports various stack operations and allows for extending functionality by adding more bytecode instructions.
๐ข Task: Implement the push
and pall
opcodes.
-
push: Pushes an element to the stack.
- Usage:
push <int>
- If
<int>
is not provided or not an integer, print an error message and exit with statusEXIT_FAILURE
.
- Usage:
-
pall: Prints all the values on the stack from the top.
- Usage:
pall
- Usage:
- Usage:
pint
- If the stack is empty, print an error message and exit with status
EXIT_FAILURE
.
- Usage:
pop
- If the stack is empty, print an error message and exit with status
EXIT_FAILURE
.
- Usage:
swap
- If the stack contains less than two elements, print an error message and exit with status
EXIT_FAILURE
.
- Usage:
add
- If the stack contains less than two elements, print an error message and exit with status
EXIT_FAILURE
.
- Usage:
nop
โ Task: Implement the sub
opcode to subtract the top element of the stack from the second top element.
- Usage:
sub
- If the stack contains less than two elements, print an error message and exit with status
EXIT_FAILURE
.
โ Task: Implement the div
opcode to divide the second top element of the stack by the top element.
- Usage:
div
- If the stack contains less than two elements, print an error message and exit with status
EXIT_FAILURE
. - If the top element is 0, print an error message and exit with status
EXIT_FAILURE
.
โ๏ธ Task: Implement the mul
opcode to multiply the second top element of the stack with the top element.
- Usage:
mul
- If the stack contains less than two elements, print an error message and exit with status
EXIT_FAILURE
.
๐ข Task: Implement the mod
opcode to compute the remainder of the division of the second top element by the top element.
- Usage:
mod
- If the stack contains less than two elements, print an error message and exit with status
EXIT_FAILURE
. - If the top element is 0, print an error message and exit with status
EXIT_FAILURE
.
๐ฌ Task: Handle comments in the bytecode files. Lines starting with #
should be treated as comments.
- Usage:
pchar
- If the value is not in the ASCII table, print an error message and exit with status
EXIT_FAILURE
. - If the stack is empty, print an error message and exit with status
EXIT_FAILURE
.
- Usage:
pstr
- The string stops when the stack is over, the value of the element is 0, or the value is not in the ASCII table.
- Usage:
rotl
- Usage:
rotr
- Usage:
stack
to switch to stack mode - Usage:
queue
to switch to queue mode
๐ง Task: Write a Brainf*ck interpreter.
โ Task: Write a Brainf*ck script that adds two digits given by the user.
โ๏ธ Task: Write a Brainf*ck script that multiplies two digits given by the user.
โ๏ธ Task: Write a Brainf*ck script that multiplies two digits given by the user and prints the result followed by a new line.
-
Clone the repository:
git clone https://github.com/Linf0rd/monty.git
cd monty
-
Compile the interpreter:
gcc -Wall -Werror -Wextra -pedantic *.c -o monty
-
Run the interpreter:
./monty <file.m>
-
GCC: Ensure you have the GCC compiler installed. You can install it using:
sudo apt update
sudo apt install build-essential
๐จโ๐ป Linf0rd