Since algorithms are programming language-independent, they can be implemented in a multitude of mediums. We shall present a Java-based solution while you are encouraged to experiment with different host languages of your choice in which case the number of the upcoming steps will likely vary.
We reason that first we need an input reader to scan an arithmetic expression rendered in an infix notation. Since this is not a grammar-recognition exercise we fuse the input reader and the parser into one whole: our arithmetic operators are one character-long and, barring white space, everything that is not an operator is treated as an operand:
We store the input reader-manufactured arithmetic expression items in a mixed-gender entity that can be either an operand or an operator:
These items dwell in linear containers we qualify as a queue and a stack. Java offers a plethora of stock linear containers to choose from - we use ArrayList and Stack for those.
To capture the commonalities of arithmetic expressions' output notations in order to preserve the input-reading uniformity we use an abstract data type in a form of a Java interface:
of which we have two implementations:
We house the Shunting Yard algorithm implementation proper in one file:
while wrapping it in a separate entity containing a command line interface that can be used to exercise the functionality of this arithmetic expressions calculator:
which completes the whole - a Java aec package:
We use vi to type in the code and a C-styled make file to build it.
The initial set of source files should survive the compilation producing a functional program that runs but generates no meaningful output yet:
make clean rm -f aec.jar aec/*.class make aec.jar javac -g -classpath .:./aec aec/Aec.java javac -g -classpath .:./aec aec/AecImpl.java javac -g -classpath .:./aec aec/AeNotation.java javac -g -classpath .:./aec aec/AeItem.java javac -g -classpath .:./aec aec/IReader.java javac -g -classpath .:./aec aec/Postfix.java javac -g -classpath .:./aec aec/Prefix.java rm -f /tmp/aecManifest echo "Main-Class: aec/Aec" > /tmp/aecManifest jar cmf /tmp/aecManifest aec.jar aec/*.class rm -f /tmp/aecManifest java -jar aec.jar
Files
Aec.java AecImpl.java Postfix.java Prefix.java AeNotation.java AeItem.java IReader.java
\(\blacksquare\)