llvmir some opt
This commit is contained in:
59
frontend/ast/decl/VarDecl.java
Normal file
59
frontend/ast/decl/VarDecl.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package frontend.ast.decl;
|
||||
|
||||
import error.ErrorType;
|
||||
import error.Errors;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import error.Error;
|
||||
import frontend.ast.Node;
|
||||
import frontend.ast.SyntaxType;
|
||||
import frontend.ast.token.TokenNode;
|
||||
import frontend.lexer.TokenStream;
|
||||
import frontend.lexer.TokenType;
|
||||
|
||||
public class VarDecl extends Node {
|
||||
public VarDecl(TokenStream ts) {
|
||||
super(SyntaxType.VAR_DECL, ts);
|
||||
}
|
||||
|
||||
public void parse(Errors errors) {
|
||||
if (getCurrToken().getType() == TokenType.STATICTK) {
|
||||
TokenNode staitckk = new TokenNode(ts);
|
||||
addChild(staitckk);
|
||||
}
|
||||
TokenNode intkk = new TokenNode(ts);
|
||||
addChild(intkk);
|
||||
while (true) {
|
||||
VarDef vdf = new VarDef(ts);
|
||||
vdf.parse(errors);
|
||||
addChild(vdf);
|
||||
if (getCurrToken().getType() == TokenType.COMMA) {
|
||||
TokenNode comma = new TokenNode(ts);
|
||||
addChild(comma);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (getCurrToken().getType() == TokenType.SEMICN) {
|
||||
TokenNode semicn = new TokenNode(ts);
|
||||
addChild(semicn);
|
||||
} else {
|
||||
errors.addError(new Error(this.ts.peek(-1).getLine(), ErrorType.i));
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<VarDef> GetVarDefs() {
|
||||
ArrayList<VarDef> varDefs = new ArrayList<VarDef>();
|
||||
if (getChild(1) instanceof VarDef) {
|
||||
for (int i = 1; i < getChildren().size(); i += 2) {
|
||||
varDefs.add((VarDef) getChild(i));
|
||||
}
|
||||
} else {
|
||||
for (int i = 2; i < getChildren().size(); i += 2) {
|
||||
varDefs.add((VarDef) getChild(i));
|
||||
}
|
||||
}
|
||||
return varDefs;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user