A stack in C is nothing but a linear data structure that follows the LIFO rule (Last In First Out). In a stack, both insertion and deletion take place from just one end, that is, from the top.
In contrast to a stack, a queue in C is nothing but a linear data structure that follows the FIFO rule (First In First Out). Insertion is done from the back (the rear end) and deletion is done from the front.
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. The goal of this project is to create an interpreter for Monty ByteCodes 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:
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$
$ gcc -Wall -Werror -Wextra -pedantic -std=c89 *.c -o monty
The following opcodes are supported by the interpreter:
push:
Pushes an integer onto the stackpop:
Removes the top element of the stackswap:
Swaps the top two elements of the stackadd:
Adds the top two elements of the stack.sub:
Subtracts the top element of the stack from the second top element.div:
Divides the second top element of the stack by the top element.mul:
Multiplies the second top element of the stack with the top element.mod:
Computes the modulus of the second top element of the stack with the top element of the stack.pall:
Prints all the values on the stack.pint:
Prints the value at the top of the stack.pchar:
Prints the character at the top of the stack.pstr:
Prints the string starting at the top of the stack.nop:
Does nothing.comments:
The capability of commenting.rotl:
Moves element at the top to the bottom of the stack.rotr:
The bottom of the stack becomes the top.queue, stack:
Toggles the doubly link list implementation style
julien@ubuntu:~/monty$ cat bytecodes/35.m
push 1
push 2
push 3
push 4
push 5
push 6
push 7
push 8
push 9
push 0
pall
rotl
pall
julien@ubuntu:~/monty$ ./monty bytecodes/35.m
0
9
8
7
6
5
4
3
2
1
9
8
7
6
5
4
3
2
1
0
julien@ubuntu:~/monty$
This program was written by:
Nkechi Christabel Udenkwor
Bamiwo Adebayo