GithubHelp home page GithubHelp logo

monty's Introduction

Monty (0x19. C - Stacks, Queues - LIFO, FIFO) ๐Ÿฐ

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.

Table of Contents

Description

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.

Tasks

0. push, pall

๐Ÿ”ข 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 status EXIT_FAILURE.
  • pall: Prints all the values on the stack from the top.

    • Usage: pall

1. pint

๐Ÿ“œ Task: Implement the pint opcode to print the value at the top of the stack.

  • Usage: pint
  • If the stack is empty, print an error message and exit with status EXIT_FAILURE.

2. pop

๐Ÿ”„ Task: Implement the pop opcode to remove the top element of the stack.

  • Usage: pop
  • If the stack is empty, print an error message and exit with status EXIT_FAILURE.

3. swap

๐Ÿ”„ Task: Implement the swap opcode to swap the top two elements of the stack.

  • Usage: swap
  • If the stack contains less than two elements, print an error message and exit with status EXIT_FAILURE.

4. add

โž• Task: Implement the add opcode to add the top two elements of the stack.

  • Usage: add
  • If the stack contains less than two elements, print an error message and exit with status EXIT_FAILURE.

5. nop

๐Ÿšซ Task: Implement the nop opcode that does nothing.

  • Usage: nop

6. sub

โž– 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.

7. div

โž— 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.

8. mul

โœ–๏ธ 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.

9. mod

๐Ÿ”ข 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.

10. comments

๐Ÿ’ฌ Task: Handle comments in the bytecode files. Lines starting with # should be treated as comments.

11. pchar

๐Ÿ”ค Task: Implement the pchar opcode to print the char at the top of the stack.

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

12. pstr

๐Ÿ”ค Task: Implement the pstr opcode to print the string starting at the top of the stack.

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

13. rotl

๐Ÿ”„ Task: Implement the rotl opcode to rotate the stack to the top.

  • Usage: rotl

14. rotr

๐Ÿ”„ Task: Implement the rotr opcode to rotate the stack to the bottom.

  • Usage: rotr

15. stack, queue

๐Ÿ”„ Task: Implement the stack and queue opcodes to switch the mode of the data structure.

  • Usage: stack to switch to stack mode
  • Usage: queue to switch to queue mode

16. Brainf*ck

๐Ÿง  Task: Write a Brainf*ck interpreter.

17. Add two digits

โž• Task: Write a Brainf*ck script that adds two digits given by the user.

18. Multiplication

โœ–๏ธ Task: Write a Brainf*ck script that multiplies two digits given by the user.

19. Multiplication level up

โœ–๏ธ Task: Write a Brainf*ck script that multiplies two digits given by the user and prints the result followed by a new line.

How to Run

  1. Clone the repository:

    git clone https://github.com/Linf0rd/monty.git

    cd monty

  2. Compile the interpreter:

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

  3. Run the interpreter:

    ./monty <file.m>

Dependencies

  • GCC: Ensure you have the GCC compiler installed. You can install it using:

    sudo apt update

    sudo apt install build-essential

Author

๐Ÿ‘จโ€๐Ÿ’ป Linf0rd

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.