Example #1
0
        /// 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);
            }
        }
Example #2
0
 public BinaryExprAST(char op, ExprAST lhs, ExprAST rhs) 
 {
     this.Op = op;
     this.LHS = lhs;
     this.RHS = rhs;
 }
Example #3
0
 public FunctionAST(PrototypeAST proto, ExprAST body)
 {
     this.Proto = proto;
     this.Body = body;
 }
Example #4
0
 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;
 }
Example #5
0
 public IfExprAST(ExprAST condExpr, ExprAST thenExpr, ExprAST elseExpr)
 {
     this.Cond = condExpr;
     this.Then = thenExpr;
     this.Else = elseExpr;
 }
Example #6
0
 public UnaryExprAST(char op, ExprAST operand)
 {
     this.Op = op;
     this.Operand = operand;
 }