51 lines
1.0 KiB
Java
Executable File
51 lines
1.0 KiB
Java
Executable File
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;
|
|
}
|
|
}
|