Giter Site home page Giter Site logo

monty's Introduction

C - Stacks, Queues - LIFO, FIFO Interpretation by Monty Language

The Monty Language

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. In this project, I learnt how to create an interpreter for Monty ByteCode files.

Getting Started

  • Ubuntu 20.04 LTS - Operating system required.

  • GCC 9.4.0 - Compiler used

What’s Required

  • Ubuntu Terminal or any other VM Sandbox

Installation and Usage

Clone the repository into a new directory:

$ git clone https://github.com/felixayot/monty.git

Compile with the following:

$ gcc -Wall -Werror -Wextra -pedantic -std=c89 *.c -o monty

Run the interpreter on a file:

./monty file.m

Monty Opcodes

  • push

Usage: push <int>

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.

    Opcodes preceded by a # are treated as comments and the corresponding line is ignored.

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

Examples

You can try out your own additional examples by creating a Monty file with the file extension .m and running the Monty interpreter as per the usage stated above. See below for guidance.

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:

	$ cat monty_bytecode.m
	push 1
	pint
	push 2
	pint
	push 3
	pint
	$ ./monty monty_bytecode.m
	1
	2
	3

Authors

Acknowledgments

  • ALX SE program provided the resources and project guidance. More information on this amazing program can be found through this link.

monty's People

Contributors

felixayot avatar

Stargazers

 avatar

Watchers

 avatar

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.