本文整理汇总了C++中Environment::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Environment::add方法的具体用法?C++ Environment::add怎么用?C++ Environment::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment::add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
ASTNode *a = (ASTNode*)0x1;
ASTNode *b = (ASTNode*)0x2;
Environment *env = new Environment(0, "globl_env");
env->add("a", a);
env->add("a", a);
env->add("b", b);
ASTNode* n = env->lookup("b");
if (n)
printf("n: %p\n", n);
else
printf("cannot found\n");
Environment *f1_env = new Environment(env, "f1_env");
ASTNode *fa = (ASTNode*)0x11;
ASTNode *fb = (ASTNode*)0x22;
f1_env->add("a", fa);
f1_env->add("b", fb);
n = f1_env->lookup("b");
if (n)
printf("n: %p\n", n);
else
printf("cannot found\n");
return 0;
}
示例2: assign
void ExpressionCallWithNamedParameters::assign(Environment &env, Co<Expression> value) const {
if (bindings.size() > 0) {
Expression::assign(env, value);
} else {
Co<ExpressionDefine> define = Co<ExpressionDefine>(new ExpressionDefine(name, value));
env.add(name, Co<ExpressionClosure>(new ExpressionClosure(define, env)));
}
}
示例3: initialize
ReaderClass* initialize()
{
// initialize global variables
ReaderClass* reader = new LispReader;
// initialize the value of true
Symbol* truesym = new Symbol("T");
trueExpr = truesym;
falseExpr = emptyList();
// initialize the commands environment
Environment* cmds = commands;
cmds->add(new Symbol("set"), new SetStatement);
// initialize the global environment
Environment* ge = globalEnvironment;
ge->add(new Symbol("if"), new IfStatement);
ge->add(new Symbol("+"), new IntegerBinaryFunction(PlusFunction));
ge->add(new Symbol("-"), new IntegerBinaryFunction(MinusFunction));
ge->add(new Symbol("*"), new IntegerBinaryFunction(TimesFunction));
ge->add(new Symbol("/"), new IntegerBinaryFunction(DivideFunction));
ge->add(new Symbol("="), new BinaryFunction(EqualFunction));
ge->add(new Symbol("<"), new BooleanBinaryFunction(LessThanFunction));
ge->add(new Symbol(">"), new BooleanBinaryFunction(GreaterThanFunction));
ge->add(new Symbol("cons"), new SaslConsFunction);
ge->add(new Symbol("car"), new UnaryFunction(CarFunction));
ge->add(new Symbol("cdr"), new UnaryFunction(CdrFunction));
ge->add(new Symbol("number?"), new BooleanUnary(NumberpFunction));
ge->add(new Symbol("symbol?"), new BooleanUnary(SymbolpFunction));
ge->add(new Symbol("list?"), new BooleanUnary(ListpFunction));
ge->add(new Symbol("null?"), new BooleanUnary(NullpFunction));
ge->add(new Symbol("primop?"), new BooleanUnary(PrimoppFunction));
ge->add(new Symbol("closure?"), new BooleanUnary(ClosurepFunction));
ge->add(new Symbol("print"), new UnaryFunction(PrintFunction));
ge->add(new Symbol("lambda"), new LambdaFunction);
ge->add(truesym, truesym);
ge->add(new Symbol("nil"), emptyList());
return reader;
}
示例4: initialize
/// APLInitialize
ReaderClass* initialize()
{
// initialize global variables
ReaderClass* reader = new APLreader;
// initialize the statement environment
Environment* cmds = commands;
cmds->add(new Symbol("define"), new DefineStatement);
// initialize the value ops environment
Environment* vo = valueOps;
vo->add(new Symbol("if"), new IfStatement);
vo->add(new Symbol("begin"), new BeginStatement);
vo->add(new Symbol("set"), new SetStatement);
vo->add(new Symbol("+"), new APLScalarFunction(PlusFunction));
vo->add(new Symbol("-"), new APLScalarFunction(MinusFunction));
vo->add(new Symbol("*"), new APLScalarFunction(TimesFunction));
vo->add(new Symbol("/"), new APLScalarFunction(DivideFunction));
vo->add(new Symbol("max"), new APLScalarFunction(scalarMax));
vo->add(new Symbol("or"), new APLScalarFunction(scalarOr));
vo->add(new Symbol("and"), new APLScalarFunction(scalarAnd));
vo->add(new Symbol("="), new APLScalarFunction(scalarEq));
vo->add(new Symbol("<"), new APLScalarFunction(LessThanFunction));
vo->add(new Symbol(">"), new APLScalarFunction(GreaterThanFunction));
vo->add(new Symbol("+/"), new APLReduction(PlusFunction));
vo->add(new Symbol("-/"), new APLReduction(MinusFunction));
vo->add(new Symbol("*/"), new APLReduction(TimesFunction));
vo->add(new Symbol("//"), new APLReduction(DivideFunction));
vo->add(new Symbol("max/"), new APLReduction(scalarMax));
vo->add(new Symbol("or/"), new APLReduction(scalarOr));
vo->add(new Symbol("and/"), new APLReduction(scalarAnd));
vo->add(new Symbol("compress"), new CompressionFunction);
vo->add(new Symbol("shape"), new ShapeFunction);
vo->add(new Symbol("ravel"), new RavelFunction);
vo->add(new Symbol("restruct"), new RestructFunction);
vo->add(new Symbol("cat"), new CatenationFunction);
vo->add(new Symbol("indx"), new IndexFunction);
vo->add(new Symbol("trans"), new TransposeFunction);
vo->add(new Symbol("[]"), new SubscriptFunction);
vo->add(new Symbol("print"), new UnaryFunction(PrintFunction));
return reader;
}