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


C# SymbolTable.GetSymbolCount方法代码示例

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


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

示例1: Compile

        static IASTNode Compile(SymbolTable symTable, object exp)
        {
            if (exp is string) {
                string name = (string)exp;
                if (symTable != null && symTable.Lookup(name) != -1) {
                    return new ASTNode_GetLocalVar(){Index=symTable.Lookup(name)};
                }

                int envIndex = 0;
                for (; symTable != null && symTable.Lookup(name) == -1; symTable = symTable.PrevTalbe, ++envIndex);

                if (symTable == null) {
                    return new ASTNode_GetGlobalVar(){Index=GlobalSymbolTable.Instance().LookupOrDefine(name)};
                } else {
                    return new ASTNode_GetFreeVar(){EnvIndex=envIndex, Index=symTable.Lookup(name)};
                }
            } else if (!(exp is List<object>)) {
                return new ASTNode_Literal(){Value=exp};
            }

            List<object> l = (List<object>)exp;
            switch (l[0] as string) {
                case "quote":
                    return new ASTNode_Literal() { Value = ListExpToPairExp(l[1]) };
                case "if":
                    return new ASTNode_If() { PredNode = Compile(symTable, l[1]), ThenNode = Compile(symTable, l[2]), ElseNode = Compile(symTable, l[3]) };
                case "lambda": {
                        SymbolTable newSymTable = new SymbolTable(symTable);
                        foreach (string name in ((List<object>)l[1])) {
                            newSymTable.Define(name);
                        }

                        List<string> defines = new List<string>();
                        FindDefinition(defines, (List<object>)l[2], 1);
                        foreach (string name in defines) {
                            newSymTable.Define(name);
                        }

                        return new ASTNode_Lambda() { LocalVarCount = newSymTable.GetSymbolCount(), BodyNode = Compile(newSymTable, l[2]) };
                    }
                case "begin":
                    return new ASTNode_Begin() { Nodes = l.Skip(1).Select(e => Compile(symTable, e)).ToArray() };
                case "define":
                    return Compile(symTable, new List<object>() { "set!", l[1], l[2] });
                case "set!": {
                        IASTNode right = Compile(symTable, l[2]);

                        string name = (string)l[1];
                        if (symTable != null && symTable.Lookup(name) != -1) {
                            return new ASTNode_SetLocalVar() { Index = symTable.Lookup(name), RightNode = right };
                        }

                        int envIndex = 0;
                        for (; symTable != null && symTable.Lookup(name) == -1; symTable = symTable.PrevTalbe, ++envIndex) ;

                        if (symTable == null) {
                            return new ASTNode_SetGlobalVar() { Index = GlobalSymbolTable.Instance().LookupOrDefine(name), RightNode = right };
                        } else {
                            return new ASTNode_SetFreeVar() { EnvIndex = envIndex, Index = symTable.Lookup(name), RightNode = right };
                        }
                    }
                default: {
                        return new ASTNode_Application() { ProcedureNode = Compile(symTable, l[0]), ActualNodes = l.Skip(1).Select(e => Compile(symTable, e)).ToArray() };
                    }
            }
        }
开发者ID:GHScan,项目名称:DailyProjects,代码行数:66,代码来源:Program.cs


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