llvmir some opt
This commit is contained in:
50
frontend/ast/token/TokenNode.java
Normal file
50
frontend/ast/token/TokenNode.java
Normal file
@@ -0,0 +1,50 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user