trassare.com

com.trassare.calculator.engine
Class Token

java.lang.Object
  extended by com.trassare.calculator.engine.Token
Direct Known Subclasses:
Token.ERROR, Token.IDENTIFIER, Token.NUMBER

public class Token
extends Object

A Token class for use in a scanner for simple arithmetic expressions.
CS 152, Fall, 2005
Programming Assignment #1

Version:
10 September 2006
Author:
Kenneth C. Louden, Samuel T Trassare

Nested Class Summary
static class Token.ERROR
          Token matching an erroneous character in input.
CS 152, Fall, 2005
Programming Assignment #1
static class Token.IDENTIFIER
          Token matching regular expression [A-Z]+ in input.
This token is used for variable names in the input expression.
static class Token.NUMBER
          Token matching regular expression [0-9]+(\.[0-9]*)? in input.
CS 152, Fall, 2005
Programming Assignment #1
 
Field Summary
static Token ACOS
          Token matching 'acos' in input.
static Token ASIN
          Token matching 'asin' in input.
static Token ASSIGN
          Token matching '>>' in input.
static Token ATAN
          Token matching 'atan' in input.
static Token COS
          Token matching 'cos' in input.
static Token EOL
          Token matching end of line.
static Token ERROR
          A dummy ERROR token for equality testing.
static Token IDENTIFIER
          A dummy IDENTIFIER token for equality testing.
static Token LN
          Token matching 'ln' in input.
static Token LPAREN
          Token matching '(' in input.
static Token MINUS
          Token matching '-' in input.
static Token NUMBER
          A dummy NUMBER token for equality testing.
static Token OVER
          Token matching '/' in input.
static Token PLUS
          Token matching '+' in input.
static Token POW
          Token matching '^' in input.
static Token RECALL
          Deprecated. Do not use this token. It will be removed in future versions of this class.
static Token RPAREN
          Token matching ')' in input.
static Token SIN
          Token matching 'sin' in input.
static Token STORE
          Deprecated. Do not use this token. It will be removed in future versions of this class. Instead use Token.ASSIGN. This token was originally used as a command to send the evaluated expression to a single memory cell. The use of Token.ASSIGN signals an assignment to a variable. Beginning with the 10 September 2006 version of this class the com.trassare.calculator.engine package now supports infinite memory storage.
static Token TAN
          Token matching 'tan' in input.
static Token TIMES
          Token matching '*' in input.
 
Constructor Summary
protected Token(String inValue)
          Make the constructor protected so that only limited kinds of tokens can be generated.
 
Method Summary
 boolean equals(Object obj)
          Overrides Object.equals: all tokens in the same token subclass are implicitly equal.
 int hashCode()
          Dummy hash code implementation.
 String stringValue()
          An accessor method for the stringValue field.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACOS

public static final Token ACOS
Token matching 'acos' in input. This is the arccosine operator.


ASIN

public static final Token ASIN
Token matching 'asin' in input. This is the arcsine operator.


ASSIGN

public static final Token ASSIGN
Token matching '>>' in input. This token is used to indicate that an evaluated expression will be stored to a variable as in:
2+2>>VAR


ATAN

public static final Token ATAN
Token matching 'atan' in input. This is the arctangent operator.


COS

public static final Token COS
Token matching 'cos' in input. This is the cosine operator.


EOL

public static final Token EOL
Token matching end of line.


ERROR

public static final Token ERROR
A dummy ERROR token for equality testing. Since the constructor for the Token class is protected, a dummy error token needs to be constructed. Tokens from the input stream can be compared against the dummies to verify the type of token in the input.


LN

public static final Token LN
Token matching 'ln' in input. This is the natural logarithm operator.


LPAREN

public static final Token LPAREN
Token matching '(' in input.


MINUS

public static final Token MINUS
Token matching '-' in input. This token is both the binary subtraction operator and the unary negation operator. It's usage depends upon it's location in the expression and is determined by the expression evaluator.


NUMBER

public static final Token NUMBER
A dummy NUMBER token for equality testing. Since the constructor for the Token class is protected, a dummy number token needs to be constructed. Tokens from the input stream can be compared against the dummies to verify the type of token in the input.


IDENTIFIER

public static final Token IDENTIFIER
A dummy IDENTIFIER token for equality testing. Since the constructor for the Token class is protected, a dummy identifier token needs to be constructed. Tokens from the input stream can be compared against the dummies to verify the type of token in the input.


OVER

public static final Token OVER
Token matching '/' in input. This is the division operator.


PLUS

public static final Token PLUS
Token matching '+' in input. This is the addition operator.


POW

public static final Token POW
Token matching '^' in input. This is the power operator.


RECALL

public static final Token RECALL
Deprecated. Do not use this token. It will be removed in future versions of this class.
Token matching '@' in input. This is the recall operator.


RPAREN

public static final Token RPAREN
Token matching ')' in input.


SIN

public static final Token SIN
Token matching 'sin' in input. This is the sine operator.


STORE

public static final Token STORE
Deprecated. Do not use this token. It will be removed in future versions of this class. Instead use Token.ASSIGN. This token was originally used as a command to send the evaluated expression to a single memory cell. The use of Token.ASSIGN signals an assignment to a variable. Beginning with the 10 September 2006 version of this class the com.trassare.calculator.engine package now supports infinite memory storage.
Token matching '!' in input.


TAN

public static final Token TAN
Token matching 'tan' in input. This is the tangent operator.


TIMES

public static final Token TIMES
Token matching '*' in input. This is the multiplication operator.

Constructor Detail

Token

protected Token(String inValue)
Make the constructor protected so that only limited kinds of tokens can be generated.

Parameters:
inValue - the string value of the token
Method Detail

equals

public final boolean equals(Object obj)
Overrides Object.equals: all tokens in the same token subclass are implicitly equal.

Overrides:
equals in class Object
Parameters:
obj - the object against which this object is tested for equality
Returns:
true if obj is in the same class as this object

hashCode

public final int hashCode()
Dummy hash code implementation.

Overrides:
hashCode in class Object
Returns:
the hash code of the super object.

stringValue

public final String stringValue()
An accessor method for the stringValue field.

Returns:
the stringValue of the token

trassare.com