bottom prev next

Conversion

AecImpl.java:

Now that the input reader has been implemented and meaningful arithmetic items are available for processing we can start working on the Shunting Yard algorithm proper.

In this step we implement the initial portion of the conversion algorithm described in Whole Pass, At Once section in the introductory chapter: add operands to the output queue, add operators to the stack and, once the input has been exhausted, empty the contents of the stack into the output queue.

We split the above functionality across two methods: the existing AecImpl.java:infixTo() and a new one:

private boolean processItem( AeItem newitem )


To help us keep track of AEC's internal state we also implement:

private void printState()

which produces output only if the debugging option has been turned on:

java -Ddbg -Dae="9-4" -jar aec.jar prefix queue: [4{1.3}] Stack: {} prefix queue: [4{1.3}] Stack: [-{1.2}] prefix queue: [9{1.1}][4{1.3}] Stack: [-{1.2}] prefix queue: [-{1.2}][9{1.1}][4{1.3}] Stack: {} prefix queue, 3 item(s): [-{1.2}][9{1.1}][4{1.3}] 0 java -Ddbg -Don=postfix -Dae="9-4" -jar aec.jar postfix queue: [9{1.1}] stack: {} postfix queue: [9{1.1}] stack: [-{1.2}] postfix queue: [9{1.1}][4{1.3}] stack: [-{1.2}] postfix queue: [9{1.1}][4{1.3}][-{1.2}] stack: {} postfix queue, 3 item(s): [9{1.1}][4{1.3}][-{1.2}] 0


Files

Modified: AecImpl.java

Makefile

Aec.java AecImpl.java Postfix.java Prefix.java AeNotation.java AeItem.java IReader.java

\(\blacksquare\)

top prev next