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 LAndExp extends Node { public LAndExp(TokenStream ts) { super(SyntaxType.LAND_EXP, ts); } public void parse(Errors errors) { NodeStack stack = new NodeStack(); while (true) { EqExp eep = new EqExp(this.ts); eep.parse(errors); stack.push(eep); if (getCurrToken().getType() == TokenType.AND) { stack.push(new TokenNode(ts)); // landop } else { break; } } if (stack.size() == 1) { this.addChild((EqExp)stack.pop()); } else { LAndExp temp = this; while(stack.size() > 1) { LAndExp lae = new LAndExp(this.ts); EqExp eep = (EqExp)stack.pop(); TokenNode landop = (TokenNode)stack.pop(); temp.addChild(lae); temp.addChild(landop); temp.addChild(eep); temp = lae; } temp.addChild((EqExp)stack.pop()); } } }