A minimal language interpreter written in C for the Monty programming language, designed to manage stacks and queues (LIFO and FIFO). This project aims to parse and execute Monty bytecode files, providing a hands-on understanding of stack operations and interpreter implementation.
- About Monty Language
- Features
- Repository Structure
- Installation
- Usage
- Supported Opcodes
- Examples
- Contributing
- License
Monty 0.98 is a bytecode scripting language. Like Python, Monty scripts are compiled into Monty bytecodes, which are then executed by the interpreter. Monty programs manipulate a stack (LIFO) or a queue (FIFO) with simple instructions.
Typical use cases include learning about interpreters, stacks, queues, and general low-level programming concepts in C.
- Reads Monty bytecode files and executes commands line by line.
- Supports stack (LIFO) and queue (FIFO) operations.
- Implements fundamental stack/queue operations: push, pop, pall, pint, etc.
- Error handling for invalid opcodes, missing files, and stack underflow.
monty/
├── bytecodes/ # Example Monty bytecode files
├── main.c # Entry point for the interpreter
├── monty.h # Header file with definitions and prototypes
├── stack.c # Stack/queue manipulation logic
├── opcodes.c # Implementation of Monty opcodes
├── utils.c # Utility functions
├── README.md # Project documentation
└── ... # Additional source and header files
Note: Adjust actual file names and structure as needed.
-
Clone the repository:
git clone https://github.com/Bakugo90/monty.git cd monty
-
Compile the interpreter:
gcc -Wall -Werror -Wextra -pedantic *.c -o monty
To execute a Monty bytecode file:
./monty <file.m>
Replace <file.m>
with the path to a valid Monty bytecode file.
Some of the supported instructions include:
push <int>
: Pushes an integer onto the stack.pall
: Prints all values on the stack.pint
: Prints the value at the top of the stack.pop
: Removes the top element.swap
: Swaps the top two elements.add
,sub
,mul
,div
,mod
: Arithmetic operations on the stack.queue
: Switches to queue mode (FIFO).stack
: Switches to stack mode (LIFO).- ...and more.
Example Monty bytecode (bytecodes/001.m
):
push 1
push 2
push 3
pall
Command to run:
./monty bytecodes/001.m
Expected output:
3
2
1
Contributions are welcome! Please fork the repository and submit a pull request for review.
This project is licensed under the MIT License. See the LICENSE file for details.