本文整理汇总了C++中Proc::apply方法的典型用法代码示例。如果您正苦于以下问题:C++ Proc::apply方法的具体用法?C++ Proc::apply怎么用?C++ Proc::apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Proc
的用法示例。
在下文中一共展示了Proc::apply方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
StmtList *SL, *SL1;
Stmt *S1, *S2, *S3, *S4, *S5, *S6;
Expr *E;
// statement list for Add function
S1 = new AssignStmt("i",new Ident("n"));
S2 = new AssignStmt("s",new Number(0));
S3 = new AssignStmt("s",
new Plus(new Ident("s"), new Ident("i")));
S4 = new AssignStmt("i",
new Minus(new Ident("i"), new Number(1)));
SL1 = new StmtList();
SL1->insert(S4); SL1->insert(S3);
E = new Ident("i");
S5 = new WhileStmt(E,SL1);
S6 = new AssignStmt("return", new Ident("s"));
SL = new StmtList();
SL->insert(S6); SL->insert(S5); SL->insert(S2); SL->insert(S1);
cout << "Add(n)" << endl;
cout << "i := n; s := 0;" << endl;
cout << "while i do s := s+i; i := i-1 od;" << endl;
cout << "return := s" << endl;
Proc *Add;
list<string> *paramlist;
paramlist = new list<string>;
paramlist->push_front("n");
cout << "Creating function" << endl;
Add = new Proc(paramlist,SL);
map<string,int> NT;
map<string,Proc*> FT;
NT.clear(); FT.clear();
FT["add"] = Add;
list<Expr*> *arglist;
Expr *E1;
int n;
cout << "Enter n: ";
cin >> n;
E1 = new Number(n);
arglist = new list<Expr*>;
arglist->push_front(E1);
cout << "Calling function" << endl;
cout << "Add(" << E1->eval(NT,FT) << ") = ";
cout << Add->apply(NT,FT,arglist) << endl;
return 0;
}