https://github.com/mohamed-mostafaaa/monty
Monty 0.98 is a scripting language that is first compiled into Monty byte codes (Just like Python). It relies on a unique stack, with specific instructions to manipulate it. The goal of this project is to create an interpreter for Monty ByteCodes files.
https://github.com/mohamed-mostafaaa/monty
brainfuck bytecode c data-structures monty queue stack
Last synced: 12 months ago
JSON representation
Monty 0.98 is a scripting language that is first compiled into Monty byte codes (Just like Python). It relies on a unique stack, with specific instructions to manipulate it. The goal of this project is to create an interpreter for Monty ByteCodes files.
- Host: GitHub
- URL: https://github.com/mohamed-mostafaaa/monty
- Owner: Mohamed-Mostafaaa
- Created: 2023-11-14T12:06:04.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-17T11:43:40.000Z (over 2 years ago)
- Last Synced: 2025-02-28T20:56:15.116Z (over 1 year ago)
- Topics: brainfuck, bytecode, c, data-structures, monty, queue, stack
- Language: C
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

> monty
# :snake: Monty Interpreter
Welcome to the Monty Bytecode Interpreter. This interpreter was built in the C language and is compliant with `ISO90`, `ISO99`, & `ISO11`. It reads Monty bytecode files of any extension (preferably `.m` although it doesn't matter), and interprets the opcodes contained.
Monty 0.98 is a scripting language that is first compiled into Monty byte codes (Just like Python). It relies on a unique stack, with specific instructions to manipulate it. The goal of this project is to create an interpreter for Monty ByteCodes files.
Our interpreter can be run as either a stack (LIFO) or queue (FIFO). Mode can be switched mid-script. The interpreter can handle a variety of Monty opcodes, including printing, mathematical operations, and more - all handled opcodes are listed below.
## :running: Getting Started
* [Ubuntu 14.04 LTS](http://releases.ubuntu.com/14.04/) - Operating system reqd.
* [GCC 4.8.4](https://gcc.gnu.org/gcc-4.8/) - Compiler used
## :arrow_down: Installing and Using
Clone the repository into a new directory:
```
git clone https://github.com/Mohamed-Mostafaaa/monty.git
```
Compile with the following:
```
gcc -Wall -Werror -Wextra -pedantic *.c -o monty
```
Run the interpreter on a file:
```
./monty file.m
```
## :wrench: Header file [monty.h](./monty.h)
### Data structures
Use the following data structures, dont forget to include them in the header file.
```c
/**
* struct stack_s - doubly linked list representation of a stack (or queue)
* @n: integer
* @prev: points to the previous element of the stack (or queue)
* @next: points to the next element of the stack (or queue)
*
* Description: doubly linked list node structure
* for stack, queues, LIFO, FIFO
*/
typedef struct stack_s
{
int n;
struct stack_s *prev;
struct stack_s *next;
} stack_
```
```c
/**
* struct instruction_s - opcode and its function
* @opcode: the opcode
* @f: function to handle the opcode
*
* Description: opcode and its function
* for stack, queues, LIFO, FIFO
*/
typedef struct instruction_s
{
char *opcode;
void (*f)(stack_t **stack, unsigned int line_number);
} instruction_t;
```
## :wrench: Monty Opcodes
* **push**
* Usage: `push `
* Pushes an element to the stack.
* The parameter `` must be an integer.
* **pall**
* Prints all values in the stack/queue, starting from the top.
* **pint**
* Prints the top value of the stack/queue.
* **pop**
* Removes the top element of the stack/queue.
* **swap**
* Swaps the top two elements of the stack/queue.
* **nop**
* Does not do anything.
* **add**
* Adds the top two elements of the stack/queue.
* The result is stored in the second element from the top and the top element is popped.
* **sub**
* Subtracts the top element of the stack/queue from the second element from the top.
* The result is stored in the second element from the top and the top element is removed.
* **mul**
* Multiplies the top two elements of the stack/queue.
* The result is stored in the second element from the top and the top element is removed.
* **div**
* Divides the second element from the top of the stack/queue by the top element.
* The result is stored in the second element from the top and the top element is removed.
* **mod**
* Computes the modulus of the second element from the top of the stack/queue divided by the top element.
* The result is stored in the second element from the top and the top element is removed.
* **pchar**
* Prints the character value of the top element of the stack/queue.
* The integer at the top is treated as an ASCII value.
* **pstr**
* Prints the string contained in the stack/queue.
* Prints characters element by element until the stack/queue is empty, a value is `0`, or an error occurs.
* **rotl**
* Rotates the top element of the stack/queue to the bottom.
* **rotr**
* Rotates the bottom element of the stack/queue to the top.
* **stack**
* Switches a queue to stack mode.
* **queue**
* Switches a stack to queue mode.
:arrow_forward: Opcodes preceeded by a `#` are treated as comments and the corresponding line is ignored.
:arrow_forward: Lines can be empty and can contain any number of spaces before or after an opcode and its argument (only the first opcode and/or argument is taken into account).
## :blue_book: Authors
* **Mohamed Mostafa** - [@Mohamed-Mostafaaa](https://github.com/Mohamed-Mostafaaa)
* **Eman Elkamel** - [@emanelkamel](https://github.com/emanelkamel)