Code Monkey home page Code Monkey logo

monty-1's Introduction

Stacks, Queues - LIFO, FIFO

What is this?

A project for Holberton School, this is an interpreter for Monty bytecodes files. Monty is a scripting language that is first compiled into Monty byte codes. It relies on a unique stack data structure with specific instructions to manipulate it. Monty byte codes usually have the .m extension.

Why?

This project reviewed the concepts of file input/output, linked lists, and stack data structure.

Requirements of project

  • Ubuntu 14.04 LTS
  • all .c files pass Betty style: betty-style.pl and betty-doc.pl
  • maximum of one global variable
  • no more than 5 functions per file
  • prototypes of all functions are included in header file called monty.h
  • all header files are include guarded
  • allowed to use standard library

Compilation

The files are to be compiled this way:

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

How to use

  1. compile files
  2. $ ./monty monty_byte_code_file_name.m

A few Monty bytecode files are supplied in the byecodes directory. For supported opcodes, look below.

Example of usage

$ cat bytecodes/12.m
push 1
push 2
push 3
pall
add
pall
$ ./monty bytecodes/12.m
3
2
1
5
1

Implemented opcodes

  • push

    Usage: push <int> where <int> is an integer

    What it does: pushes an element to the stack.

  • pall

    Usage: pall

    What it does: prints all the values on the stack, starting from the top of the stack.

  • pint

    Usage: pint

    What it does: prints the value at the top of the stack followed by a new line.

  • pop

    Usage: pop

    What it does: removes the top element of the stack.

  • swap

    Usage: swap

    What it does: swaps the top two elements of the stack.

  • add

    Usage: add

    What it does: adds the top two elements of the stack. The answer is stored in the second top element of the stack and the top element is removed so that the top element contains the result and the stack is one element shorter.

  • nop

    Usage: nop

    What it does: nothing.

  • sub

    Usage: sub

    What it does: subtracts the top element of the stack from the second element of the stack. The answer is stored in the second top element of the stack and the top element is removed so that the top element contains the result and the stack is one element shorter.

  • div

    Usage: div

    What it does: divides the second top element of the stack by the first element of the stack. The answer is stored in the second top element of the stack and the top element is removed so that the top element contains the result and the stack is one element shorter.

  • mul

    Usage: mul

    What it does: multiplies the top two elements of the stack. The answer is stored in the second top element of the stack and the top element is removed so that the top element contains the result and the stack is one element shorter.

  • mod

    Usage: mod

    What it does: computes the remainder of the division of the second top element of the stack by the top element of the stack. The answer is stored in the second top element of the stack and the top element is removed so that the top element contains the result and the stack is one element shorter.

  • pchar

    Usage: pchar

    What it does: prints the character at the top of the stack if it is a printable character.

  • pstr

    Usage: pstr

    What it does: prints the string starting at the top of the stack.

  • rotl

    Usage: rotl

    What it does: rotates the stack to the left.

  • rotr

    Usage: rotr

    What it does: rotates the stack to the right.

Challenges

  • breaking down the project into smaller manageable pieces, and then breaking them into even smaller pieces so that I could have functions that each only did one thing
  • trying to make main function have fewer lines
  • memory leaks from not freeing dynamically allocated memory

Features that I did not implement

  • stack and queue opcodes that would set the format of the data to a stack (LIFO) or queue (FIFO).

monty-1's People

Contributors

ad-egg avatar

Watchers

James Cloos 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.