/// binoprhs /// ::= ('+' primary)* private ExprAST ParseBinOpRHS(int exprPrec, ExprAST lhs) { // If this is a binop, find its precedence. while(true) { int tokPrec = GetTokenPrecedence(); // If this is a binop that binds at least as tightly as the current binop, // consume it, otherwise we are done. if(tokPrec < exprPrec) return lhs; // Okay, we know this is a binop. char binOp = m_token.IdentiferText[0]; GetNextToken(); // Parse the unary expression after the binary operator. ExprAST rhs = ParseUnary(); if(rhs == null) return null; // If BinOp binds less tightly with RHS than the operator after RHS, let // the pending operator take RHS as its LHS. int nextPrec = GetTokenPrecedence(); if(tokPrec < nextPrec) { rhs = ParseBinOpRHS(tokPrec + 1, rhs); if(rhs == null) return null; } // Merge LHS/RHS. lhs = new BinaryExprAST(binOp, lhs, rhs); } }
public BinaryExprAST(char op, ExprAST lhs, ExprAST rhs) { this.Op = op; this.LHS = lhs; this.RHS = rhs; }
public FunctionAST(PrototypeAST proto, ExprAST body) { this.Proto = proto; this.Body = body; }
public ForExprAST(string varName, ExprAST startExpr, ExprAST endExpr, ExprAST stepExpr, ExprAST bodyExpr) { this.VarName = varName; this.Start = startExpr; this.End = endExpr; this.Step = stepExpr; this.Body = bodyExpr; }
public IfExprAST(ExprAST condExpr, ExprAST thenExpr, ExprAST elseExpr) { this.Cond = condExpr; this.Then = thenExpr; this.Else = elseExpr; }
public UnaryExprAST(char op, ExprAST operand) { this.Op = op; this.Operand = operand; }