本文整理汇总了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;
//.........这里部分代码省略.........