Question: While lineTokens is not empty: 1 . Dequeue a token from lineTokens and get its first character. 2 . If the first character is a

While lineTokens is not empty: 1. Dequeue a token from lineTokens and get its first character. 2. If the first character is a letter or digit, then the token is an Operand token. Enqueue the token onto the queue postfix. 3. If the first character is a left parenthesis, then the token is a Left Parenthesis token. Push the token onto the top of the stack ops. 4. If the first character is a right parenthesis, then the token is a Right Parenthesis token. a. Pop the operator at the top of the stack ops and enqueue the popped operator onto the queue postfix. b. Repeat step a above until the top of the stack ops contains a left parenthesis. c. Pop the left parenthesis at the top of the stack ops and discard it.5. If the first character is one of the 4 operators: +,,*, or /, then the token is an Operator token. a. If the stack ops is not empty and the operator at the top of the stack ops has a higher or equal precedence than the operator token just read, then pop the operator at the top of the stack ops and enqueue the popped operator onto the queue postfix. b. Repeat step a above until the stack ops is empty or the operator at the top of the stack ops has a lower precedence than the operator token just read. c. Finally, push the operator token just read onto the top of the stack ops. Note: Use the given method hasHigherOrEqualPrecedence to compare the precedence of two operators to see if the first operator has a higher precedence than the second operator.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!