Package mars.assembler
Class TokenList
java.lang.Object
mars.assembler.TokenList
- All Implemented Interfaces:
Cloneable
Represents the list of tokens in a single line of MIPS code. It uses, but is
not a subclass of, ArrayList.
- Version:
- August 2003
- Author:
- Pete Sanderson
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a Token object to the end of the list.clone()
Makes clone (shallow copy) of this token list object.get(int pos)
Returns requested token given position number (starting at 0).Retrieve the source line String associated with this token list.boolean
isEmpty()
Returns empty/non-empty status of list.void
remove(int pos)
Removes Token object at specified list position.void
Replaces token at position with different one.void
setProcessedLine(String line)
Use this to record the source line String for this token list after possible modification (textual substitution) during assembly preprocessing.int
size()
Returns number of tokens in list.toString()
Get a String representing the token list.Get a String representing the sequence of token types for this list.
-
Constructor Details
-
TokenList
public TokenList()Constructor for objects of class TokenList
-
-
Method Details
-
setProcessedLine
Use this to record the source line String for this token list after possible modification (textual substitution) during assembly preprocessing. The modified source will be displayed in the Text Segment Display.- Parameters:
line
- The source line, possibly modified (possibly not)
-
getProcessedLine
Retrieve the source line String associated with this token list. It may or may not have been modified during assembly preprocessing.- Returns:
- The source line for this token list.
-
get
Returns requested token given position number (starting at 0).- Parameters:
pos
- Position in token list.- Returns:
- the requested token, or ArrayIndexOutOfBounds exception
-
set
Replaces token at position with different one. Will throw ArrayIndexOutOfBounds exception if position does not exist.- Parameters:
pos
- Position in token list.replacement
- Replacement token
-
size
public int size()Returns number of tokens in list.- Returns:
- token count.
-
add
Adds a Token object to the end of the list.- Parameters:
token
- Token object to be added.
-
remove
public void remove(int pos)Removes Token object at specified list position. Uses ArrayList remove method.- Parameters:
pos
- Position in token list. Subsequent Tokens are shifted one position left.- Throws:
IndexOutOfBoundsException
- ifpos
is < 0 or >=size()
-
isEmpty
public boolean isEmpty()Returns empty/non-empty status of list.- Returns:
true
if list has no tokens, elsefalse
.
-
toString
Get a String representing the token list. -
toTypeString
Get a String representing the sequence of token types for this list.- Returns:
- String version of the token types for this list (a blank is inserted after each token type).
-
clone
Makes clone (shallow copy) of this token list object.- Returns:
- the cloned list.
-