Coder Social home page Coder Social logo

monty's Introduction

Monty

monty is an interpreter of Monty ByteCodes files, which is a scripting language just like Python.

About the Monty language

This is a language that contains specific instructions to manipulate data information (stacks or queues), where each instruction (called opcode) is sended per line. Files which contains Monty byte codes usually have the .m extension.

Example (file.m):

$ cat file.m
# Pushing element to the stack
push 0
push 1
push 2
# Printing all elements
pall
push 3
push 4
pop
# Rotating the stack to the bottom
rotr
pall
rotl
# Setting FIFO
queue
push 5
# Setting LIFO
stack
push 5
$

Technologies

  • Interpreter was written with C language
  • C files are compiled using gcc 4.8.4
  • C files are written according to the C90 standard
  • Tested on Ubuntu 14.04 LTS

Usage

To compile all files:

$ gcc -Wall -Werror -Wextra -pedantic *.c -o monty
$

The synopsis of the interpreter is the following:

$ ./monty [filename]
$

To run the interpreter:

$ ./monty file.m
2
1
0
0
3
2
1
$

Features

Opcodes

monty executes the following opcodes:

Opcode Description
push Pushes an element to the stack
pall Prints all the values on the stack
pint Prints the value at the top of the stack
pop Removes the top element of the stack
swap Swaps the top two elements of the stack
queue Sets the format of the data to a queue (FIFO)
stack Sets the format of the data to a stack (LIFO)
nop Doesn't do anything
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 element of the stack
div Divides the second top element of the stack by the top element of the 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
pstr Prints the string starting at the top of the stack
rotl Rotates the stack to the top
rotr Rotates the stack to the bottom

Comments, indicated with #, are not executed by the interpreter.

When a nonextistent opcode is passed, the interpreter prints an error message and stops:

$ cat errorfile.m
push 1
pint
pcx
$ ./monty errorfile.m
1
L3: unknown instruction pcx

Return value

When there is no errors, monty returns 0. Otherwise, returns 1

Authors

monty's People

Contributors

jorgezafra94 avatar luischaparroc avatar

Stargazers

 avatar  avatar

Watchers

 avatar

monty's Issues

Task 15. stack, queue

Implement the stack and queue opcodes.

  • The opcode stack sets the format of the data to a stack (LIFO). This is the default behavior of the program.

  • The opcode queue sets the format of the data to a queue (FIFO).

  • The top of the stack becomes the front of the queue

  • The front of the queue becomes the top of the stack

Task 3. Swap

Implement the swap opcode.

  • The opcode swap swaps the top two elements of the stack.

  • less than two elements print error and exit status EXIT_FAILURE

Task 6. sub

Implement the sub opcode.

  • sub works

  • error when stack contains less than two elements.

Task 11. pchar

Implement the pchar opcode.

  • The integer stored at the top of the stack is treated as the ascii value of the character to be printed

  • If the value is not in the ascii table (man ascii) print the error message and exit status EXIT_FAILURE

  • If the stack is empty, print the error message and exit status EXIT_FAILURE

Task 12. pstr

Implement the pstr opcode: prints the string starting at the top of the stack.

  • pstr works

Error when:

  • stack is over

  • the value of the element is 0

  • the value of the element is not in the ascii table

Task 2. pop

Implement the pop opcode.

  • pop works

  • error with pop (print message)

Task 19. Multiplication level up

Multiply two digits given by the user.

  • Read the two digits from stdin, multiply them, and print the result, followed by a new line

Task 9. mod

Implement the mod opcode.
The opcode mod computes the rest of the division of the second top element of the stack by the top element of the stack.

  • If the stack contains less than two elements, print the error message and exit status EXIT_FAILURE

  • The result is stored in the second top element of the stack, and the top element is removed, so that at the end:
    - The top element of the stack contains the result
    - The stack is one element shorter

  • If the top element of the stack is 0, print the error message and exit status EXIT_FAILURE

Task 5. nop

Implement the nop opcode.

  • The opcode nop doesn’t do anything.

Task 14. rotr

Implement the rotr opcode.

  • rotr works

  • rotr never fails

Task 1. Pint

Implement the pint opcode.

  • The opcode pint prints the value at the top of the stack, followed by a new line.

  • If the stack is empty, print the error message, and exit status EXIT_FAILURE

Task 18. Multiplication

Multiply two digits given by the user.

  • Read the two digits from stdin, multiply them and print the result

  • The result of the multiplication will be one digit-long

Task 7. div

Implement the div opcode.

The opcode div divides the second top element of the stack by the top element of the stack.

  • If the stack contains less than two elements, print the error message and exit status EXIT_FAILURE

  • The result is stored in the second top element of the stack, and the top element is removed, so that at the end:
    - The top element of the stack contains the result
    - The stack is one element shorter

  • if the top element of the stack is 0, print the error message and exit with EXIT_FAILURE

Task 16. Holberton

Write a BF script that prints Holberton

  • Files are stored inside bf sub directory

Task 8. mul

Implement the mul opcode.

  • mul works

  • error when stack contains less than two elements

  • exit with the status EXIT_FAILURE when there is an error

Task 4. add

Implement the add opcode.

  • add works

  • error when stack contains less than two elements.

Task 17. Add two digits

Add two digits given by the user.

  • Read the two digits from stdin, add them, and print the result

  • The total of the two digits with be one digit-long (<10)

Task 13. rotl

The opcode 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

  • rotl never fails

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.