Files
MY_COMPILER/frontend/lexer/Token.java
2025-12-10 17:58:17 +08:00

43 lines
976 B
Java

package frontend.lexer;
public class Token {
private TokenType type;
private String value;
private int line;
public Token(String value, int line) {
this.value = value;
this.type = TokenType.isWhatType(value);
this.line = line;
}
public void adjustType() {
if (this.type == TokenType.IDENFR) {
if (this.value.charAt(0) == '\"' &&
this.value.charAt(this.value.length() - 1) == '\"') {
this.type = TokenType.STRCON;
}
String regex = "^\\d+$";
if (this.value.matches(regex)) {
this.type = TokenType.INTCON;
}
}
}
public String getValue() {
return this.value;
}
public TokenType getType() {
return this.type;
}
public int getLine() {
return this.line;
}
public String toString() {
return this.type + " " + this.value + "\n";
}
}