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 EqExp extends Node { public EqExp(TokenStream ts) { super(SyntaxType.EQ_EXP, ts); } public void parse(Errors errors) { NodeStack stack = new NodeStack(); while (true) { RelExp relexp = new RelExp(this.ts); relexp.parse(errors); stack.push(relexp); if (isEqOp()) { stack.push(new TokenNode(ts)); // eqop } else { break; } } if(stack.size() == 1) { this.addChild((RelExp)stack.pop()); } else { EqExp temp = this; while (stack.size() > 1) { EqExp eep = new EqExp(this.ts); RelExp relexp = (RelExp)stack.pop(); TokenNode eqop = (TokenNode)stack.pop(); temp.addChild(eep); temp.addChild(eqop); temp.addChild(relexp); temp = eep; } temp.addChild((RelExp)stack.pop()); } } public boolean isEqOp() { TokenType t = getCurrToken().getType(); return t == TokenType.EQL || t == TokenType.NEQ; } }