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


C# Node.eval方法代码示例

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


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

示例1: checkTrue

 public Boolean checkTrue(Node cond, Environment e)
 {
     Node check = cond.eval(cond, e);
     if (check.isBool() == true)
     {
         BoolLit boolVal = (BoolLit) check;
         return boolVal.getVal();
     }
     return true;
 }
开发者ID:sbaldw2,项目名称:CSC4101,代码行数:10,代码来源:If.cs

示例2: apply2

 private Node apply2(Node arg1, Node arg2)
 {
     string name = this.symbol.getName();
     bool flag = name.Equals("eq?");
     Node result;
     if (flag)
     {
         bool flag2 = arg1.isSymbol() && arg2.isSymbol();
         if (flag2)
         {
             string name2 = arg1.getName();
             string name3 = arg2.getName();
             result = BoolLit.getInstance(name2.Equals(name3));
         }
         else
         {
             result = BoolLit.getInstance(arg1 == arg2);
         }
     }
     else
     {
         bool flag3 = name.Equals("cons");
         if (flag3)
         {
             result = new Cons(arg1, arg2);
         }
         else
         {
             bool flag4 = name.Equals("set-car!");
             if (flag4)
             {
                 arg1.setCar(arg2);
                 result = Unspecific.getInstance();
             }
             else
             {
                 bool flag5 = name.Equals("set-cdr!");
                 if (flag5)
                 {
                     arg1.setCdr(arg2);
                     result = Unspecific.getInstance();
                 }
                 else
                 {
                     bool flag6 = name.Equals("eval");
                     if (flag6)
                     {
                         bool flag7 = arg2.isEnvironment();
                         if (flag7)
                         {
                             result = arg1.eval((Environment)arg2);
                         }
                         else
                         {
                             Console.Error.WriteLine("Error: wrong type of argument");
                             result = Nil.getInstance();
                         }
                     }
                     else
                     {
                         bool flag8 = name.Equals("apply");
                         if (flag8)
                         {
                             result = arg1.apply(arg2);
                         }
                         else
                         {
                             bool flag9 = name[0] == 'b' && name.Length == 2;
                             if (flag9)
                             {
                                 bool flag10 = arg1.isNumber() && arg2.isNumber();
                                 if (flag10)
                                 {
                                     result = this.apply2(arg1.getIntVal(), arg2.getIntVal());
                                 }
                                 else
                                 {
                                     Console.Error.WriteLine("Error: invalid arguments");
                                     result = Nil.getInstance();
                                 }
                             }
                             else
                             {
                                 Console.Error.WriteLine("Error: wrong number of arguments");
                                 result = Nil.getInstance();
                             }
                         }
                     }
                 }
             }
         }
     }
     return result;
 }
开发者ID:Profitlol,项目名称:prog2-baum,代码行数:94,代码来源:BuiltIn.cs

示例3: Main

    public static int Main(string[] args)
    {
        // Create scanner that reads from standard input
        Scanner scanner = new Scanner(Console.In);

        if (args.Length > 1 ||
            (args.Length == 1 && ! args[0].Equals("-d")))
        {
            Console.Error.WriteLine("Usage: mono SPP [-d]");
            return 1;
        }

        // If command line option -d is provided, debug the scanner.
        if (args.Length == 1 && args[0].Equals("-d"))
        {
            // Console.Write("Scheme 4101> ");
            Token tok = scanner.getNextToken();
            while (tok != null)
            {
                TokenType tt = tok.getType();

                Console.Write(tt);
                if (tt == TokenType.INT)
                    Console.WriteLine(", intVal = " + tok.getIntVal());
                else if (tt == TokenType.STRING)
                    Console.WriteLine(", stringVal = " + tok.getStringVal());
                else if (tt == TokenType.IDENT)
                    Console.WriteLine(", name = " + tok.getName());
                else
                    Console.WriteLine();

                // Console.Write("Scheme 4101> ");
                tok = scanner.getNextToken();
            }
            return 0;
        }

        // Create parser
        TreeBuilder builder = new TreeBuilder();
        Parser parser = new Parser(scanner, builder);
        Node root = new Node();

        // TODO: Create and populate the built-in environment and
        // create the top-level environment
        Tree.Environment env = new Tree.Environment();
        Ident id = new Ident("b+");
        env.define(id, new BuiltIn(id));
        env = new Tree.Environment(env);

        Ident test = new Ident("xxxx");
        IntLit test2 = new IntLit(3);

        env.define(test, test2);

        root = (Node) parser.parseExp();
        while (root != null)
        {
            root.eval(env).print(0);
            root = (Node) parser.parseExp();
        }

        // Read-eval-print loop

        // TODO: print prompt and evaluate the expression
        /*
        root = (Node) parser.parseExp();
        while (root != null)
        {
            root.print(0);
            root = (Node) parser.parseExp();
        }
        */

        return 0;
    }
开发者ID:RanNPC,项目名称:Prog2,代码行数:75,代码来源:Scheme4101.cs


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