Question: TOKEN CLASS: (10 pts) This class represents an individual token with in a Lisp expression. A Token can be an operator or a variable.

TOKEN CLASS: (10 pts) This class represents an individual token with in

TOKEN CLASS: (10 pts) This class represents an individual token with in a Lisp expression. A Token can be an operator or a variable. For example, in the expression (+ a 2), we have the following tokens: +, a, and 2, where + is an operator and 2 and a are operands. Define a class called Token. The class has the follwoing attributes: operator - a Character object that represents an operator. operand - a Double object that represents operands. isOperator - a boolean variable that indicates whether a token is an operator or not. The class also has the following methods: public Token (Character operator) - a constructor that initializes an operator with the given value and an operand to 0.0 and isOperator to true. public Token (Double operand) - a constructor that initializes an operand with the given value and an operator to (space character) and isOperator to false. Double applyOperator (Double valuel, Double value2) - a method that applies the operator to the two values and return the result. public Double getIdentity() - a method that returns the identity value of an operator. For example, x + 0 = x. Therefore o is the identity for + and it will be associated with the expression (+), i.e., if a Lisp expression that contains (+) will be evaluated to 0. The method will return the identity for +, -, *, /. public boolean takes Nooperands ( ) - this method decides if an operator can be used without an operand in an expression. Please, take a look at the description of Lisp expression above to decide which arithmetic operator can be used without an operand. The method returns true, if the operator can be used without an operand, false otherwise. public boolean isoperator() - returns true if the token is an operator, false otherwise. Getter methods for the operand called getValue and the operator called getoperator.

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!