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


C# IEnvironment.Lookup方法代码示例

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


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

示例1: Analyze

        public IExpression Analyze(Object expr, IEnvironment env, Location enclosingLoc)
        {
            Symbol symbol = expr as Symbol;
            if (symbol != null) {
                if (symbol.IsDynamic)
                    return new DynamicVar(symbol);
                Object var = env.Lookup(symbol);
                if (var is LocalVariable)
                    return new LocalVar((LocalVariable)var);
                else
                    return new GlobalVar((Symbol)var);
            }
            if (!(expr is Cons))	 //must be literal
                return new QuoteExpr(expr);

            Cons exprs = (Cons)expr;

            Location loc = (Location)InnerReader.LocationTable[expr];
            if (loc != null)
                InnerReader.LocationTable.Remove(expr);
            else
                loc = enclosingLoc;

            Object f = exprs.First;
            Cons args = exprs.Rest;

            //see if it's a macro
            Symbol s = f as Symbol;
            if (s != null && s.IsDefined && s.GlobalValue is Macro) {
                Macro m = (Macro)s.GlobalValue;
                Object[] argarray = Cons.ToVector(args);
                Object mexprs = null;
                try {
                    mexprs = m.Invoke(argarray);
                } catch (Exception ex) {
                    BacktraceFrame frame = new BacktraceFrame(loc, s, args);
                    throw BacktraceException.Push(ex, frame, this);
                }
                try {
                    return Analyze(mexprs, env, loc);
                } catch (Exception ex) {
                    BacktraceFrame frame = new BacktraceFrame(loc, "when expanding ", exprs);
                    throw BacktraceException.Push(ex, frame, this);
                }
            }
            Int32 numargs = Cons.GetLength(args);

            if (f == DLET)
                return new DynamicLet(args, env, this, loc);
            else if (f == FN)
                return new Closure(args, env, this, loc);
            else if (f == MACRO)
                return new Macro(args, env, this, loc);
            else if (f == WHILE)
                return new WhileExpression(args, env, this, loc);
            else if (f == BLOCK) {
                if (numargs == 0)
                    return new QuoteExpr(null);
                //remove block from block of one
                else if (numargs == 1)
                    return Analyze(args.First, env, loc);
                else
                    return new BlockExpression(args, env, this, loc);
            } else if (f == OR) {
                if (numargs == 0)
                    return new QuoteExpr(null);
                else
                    return new OrExpression(args, env, this, loc);
            } else if (f == IF)
                return new IfExpression(args, env, this, loc);
            else if (f == QUOTE)
                return new QuoteExpr(args.First);
            else if (f == SET)
                return new SetExpression(args, env, this, loc);
            else	//presume funcall
                return new ApplyExpression(exprs, env, this, loc);
        }
开发者ID:Lovesan,项目名称:research-lisp,代码行数:77,代码来源:Interpreter.cs


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