Giter Site home page Giter Site logo

monty's Introduction

0x19. C - Stacks, Queues - LIFO, FIFO

About: In this project, we created a simple interpreter for Monty ByteCodes. The interpreter reads a bytecode file and executes the bytecode commands.

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.

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: examples

Objectives:

  • To know what LIFO and FIFO mean
  • To know what a stack is, and when to use it
  • To know what a queue is, and when to use it
  • To know the common implementations of stacks and queues
  • To know the most common use cases of stacks and queues
  • To know the proper way to use global variables

Resource:

General Requirements

  • Allowed editors: vi, vim, emacs
  • All files is compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -Werror -Wextra -pedantic -std=gnu89
  • All files ends with a new line
  • There is README.md file at the root of the alx-low_level_programming
  • Maximum of one global variable is allowed
  • No more than 5 functions per file
  • The C standard library is allowed
  • The prototypes of all the functions were included in the header file called monty.h
  • All the header files are include guarded

Instruction given:

  • To use the following data structures for this project, and to also include them in the header file.
/**
 * struct stack_s - doubly linked list representation of a stack (or queue)
 * @n: integer
 * @prev: points to the previous element of the stack (or queue)
 * @next: points to the next element of the stack (or queue)
 *
 * Description: doubly linked list node structure
 * for stack, queues, LIFO, FIFO
 */
typedef struct stack_s
{
        int n;
        struct stack_s *prev;
        struct stack_s *next;
} stack_t;
/**
 * struct instruction_s - opcode and its function
 * @opcode: the opcode
 * @f: function to handle the opcode
 *
 * Description: opcode and its function
 * for stack, queues, LIFO, FIFO
 */
typedef struct instruction_s
{
        char *opcode;
        void (*f)(stack_t **stack, unsigned int line_number);
} instruction_t;

List of files/Descriptions:

S/N Files Description
1.
2.
3.
4.
5.

Compilation & Output

  • These codes were compiled using: gcc -Wall -Werror -Wextra -pedantic -std=c89 *.c -o monty
  • Any output must be printed on stdout
  • Any error message must be printed on stderr

Examples

julien@ubuntu:~/monty$ cat -e bytecodes/000.m
push 0$
push 1$
push 2$
  push 3$
                   pall    $
push 4$
    push 5    $
      push    6        $
pall$
julien@ubuntu:~/monty$

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:

julien@ubuntu:~/monty$ cat -e bytecodes/001.m
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!$
julien@ubuntu:~/monty$
  • Some examples of using monty and its console output.
Example #1 Example #2 Example #3
~/monty$ cat -e bytecodes/00.m
push 1$
push 2$
push 3$
pall$
~/monty$ ./monty bytecodes/00.m
3
2
1
~/monty$ cat bytecodes/07.m
push 1
push 2
push 3
pall
pop
pall
pop
pall
pop
pall
~/monty$ ./monty bytecodes/07.m
3
2
1
2
1
1
~/monty$ cat bytecodes/09.m
push 1
push 2
push 3
pall
swap
pall
~/monty$ ./monty bytecodes/09.m
3
2
1
2
3
1

Authors/Collaborators

Okpara Onyedikachi || Duff Iniobong

monty's People

Contributors

ahmedadel35 avatar

Watchers

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