當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。