Skip to content

An infix to postfix converter and calculator written in the esoteric language Piet

Notifications You must be signed in to change notification settings

DovahBot/Piet-Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Piet Calculator

An infix to postfix converter and calculator written in the esoteric language Piet

Table of Contents

  1. Programs
    1. Infix To Postfix Converter
    2. Postfix Calculator
    3. PietCalc.cpp
  2. About Piet
  3. Project Notes
    1. Limitations
  4. How to Run
  5. Contributing
  6. License

Programs

Infix To Postfix Converter

This converts an expression from infix to postfix notation
See a detailed explanation here

Input: 1+(3-4)*9/2
Output: 134-9*2/+

Postfix Calculator

This takes a postfix notation expression as input and calculates the result
See a detailed explanation here

Input: 134-9*2/+
Output: -3

PietCalc.cpp

This .cpp file is just showing how I initially planned the algorithm prior to diving into Piet. It's not the prettiest or most efficient, but I wanted to write the code as if most of the limitations of Piet were in place.

About Piet

Piet is an esoteric programming language, named after the artist Piet Mondrian, in which every instruction is represented by a transition between colors and hues.

Read more about Piet here!

Project Notes

This calculator begins with a conversion to postfix (aka Reverse Polish Notation (RPN)) as it is significantly easier in Piet to calculate the value of a postfix expression rather than an infix one.

I initially imagined this calculator to be confined within a single image, instead of one program to convert from infix to postfix and another to calculate. However, after making significant progress on the former I realized without access to another stack to store program output for later, this would be very difficult.

I do think it's feasible, but would require significant stack manipulation. Maybe it'll be a future endeavor...

Limitations

Currently, these programs do not handle multi-digit numbers, negative numbers, or exponents as input. Also, any decimals are truncated.

How to Run

  1. Either clone this repo or download the png's from the latest release.

    Note: Codel size of release png is important when running.

  2. I recommend using the Pietron IDE to run as it has a useful debugger where you can step through to better understand the program if you wish.
  3. Open either infixToPostfix_Codel_1 or _20 and enter that value when prompted for codel size.
    1. Input an infix expression, run, and copy the output.
  4. Then follow step 3 for postfixCalc_1 or _20.
    1. Input the return value from 3.1 and run to calculate the value.

Contributing

Please open issues to discuss bugs or ideas 😁

License

MIT

About

An infix to postfix converter and calculator written in the esoteric language Piet

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages