Skip to content

MA-Abahmane/monty

Repository files navigation

Monty byte codes interpretor

Topics: C - Stacks, Queues - LIFO, FIFO

The Monty language

About

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.

Monty byte code files

Files containing Monty byte codes usually have the .m extension. Most of the industry uses this standard but it is not required by the specification of the language. There is not more than one instruction per line. There can be any number of spaces before or after the opcode and its argument.

BrainFuck

Brainfuck is an esoteric programming language created in 1993 by Urban Müller.

Documentation

Monty: Compilation and usage

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

  • One operator per line
  • spaces, tabs and newlines are ignored
  • '#' sign represent comments and the line will be ignored
  • Helper functions

  • cmd_executer: Handle line and execute given monty instruction
  • add_node: Add a node to the stack.
  • add_node_end: Add a node at the end of the stack
  • free_stack: Free memory allocated to the stack nodes
  • stack_len: Return the stack length
  • is_number: Check if a string is a number
  • Instructions

  • push: Push an element to the stack
  • pall: Print all the elements of the stack
  • pint: Print the last pushed element of the stack
  • pop: Remove the top element of the stack
  • swap: Swaps the top two elements of the stack
  • add: Adds the top two elements of the stack
  • nop: Doesn’t do anything
  • sub: Subtracts the top element of the stack from the second top element of the stack
  • div: Divides the second top element of the stack by the top element of the stack
  • mul: Multiplies the second top element of the stack with the top element of the stack
  • mod: Computes the rest of the division of the second top element of the stack by the top element of the stack
  • pchar: Prints the char at the top of the stack, followed by a new line
  • pstr: Prints the string starting at the top of the stack, followed by a new line
  • rotl: Rotates the stack to the top
  • rotr: Rotates the stack to the bottom
  • stack: Sets the format of the data to a stack (LIFO). This is the default behavior of the program
  • queue: Sets the format of the data to a queue (FIFO)
  • Additional tasks: BrainFuck

  • 1000-school.bf: Print school. `bf 1000-school.bf`
  • 1001-add.bf: Add two digits given by the user. `bf 1000-school.bf`
  • About

    C - Stacks, Queues - LIFO, FIFO

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published

    Languages