An infix to postfix converter and calculator written in the esoteric language Piet
This converts an expression from infix to postfix notation
See a detailed explanation here
Input: 1+(3-4)*9/2
Output: 134-9*2/+
This takes a postfix notation expression as input and calculates the result
See a detailed explanation here
Input: 134-9*2/+
Output: -3
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.
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.
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...
Currently, these programs do not handle multi-digit numbers, negative numbers, or exponents as input. Also, any decimals are truncated.
- Either clone this repo or download the png's from the latest release.
Note: Codel size of release png is important when running.
- 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.
- Open either infixToPostfix_Codel_1 or _20 and enter that value when prompted for codel size.
- Input an infix expression, run, and copy the output.
- Then follow step 3 for postfixCalc_1 or _20.
- Input the return value from 3.1 and run to calculate the value.
Please open issues to discuss bugs or ideas 😁