You will be using a Stack to manipulate operator Strings, and a Queue to create the postfix expression. Therefore, you need to implement a Stack of Strings and a Queue of Strings. The Stack and Queue operations are declared in the provided interfaces StackIF and QueueIF. Also, two classes StackException and QueueException are provided. The TestDriver reads an input file line by line and exercises your In2Post code. Copy the following starter codes and input file, and put them in an Eclipse project:
TokenIter.java
StackIF.java
StackException.java
Stack.java
QueueIF.java
QueueException.java
Queue.java
In2Post.java
TestDriver.java
in
You need to work on the following codes.
A regular definition is a
name = regular expressionwhere name can be used in in other regular definitions.
Valid tokens are numbers, operators and parentheses, defined by the following regular definitions:
digit = [0-9] number = (digit)+ operator = "+" | "-" | "*" | "/" parenthesis = "(" | ")"The main method exercises TokenIter; it prints every next token surrounded by square brackets, to show white space, and produces the following output:
line: [ 15*(26+37) - 489/5*61 - (723-8456789) ] next token: [15] next token: [*] next token: [(] next token: [26] next token: [+] next token: [37] next token: [)] next token: [-] next token: [489] next token: [/] next token: [5] next token: [*] next token: [61] next token: [-] next token: [(] next token: [723] next token: [-] next token: [8456789] next token: [)]
res
contains the result of running TestDriver for
input file in
, when in not debug mode.
Use the Checkin webserver to exercise and submit your code. Submit a P2.jar file containing your Stack.java, Queue.java, In2Post.java, and TokenIter.java codes **ONLY**.
Make sure you put ***java** files in your jar (not class files). The TAs can help you creating a proper jar file.