43 lines
1018 B
Java
Executable File
43 lines
1018 B
Java
Executable File
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";
|
|
}
|
|
}
|