Files
MY_COMPILER/frontend/ast/token/TokenNode.java
2025-12-10 17:58:17 +08:00

51 lines
1.0 KiB
Java

package frontend.ast.token;
import frontend.ast.Node;
import frontend.ast.SyntaxType;
import frontend.lexer.Token;
import frontend.lexer.TokenStream;
import frontend.lexer.TokenType;
public class TokenNode extends Node {
private Token token;
public TokenNode(TokenStream ts) {
super(SyntaxType.TOKEN, ts);
token = ts.read();
}
@Override
public String toString() {
return token.toString();
}
public String getValue() {
return token.getValue();
}
public int getLine() {
return token.getLine();
}
public String getName() {
return token.getValue();
}
public TokenType getType() {
return token.getType();
}
public int getFormatNum() {
int num = 0;
String str = token.getValue();
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '%' && i + 1 < str.length()
&& str.charAt(i + 1) == 'd') {
num++;
i++;
}
}
return num;
}
}