llvmir some opt
This commit is contained in:
57
frontend/ast/block/ForStmt.java
Normal file
57
frontend/ast/block/ForStmt.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package frontend.ast.block;
|
||||
|
||||
import frontend.ast.SyntaxType;
|
||||
import frontend.ast.token.TokenNode;
|
||||
import frontend.lexer.TokenStream;
|
||||
import frontend.lexer.TokenType;
|
||||
import frontend.ast.Node;
|
||||
import frontend.ast.exp.Exp;
|
||||
import frontend.ast.exp.LVal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import error.Errors;
|
||||
|
||||
public class ForStmt extends Node {
|
||||
public ForStmt(TokenStream ts) {
|
||||
super(SyntaxType.FOR_STMT, ts);
|
||||
}
|
||||
|
||||
public void parse(Errors errors) {
|
||||
handleAssign(errors);
|
||||
while (getCurrToken().getType() == TokenType.COMMA) {
|
||||
addChild(new TokenNode(ts)); // comma
|
||||
handleAssign(errors);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleAssign(Errors errors) {
|
||||
LVal lval = new LVal(this.ts);
|
||||
lval.parse(errors);
|
||||
addChild(lval);
|
||||
addChild(new TokenNode(ts)); // assign
|
||||
Exp exp = new Exp(this.ts);
|
||||
exp.parse(errors);
|
||||
addChild(exp);
|
||||
}
|
||||
|
||||
public ArrayList<LVal> getLValList() {
|
||||
ArrayList<LVal> lvalList = new ArrayList<>();
|
||||
for (int i = 0; i < getChildren().size(); i++) {
|
||||
if (getChild(i) instanceof LVal) {
|
||||
lvalList.add((LVal) getChild(i));
|
||||
}
|
||||
}
|
||||
return lvalList;
|
||||
}
|
||||
|
||||
public ArrayList<Exp> getExpList() {
|
||||
ArrayList<Exp> expList = new ArrayList<>();
|
||||
for (int i = 0; i < getChildren().size(); i++) {
|
||||
if (getChild(i) instanceof Exp) {
|
||||
expList.add((Exp) getChild(i));
|
||||
}
|
||||
}
|
||||
return expList;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user