diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-25 00:17:56 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-25 00:18:51 -0600 |
commit | 765337c53286db39ffc3c64eede602afe3899647 (patch) | |
tree | 893b488f70b22c4d18cec6934ed479feb0943b54 /st/TokenKey.java | |
parent | d2017d232557b45792857b972ca8883df6e79506 (diff) |
Rewrote SymbolTable to add uniqueness to stored tokens
Diffstat (limited to 'st/TokenKey.java')
-rw-r--r-- | st/TokenKey.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/st/TokenKey.java b/st/TokenKey.java new file mode 100644 index 0000000..2319917 --- /dev/null +++ b/st/TokenKey.java @@ -0,0 +1,45 @@ +package st; + +/** + * This class is a data structure used to distinguish tokens in + * a given program. Tokens are considered unique if their "beginLine" + * and name are different. + */ +public class TokenKey { + + private String name; + private int beginLine; + + public TokenKey(String name, int beginLine) { + // classes CANNOT collide, so CALLEES ARE EXPECTED TO USE ZERO! + this.name = name; + this.beginLine = beginLine; + } + + @Override public String toString() { + return String.format("%s (%d)", + this.name, + this.beginLine); + } + + + @Override public boolean equals(Object other) { + boolean ret = false; + TokenKey o; + if (other instanceof TokenKey && + (o = (TokenKey) other).name == this.name && + o.beginLine == this.beginLine) { + ret = true; + } + return ret; + } + + @Override public int hashCode() { + return this.name.hashCode(); + } + + public String getName() { + return this.name; + } + +} |