From 2727bca0e623dfff1945e10a7662616169289dd5 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sat, 7 Oct 2023 11:46:00 -0400 Subject: [PATCH] Created Token Enums with Functions. --- .../jt_kb/cs4308/compiler/models/Token.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/edu/jt_kb/cs4308/compiler/models/Token.java diff --git a/src/edu/jt_kb/cs4308/compiler/models/Token.java b/src/edu/jt_kb/cs4308/compiler/models/Token.java new file mode 100644 index 0000000..db19eb9 --- /dev/null +++ b/src/edu/jt_kb/cs4308/compiler/models/Token.java @@ -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; + } +}