Created Token Enums with Functions.
This commit is contained in:
commit
2727bca0e6
30
src/edu/jt_kb/cs4308/compiler/models/Token.java
Normal file
30
src/edu/jt_kb/cs4308/compiler/models/Token.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package edu.jt_kb.cs4308.compiler.models;
|
||||||
|
|
||||||
|
public enum Token {
|
||||||
|
IDENT(0),ASS_OP(1),SUB_OP(2),DIV_OP(3),INT_LITERAL(4),SEMICOLON(5);
|
||||||
|
|
||||||
|
public final int value; /* represents which Token you are referencing. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the ENUM to represent the value of each Token.
|
||||||
|
*
|
||||||
|
* @precondition: none
|
||||||
|
* @postcondition: A token is created.
|
||||||
|
*
|
||||||
|
* @param value - the integer value for the token.
|
||||||
|
*/
|
||||||
|
Token(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares two tokens and returns whether they are the same value or not.
|
||||||
|
*
|
||||||
|
* @param other - the other token being compared.
|
||||||
|
* @return if the values are the same, true
|
||||||
|
* else, false
|
||||||
|
*/
|
||||||
|
public boolean equals(Token other) {
|
||||||
|
return this.value == other.value;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user