Skip to content
/ monty Public

🚀 This project reviewed the concepts of LIFO and FIFO methods, stacks, queues, linked lists, and global variables in C programming.

Notifications You must be signed in to change notification settings

tatsOre/monty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stacks, Queues - LIFO, FIFO

The goal of this project is to create an interpreter for Monty ByteCodes files. 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.

Objectives:

This project reviewed the concepts of LIFO and FIFO methods, stacks, queues, linked lists, and global variables in C programming.

Monty byte code files examples:

Files containing Monty byte codes usually have the .m extension.

::~/monty $

push 0$
push 1$
push 2$
  push 3$
                   pall    $
push 4$
    push 5    $
      push    6        $
pall$

Monty byte code files can contain blank lines (empty or made of spaces only, and any additional text after the opcode or its required argument is not taken into account:

::~/monty $

push 0 Push 0 onto the stack$
push 1 Push 1 onto the stack$
$
push 2$
  push 3$
                   pall    $
$
$
                           $
push 4$
$
    push 5    $
      push    6        $
$
pall This is the end of our program. Monty is awesome!$

The Monty Program:

Usage: $ monty file. Where file is the path to the file containing Monty byte code.

Opcode What it does:
push <int> Pushes an element to the stack.
pall Prints all the values on the stack, starting from 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.
nop Does nothing.
swap Swaps the top two elements of the stack.
add Adds the top two elements of the stack.
sub Subtracts the top element of the stack from the second top element of the stack.
mul Multiplies the second top element of the stack with the top of stack.
div Divides the second top element of the stack by the top of 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 TOS, followed by a new line.
rotr Rotates the stack to the bottom. The last element of the stack becomes the top element of the stack.
rotl Rotates the stack to the top. The top element of the stack becomes the last one, and the second top element of the stack becomes the first one.
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).

Resources:

Compilation:

Code files must be compiled this way:

$ gcc -Wall -Werror -Wextra -pedantic *.c -o monty
  • Any output must be printed on stdout
  • Any error message must be printed on stderr

Author:

  • Tatiana Orejuela Zapata | Github
Foundations - Low-level programming & Algorithm Data structures and Algorithms
May, 2020. Cali, Colombia.

About

🚀 This project reviewed the concepts of LIFO and FIFO methods, stacks, queues, linked lists, and global variables in C programming.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published