com.neoworks.rdc
Class TokenList

java.lang.Object
  |
  +--com.neoworks.rdc.TokenList
Direct Known Subclasses:
SymbolTable

public class TokenList
extends java.lang.Object

Class which holds a vector of Tokens, and the last position accessed in the array.


Field Summary
protected  java.util.Vector tokenData
           
 
Constructor Summary
TokenList()
          Create a new empty list of tokens
TokenList(TokenList copyList)
          Copy constructor.
TokenList(java.util.Vector newTokenList)
          Create a new token list from a vector of tokens.
 
Method Summary
 void addToken(Token newToken)
          This function appends a token to the end of the TokenList, and increments nextPosition.
 int getSize()
          Returns the index of the next position in the list
 Token getTokenAt(int tokenIndex)
          Returns the token at a position in the list.
 void removeTokenAt(int tokenIndex)
          Removes a token from the list at the specified position
 int tokenIsIn(Token findThisToken)
          Find the index of a token in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tokenData

protected java.util.Vector tokenData
Constructor Detail

TokenList

public TokenList(TokenList copyList)
Copy constructor. Creat a new TokenList from an existing TokenList. This does a shalow copy of the tokens in the list. To do a deep copy of the vetor use the clone method. Note that this does not do a deep copy of the elements in the vector so they should also be cloned seperatly.

Parameters:
copyList - The token list to copy into this one

TokenList

public TokenList(java.util.Vector newTokenList)
Create a new token list from a vector of tokens. The tokens in the vector are added in the same order to the list. The next pointer is then set to the end of the list.

Parameters:
newTokenList - A vector of tokens to start the new tokenList

TokenList

public TokenList()
Create a new empty list of tokens

Method Detail

addToken

public void addToken(Token newToken)
This function appends a token to the end of the TokenList, and increments nextPosition.

Parameters:
newToken - The new token to be added to the array.

getTokenAt

public Token getTokenAt(int tokenIndex)
Returns the token at a position in the list. Will throw an out of bounds exception if the index is out of bounds.

Parameters:
tokenIndex - The index of the token in the list to return
Returns:
The token at the index passed

removeTokenAt

public void removeTokenAt(int tokenIndex)
Removes a token from the list at the specified position

Parameters:
tokenIndex - The index of the token in the list to remove

getSize

public int getSize()
Returns the index of the next position in the list

Returns:
The index of the next position in the list

tokenIsIn

public int tokenIsIn(Token findThisToken)
Find the index of a token in the list. Finds a token in the list with the same lexeme as in the findThisToken token passed. Note that this only compares the lexems and not the types or values!! Returns the index of the found token or -1 if no token found.

Parameters:
findThisToken - The token to look for
Returns:
The index of the found token (or -1 if not found)