Giter Site home page Giter Site logo

monty's Introduction

monty - Stacks, Queues - LIFO, FIFO πŸ₯ž

monty functions as a Monty byte code interpreter. 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.

SYNOPSIS

monty is a simple byte code interpreter in accordance with Holberton School standards and expectations. This project's purpose was to introduce students to working with the stack which is LIFO (last in first out) and the queue, which is FIFO (first in first out).

INSTALLATION AND USAGE

Please use GCC 4.8.4 compiler or later.

$ git clone [repository link]  
$ gcc -Wall -Werror -Wextra -pedantic *.c -o monty  
$ ./monty file_name.m  

SYNTAX OVERVIEW AND EXAMPLES

Below are some examples of using monty with bytecode files:

vagrant@vagrant-ubuntu-trusty-64:~/0x19-stacks_queues_lifo_fifo$ cat -e bytecodes/00.m  
push 1$  
push 2$  
push 3$  
pall$  
vagrant@vagrant-ubuntu-trusty-64:~/0x19-stacks_queues_lifo_fifo$ ./monty bytecodes/00.m  
3  
2  
1  
vagrant@vagrant-ubuntu-trusty-64:~/0x19-stacks_queues_lifo_fifo$  
vagrant@vagrant-ubuntu-trusty-64:~/0x19-stacks_queues_lifo_fifo$ cat bytecodes/09.m  
push 1  
push 2  
push 3  
pall  
swap  
pall  
vagrant@vagrant-ubuntu-trusty-64:~/0x19-stacks_queues_lifo_fifo$ ./monty bytecodes/09.m  
3  
2  
1  
2  
3  
1  
vagrant@vagrant-ubuntu-trusty-64:~/0x19-stacks_queues_lifo_fifo$  

opcodes

Listed below are the opcodes to can be used in monty:

opcode Function
push Pushes an element to the stack
pall Prints all the values on the stack, starting from the top of the stack
pint prints the value at the top of the stack, followed by a new line
pop Removes 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

File Descriptions

Listed below are the descriptions of the files in this repo:

File Description
helperfuncs.c Includes functions for string manipulation.
main.c Contains parser and main monty interpreter.
free_list.c Contains function to print doubly linked list
monty.c Contains functions for opcodes
monty1.c Contains functions for opcodes
monty.h Contains function prototypes and data structures.

Authors

Faizan Khan ⚑

Christian Williams 🎡

Data Structures and Functions Used

typedef struct stack_s

{
int n;
struct stack_s *prev;
struct stack_s *next;
} stack_t;

typedef struct instruction_s

{
char *opcode;
void (*f)(stack_t **stack, unsigned int line_number);
} instruction_t;

void add(stack_t **stack, unsigned int line_num);
void swap(stack_t **stack, unsigned int line_num);
void pop(stack_t **stack, unsigned int line_num);
stack_t *push(stack_t **stack, unsigned int line_num, int n);
void pall(stack_t **stack, unsigned int line_num);
stack_t *push(stack_t **stack, unsigned int line_num, int n);
void swap(stack_t **stack, unsigned int line_num);
void free_dlistint(dlistint_t *head);
int _strcmp(char *s1, char *s2);


monty's People

Contributors

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