Class TokenList

java.lang.Object
mars.assembler.TokenList
All Implemented Interfaces:
Cloneable

public class TokenList extends Object implements 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
    Constructor
    Description
    Constructor for objects of class TokenList
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add​(Token token)
    Adds a Token object to the end of the list.
    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
    Returns empty/non-empty status of list.
    void
    remove​(int pos)
    Removes Token object at specified list position.
    void
    set​(int pos, Token replacement)
    Replaces token at position with different one.
    void
    Use this to record the source line String for this token list after possible modification (textual substitution) during assembly preprocessing.
    int
    Returns number of tokens in list.
    Get a String representing the token list.
    Get a String representing the sequence of token types for this list.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • TokenList

      public TokenList()
      Constructor for objects of class TokenList
  • Method Details

    • setProcessedLine

      public void setProcessedLine(String line)
      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

      public String 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

      public Token get(int pos)
      Returns requested token given position number (starting at 0).
      Parameters:
      pos - Position in token list.
      Returns:
      the requested token, or ArrayIndexOutOfBounds exception
    • set

      public void set(int pos, Token replacement)
      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

      public void add(Token token)
      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 - if pos is < 0 or >= size()
    • isEmpty

      public boolean isEmpty()
      Returns empty/non-empty status of list.
      Returns:
      true if list has no tokens, else false.
    • toString

      public String toString()
      Get a String representing the token list.
      Overrides:
      toString in class Object
      Returns:
      String version of the token list (a blank is inserted after each token).
    • toTypeString

      public String 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

      public Object clone()
      Makes clone (shallow copy) of this token list object.
      Returns:
      the cloned list.