Skip to content
/ monty Public

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.

Notifications You must be signed in to change notification settings

Bakugo90/monty

Repository files navigation

Monty

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.

Table of Contents


About Monty Language

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.

Features

  • 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.

Repository Structure

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.

Installation

  1. Clone the repository:

    git clone https://github.com/Bakugo90/monty.git
    cd monty
  2. Compile the interpreter:

    gcc -Wall -Werror -Wextra -pedantic *.c -o monty

Usage

To execute a Monty bytecode file:

./monty <file.m>

Replace <file.m> with the path to a valid Monty bytecode file.

Supported Opcodes

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.

Examples

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

Contributing

Contributions are welcome! Please fork the repository and submit a pull request for review.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published