llvmir some opt
This commit is contained in:
44
frontend/ast/exp/LOrExp.java
Normal file
44
frontend/ast/exp/LOrExp.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package frontend.ast.exp;
|
||||
|
||||
import frontend.ast.Node;
|
||||
import frontend.ast.NodeStack;
|
||||
import frontend.ast.SyntaxType;
|
||||
import frontend.lexer.TokenStream;
|
||||
import frontend.lexer.TokenType;
|
||||
import frontend.ast.token.TokenNode;
|
||||
import error.Errors;
|
||||
|
||||
public class LOrExp extends Node {
|
||||
public LOrExp(TokenStream ts) {
|
||||
super(SyntaxType.LOR_EXP, ts);
|
||||
}
|
||||
|
||||
public void parse(Errors errors) {
|
||||
NodeStack stack = new NodeStack();
|
||||
while (true) {
|
||||
LAndExp andexp = new LAndExp(this.ts);
|
||||
andexp.parse(errors);
|
||||
stack.push(andexp);
|
||||
if (getCurrToken().getType() == TokenType.OR) {
|
||||
stack.push(new TokenNode(ts)); // lorop
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (stack.size() == 1) {
|
||||
this.addChild((LAndExp)stack.pop());
|
||||
} else {
|
||||
LOrExp temp = this;
|
||||
while(stack.size() > 1) {
|
||||
LOrExp loe = new LOrExp(this.ts);
|
||||
LAndExp lae = (LAndExp)stack.pop();
|
||||
TokenNode lorop = (TokenNode)stack.pop();
|
||||
temp.addChild(loe);
|
||||
temp.addChild(lorop);
|
||||
temp.addChild(lae);
|
||||
temp = loe;
|
||||
}
|
||||
temp.addChild((LAndExp)stack.pop());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user