Giter Site home page Giter Site logo

monty's Introduction

Monty

Welcome

Thanks for visiting our project, Monty. It is entirely written in C and any reference to Python is purely accidental. Monty is a simple calculator implementing Addition, Subtraction, Multiplication, Division, and Modulo operations with simple bytecodes in a *.m file. This use of a stack (with limited features of a queue) is a basic Reverse Polish Notation calculator.

The code uses only one global variable (extern) and is highly modular. Expansion of this calculator to include more bytecode instructions or scientific functions would be fairly easy.

Table of Contents

Requirements

  • Ubuntu 14.04 LTS
  • gcc 4.8.4 (-Wall, -Werror, -Wextra, and -pedantic flags)

Installation

In your terminal, git clone the directory with the following command:

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

Compile the files using:

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

If you as a developer would like to fork our current project and create your own domain-specific monty, please give us a shout-out.

Usage

./monty [./myFile.m]

where [./myFile.m] contains the direct path to the file containing the Monty bytecode instructions. Each file lists one instruction per line maximum. Each line is read individually and evaluated. The file can contain blank lines (empty or made of spaces only. Any additional text after the opcode or its required argument is not taken into account. If there are comments, denoted by a "#" is ignored as well.

If the Monty file contains an error, where the program cannot run or process it, the program will print an error message and exit with EXIT_FAILURE.

To start Monty at your shell prompt, type:

./monty [myFile.m]

An example [myFile.m] Monty file:

push 1
push 2
  push 3
                   pall
add
pall
push 110
push 111
push 116
push 114
push 101
push 98
push 108
push 111
push 72
pstr

Bytecode Instructions

The commands that you can use with Monty

Category Instruction Description
Enter Data push (operand) Push operand onto stack/queue
pop Remove top element off stack
Change Data swap Swap the top two elements of the stack
rotl Rotate the top element to the bottom
rotr Rotate the bottom element to the top
stack Change to stack mode
queue Change to queue mode
Operations add Add top two operands
div Divide top two operands
mod Modulo top two operands
mul Multiply top two operands
sub Subtract top two operands
nop No operation (misnomer)
# Comment (Not an operation)
Output pall print all elements
pint print integer
pchar print element as a character
pstr print elements as a string

We do check for division by zero in the div and mod functions

Credits

Monty is owned and maintained by Kiren Srinivasan (@srinitude) and Felicia Hsieh (@feliciahsiehsw). You can reply to us and to @holbertonschool on Twitter for more updates on this project and our forked projects.

License

Monty is released under the MIT license. See LICENSE for details.

monty's People

Contributors

srinitude avatar feliciahsieh avatar

Watchers

James Cloos avatar  avatar

Forkers

winlesh

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.