Exemplo n.º 1
0
 public BinaryExprAST(char op, ExprAST lhs, ExprAST rhs) 
 {
     this.Op = op;
     this.LHS = lhs;
     this.RHS = rhs;
 }
Exemplo n.º 2
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 primary expression after the binary operator.
                ExprAST rhs = ParsePrimary();
                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);
            }
        }
Exemplo n.º 3
0
 public FunctionAST(PrototypeAST proto, ExprAST body)
 {
     this.Proto = proto;
     this.Body = body;
 }