Package mars.assembler
Class Token
java.lang.Object
mars.assembler.Token
Represents one token in the input MIPS program. Each Token carries, along
with its type and value, the position (line, column) in which its source
appears in the MIPS program.
- Version:
- August 2003
- Author:
- Pete Sanderson
-
Constructor Summary
ConstructorsConstructorDescriptionToken(TokenTypes type, String value, MIPSprogram sourceMIPSprogram, int line, int start)
Constructor for Token class. -
Method Summary
Modifier and TypeMethodDescriptionProduces original program containing this token.int
Produces original line number of this token.int
Produces line number of MIPS program of this token.Produces MIPSprogram object associated with this token.int
Produces position within source line of this token.getType()
Produces token type of this token.getValue()
Produces source code of this token.void
setOriginal(MIPSprogram origProgram, int origSourceLine)
Set original program and line number for this token.void
setType(TokenTypes type)
Set or modify token type.toString()
Get a String representing the token.
-
Constructor Details
-
Token
Constructor for Token class.- Parameters:
type
- The token type that this token has. (e.g. REGISTER_NAME)value
- The source value for this token (e.g. $t3)sourceMIPSprogram
- The MIPSprogram object containing this tokenline
- The line number in source program in which this token appears.start
- The starting position in that line number of this token's source value.- See Also:
TokenTypes
-
-
Method Details
-
setOriginal
Set original program and line number for this token. Line number or both may change during pre-assembly as a result of the ".include" directive, and we need to keep the original for later reference (error messages, text segment display).- Parameters:
origProgram
- MIPS program containing this token.origSourceLine
- Line within that program of this token.
-
getOriginalProgram
Produces original program containing this token.- Returns:
- MIPSprogram of origin for this token.
-
getOriginalSourceLine
public int getOriginalSourceLine()Produces original line number of this token. It could change as result of ".include"- Returns:
- original line number of this token.
-
getType
Produces token type of this token.- Returns:
- TokenType of this token.
-
setType
Set or modify token type. Generally used to note that an identifier that matches an instruction name is actually being used as a label.- Parameters:
type
- new TokenTypes for this token.
-
getValue
Produces source code of this token.- Returns:
- String containing source code of this token.
-
toString
Get a String representing the token. This method is equivalent to getValue(). -
getSourceMIPSprogram
Produces MIPSprogram object associated with this token.- Returns:
- MIPSprogram object associated with this token.
-
getSourceLine
public int getSourceLine()Produces line number of MIPS program of this token.- Returns:
- line number in source program of this token.
-
getStartPos
public int getStartPos()Produces position within source line of this token.- Returns:
- first character position within source program line of this token.
-