当前位置: 首页>>代码示例>>C++>>正文


C++ ExprAST::print方法代码示例

本文整理汇总了C++中ExprAST::print方法的典型用法代码示例。如果您正苦于以下问题:C++ ExprAST::print方法的具体用法?C++ ExprAST::print怎么用?C++ ExprAST::print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExprAST的用法示例。


在下文中一共展示了ExprAST::print方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: transform_to_lambda_calculus

ExprAST* transform_to_lambda_calculus(ExprAST* expr)
{
    switch(expr->getAST_Type())
    {
    //Non-Lambda
    case ExprAST::Function:
    {
        FunctionAST* func = (FunctionAST*)expr;

        std::cout << "Before Lambda-Calculus Conversion: " << std::endl;
        func->print();

        LambdaAST* lambda;
        std::vector<PrototypeAST*> protos;

        if(func->proto->args.size()>0)
        {
            for(int i=0;i<func->proto->args.size();++i)
            {
                std::vector<std::string> args;
                args.push_back(func->proto->args.at(i));
                PrototypeAST* proto = new PrototypeAST("",args);
                proto = new PrototypeAST("",args);
                protos.push_back(proto);
            }

            for(int i=protos.size()-1;i>=0;i-=1)
            {
                if(i<protos.size()-1)
                {
                    lambda = new LambdaAST(protos.at(i),lambda);
                }
                else
                {
                    ExprAST* lambda_body = transform_to_lambda_calculus(func->body);
                    lambda = new LambdaAST(protos.at(i),lambda_body);
                }
            }
        }
        else
        {
            std::vector<std::string> args;
            PrototypeAST* proto = new PrototypeAST("",args);
            ExprAST* lambda_body = transform_to_lambda_calculus(func->body);
            lambda = new LambdaAST(proto,lambda_body);
        }

        LetAST* let = new LetAST(func->proto->name,lambda);
        std::cout << "After Lambda-Calculus Conversion: " << std::endl;
        let->print();

        return let;
    }
        break;
    case ExprAST::FunctionCall:
    {
        CallExprAST* func_call = (CallExprAST*)expr;

        std::cout << "Before Lambda-Calculus Conversion: " << std::endl;
        func_call->print();
        std::cout << std::endl;

        ExprAST* apply = new VariableExprAST(func_call->callee);

        for(int i=0;i<func_call->args.size();++i)
        {
            ExprAST* transformed_arg = transform_to_lambda_calculus(func_call->args.at(i));
            apply = new ApplyAST(apply,transformed_arg);
        }

        std::cout << "After Lambda-Calculus Conversion: " << std::endl;
        apply->print();
        std::cout << std::endl;

        return apply;
    }
        break;
    case ExprAST::BinaryOp:
    {
        BinaryExprAST* bin_op = (BinaryExprAST*)expr;
        ExprAST* lhs = transform_to_lambda_calculus(bin_op->lhs);
        ExprAST* rhs = transform_to_lambda_calculus(bin_op->rhs);
        return new BinaryExprAST(bin_op->op,lhs,rhs);
    }
    case ExprAST::Number:
    case ExprAST::Char:
    case ExprAST::True:
    case ExprAST::False:
    case ExprAST::Variable:
        //Lambda
    case ExprAST::Lambda:
    case ExprAST::Let:
    case ExprAST::LetRec:
    case ExprAST::Apply:
        return expr;
    case ExprAST::Prototype:
        out() << "Error Parsing AST, received PrototypeExprAST in lambda calculus conversion." << std::endl;
        correct_parsing = false;
        return expr;

//.........这里部分代码省略.........
开发者ID:GlitchLich,项目名称:Panopticon,代码行数:101,代码来源:parse_ast.cpp


注:本文中的ExprAST::print方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。