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.
This project reviewed the concepts of file input/output, linked lists, and stack data structure.
- Ubuntu 14.04 LTS
- all
.cfiles passBettystyle: 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
The files are to be compiled this way:
$ gcc -Wall -Werror -Wextra -pedantic *.c -o monty
- compile files
$ ./monty monty_byte_code_file_name.m
A few Monty bytecode files are supplied in the byecodes directory. For supported opcodes, look below.
$ cat bytecodes/12.m
push 1
push 2
push 3
pall
add
pall
$ ./monty bytecodes/12.m
3
2
1
5
1
-
push
Usage:
push <int>where<int>is an integerWhat it does: pushes an element to the stack.
-
pall
Usage:
pallWhat it does: prints all the values on the stack, starting from the top of the stack.
-
pint
Usage:
pintWhat it does: prints the value at the top of the stack followed by a new line.
-
pop
Usage:
popWhat it does: removes the top element of the stack.
-
swap
Usage:
swapWhat it does: swaps the top two elements of the stack.
-
add
Usage:
addWhat 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:
nopWhat it does: nothing.
-
sub
Usage:
subWhat 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:
divWhat 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:
mulWhat 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:
modWhat 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:
pcharWhat it does: prints the character at the top of the stack if it is a printable character.
-
pstr
Usage:
pstrWhat it does: prints the string starting at the top of the stack.
-
rotl
Usage:
rotlWhat it does: rotates the stack to the left.
-
rotr
Usage:
rotrWhat it does: rotates the stack to the right.
- 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
stackandqueueopcodes that would set the format of the data to a stack (LIFO) or queue (FIFO).