llvmir some opt
This commit is contained in:
51
frontend/ast/decl/ConstDecl.java
Normal file
51
frontend/ast/decl/ConstDecl.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package frontend.ast.decl;
|
||||
|
||||
import error.Errors;
|
||||
import error.ErrorType;
|
||||
|
||||
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 ConstDecl extends Node {
|
||||
public ConstDecl(TokenStream ts) {
|
||||
super(SyntaxType.CONST_DECL, ts);
|
||||
}
|
||||
|
||||
public void parse(Errors errors) {
|
||||
TokenNode constkk = new TokenNode(this.ts);
|
||||
addChild(constkk);
|
||||
TokenNode intkk = new TokenNode(this.ts);
|
||||
addChild(intkk);
|
||||
while (true) {
|
||||
ConstDef cdef = new ConstDef(this.ts);
|
||||
cdef.parse(errors);
|
||||
addChild(cdef);
|
||||
if (getCurrToken().getType() != TokenType.COMMA) {
|
||||
break;
|
||||
} else {
|
||||
TokenNode comma = new TokenNode(this.ts);
|
||||
addChild(comma);
|
||||
}
|
||||
}
|
||||
if (getCurrToken().getType() != TokenType.SEMICN) {
|
||||
errors.addError(new Error(this.ts.peek(-1).getLine(), ErrorType.i));
|
||||
} else {
|
||||
TokenNode semicoln = new TokenNode(this.ts);
|
||||
addChild(semicoln);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<ConstDef> GetConstDefs() {
|
||||
ArrayList<ConstDef> constDefs = new ArrayList<>();
|
||||
for (int i = 2; i < getChildren().size(); i += 2) {
|
||||
constDefs.add((ConstDef) getChild(i));
|
||||
}
|
||||
return constDefs;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user