bottom prev next

Input

AeItem.java:

Being of mixed-gender, an arithmetic expression item can become an operand:

void mkOperand( String a, int ln, int col )


or an operator:

void mkOperator( String op, int ln, int col )


Playing a partial role of a parser it also detects if an input character is an operator:

boolean isOperator( char c )


AeNotation.java:

Arithmetic expression's output notations should be able to identify themselves via:

public String name()


Since potentially multi-byte operands are discovered by the prefix notation in a right to left fashion, we will need a mechanism to rotate such an operand about a vertical axis passing through its center prior to converting it into a binary form so that \(321\), for example, becomes \(123\):

public void prepareOperand( StringBuilder operand )


To support the uniform motion through the input arithmetic expression rendered in an infix form both output notations should be able to:

  • rewind
  • detect the logical end of an input queue
  • maintain its current absolute position, line and column numbers within the input queue
  • move through the input forward and backward:

public void rewind( String input ) public boolean eoi() public int curr() public int ln() public int col() public void setLn() public void setCol() public void moveNext() public void movePrev()


Both output notations should also support the uniform addition of the new items to and the removal of the existing items from the corresponding queue which we implement as Java's built-in ArrayList:

public void qAdd( ArrayList<AeItem> q, AeItem item ) public AeItem qRm( ArrayList<AeItem> q )


Prefix.java and Postfix.java:

Implement the interface outlined in AeNotation.java.


IReader.java:

The reader accepts its input via:

public void setInput( String infixae, AeNotation aeon )


and retrieves the next input item via:

public AecItem getItem()

using the following algorithm:

skip white space if ( end of input ) return null if ( item is an operator ) make an operator else make an operand move next return item

Consult IReader.java for details.


AecImpl.java:

To test the reader AecImpl.java:infixTo() steps through all the available input items and adds them to the output queue as is - not respecting the output notation request.

The auxiliary information attached to each item is its position within the input in the line.column format, for identification purposes:

java -Dae="9-4+1" -jar aec.jar prefix queue, 5 item(s): [9{1.1}][-{1.2}][4{1.3}][+{1.4}][1{1.5}] 0 java -Don=postfix -Dae="9-4+1" -jar aec.jar postfix queue, 5 item(s): [9{1.1}][-{1.2}][4{1.3}][+{1.4}][1{1.5}] 0


Files

Modified: AeItem.java, AeNotation.java, Postfix.java, Prefix.java, IReader.java, AecImpl.java

Makefile

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

\(\blacksquare\)

top prev next