Programming > Object-Oriented Programming and Data Structures > Arizona State University CSE 205 Expression.java (//Complete Code). (All)
Arizona State University CSE 205 Expression.java /**************************************************************************** // CLASS: Expression.java // // COURSE AND PROJECT INFO // CSE20... 5 Object Oriented Programing and Data Structures //**************************************************************************** /** * Represents an infix expression to be evaluated. */ public class Expression { /** * A queue which stores the tokens of the infix expression in the order in * which they were input. */ Queue<Token> mTokenQueue; /** * Expression(String) * * pExprStr is a string representing an infix expression, such as * "(1 + 2) * -3". This ctor uses the Tokenizer class to break the string * into Token objects which are stored in the token queue instance variable. * * PSEUDOCODE: Create a new Queue<Token> object and pass it to setTokenQueue * (this initializes mTokenQueue) Declare and create a Tokenizer object * named tokenizer passing pExprStr to the ctor Declare a Token object named * prevToken initialized to null -- Read the first token Declare a Token * object named token and assign the return value from tokenizer.nextToken() * to it -- Keep reading tokens until tokenizer.nextToken() returns null * While token is not null Do -- Check for and handle the negation operator. * If token instanceof SubOperator Then token = negationCheck(token, pToken) * End if -- Add the token to the queue. Call getTokenQueue().enqueue(token) * prevToken = token -- Read the next token. token = call * tokenizer.nextToken() End While */ public Expression(String pExprStr) { Queue<Token> object = new Queue<Token>(); setTokenQueue(object); Tokenizer tokenizer = new Tokenizer(pExprStr); Token pToken = null; //getTokenQueue(); Token token = tokenizer.nextToken(); while (token != null) { if (token instanceof SubOperator) { token = negationCheck(token, pToken); } getTokenQueue().enqueue(token); pToken = token; token = tokenizer.nextToken(); [Show More]
Last updated: 1 year ago
Preview 1 out of 4 pages
Connected school, study & course
About the document
Uploaded On
Dec 09, 2021
Number of pages
4
Written in
This document has been written for:
Uploaded
Dec 09, 2021
Downloads
0
Views
169
In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Browsegrades · High quality services·