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


C# Node.getCar方法代码示例

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


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

示例1: print

        public override void print(Node t, int n, bool p)
        {
            if (!p)
            {
                var spaces = "";
                if (n >= 0) spaces = new string(' ', n);
                Console.Write(spaces + "(if ");
                if (t.getCdr().getCar().isPair())
                {
                    if((t.getCdr().getCar() as Cons).form is If ||
                        (t.getCdr().getCar() as Cons).form is Lambda ||
                        (t.getCdr().getCar() as Cons).form is Define)
                    t.getCdr().getCar().print(n+4, true);
                    else
                    {
                        t.getCdr().getCar().print(0, false);
                    }

                }
                else
                    t.getCdr().getCar().print(0, false);
                t = t.getCdr().getCdr();
                do
                {
                    Console.WriteLine("");
                    t.getCar().print(n + 4, false);
                    t = t.getCdr();
                } while (t.getCdr() != null);
                Console.WriteLine("");
                t.print(n, true);
            }
            else
            {
                var spaces = "";
                if (n >= 0) spaces = new string(' ', n);
                Console.Write("(if ");
                if (t.getCdr().getCar().isPair())
                {
                    if ((t.getCdr().getCar() as Cons).form is If ||
                        (t.getCdr().getCar() as Cons).form is Lambda ||
                        (t.getCdr().getCar() as Cons).form is Define)
                        t.getCdr().getCar().print(n+4, true);
                    else
                    {
                        t.getCdr().getCar().print(0, false);
                    }

                }
                t.getCdr().getCar().print(0, false);
                t = t.getCdr().getCdr();
                do
                {
                    Console.WriteLine("");
                    t.getCar().print(n + 4, false);
                    t = t.getCdr();
                } while (t.getCdr() != null);
                Console.WriteLine("");
                t.print(n, true);
            }
        }
开发者ID:tlecom3,项目名称:4101_prog1,代码行数:60,代码来源:If.cs

示例2: eval

 public override Node eval(Node t, Environment e)
 {
     if(t.getCdr() is Closure)
         return e.lookup(t.getCar()).apply(t.getCdr());
     else
     {
         Node args = t.getCdr();
         Node param;
         if (args.getCar().isSymbol())
             param = new Cons(e.lookup((Node)args.GetCar()), Nil.getInstance());
         else
             param = new Cons((Node)args.GetCar(), Nil.getInstance());
         Node currentNode = param;
         args = args.getCdr();
         while (args != Nil.getInstance())
         {
             if (args.getCar().isSymbol())
                 currentNode.setCdr(new Cons(e.lookup(args.getCar()), Nil.getInstance()));
             else
                 currentNode.setCdr(new Cons(args.getCar(), Nil.getInstance()));
             currentNode = currentNode.getCdr();
             args = args.getCdr();
         }
         return e.lookup(t.getCar()).apply(param);
     }
 }
开发者ID:Lumenze,项目名称:4101_prog2,代码行数:26,代码来源:Regular.cs

示例3: apply

 // TODO: The method apply() should be defined in class Node
 // to report an error.  It should be overridden only in classes
 // BuiltIn and Closure.
 //public /* override */ Node apply (Node args)
 //{
 //     return new StringLit("Error: BuiltIn.apply not yet implemented");
 //}
 public override Node apply(Node args)
 {
     int num = Util.expLength(args);
     bool flag = num > 2;
     if (flag)
     {
         Console.Error.WriteLine("Error: wrong number of arguments");
     }
     bool flag2 = num == 0; // length 0 arguments
     Node result;
     if (flag2)
     {
         result = this.apply0();
     }
     else //1 or 2 argument lengths
     {
         bool flag3 = num == 1; // length 1 arguments
         if (flag3)
         {
             result = this.apply1(args.getCar());
         }
         else
         {
             result = this.apply2(args.getCar(), args.getCdr().getCar());
         }
     }
     return result;
 }
开发者ID:Profitlol,项目名称:prog2-baum,代码行数:35,代码来源:BuiltIn.cs

示例4: evalLetBody

        public Node evalLetBody(Node t, Environment env)
        {
            if(t == Nil.getInstance()) //This isn't correct. What do?
            {
                Node l = new Cons(new Nil(), new Nil()); //tree with pair of ()
                return l;
            }
            else
            {
                Node restBody = t.getCdr();
                Node variable = t.getCar().getCar();
                Node value = t.getCar().getCdr().getCar();

                if(variable.isSymbol()) //was value earlier, should be variable?
                {
                    env.define(variable,value.eval(env));
                    return evalLetBody(restBody, env);
                }
                else if(!variable.isPair()) //if it is a cons node. ???
                {
                    Console.Write("Error in Let->evalLetBody, variable is not valid");
                    return new Nil();

                }
                else if(variable.isNull())
                {
                    return new Nil();
                }
                else
                {
                    return variable.eval(env);
                }
            }
        }
开发者ID:hcross2,项目名称:4330-Project-2,代码行数:34,代码来源:Let.cs

示例5: print

        public override void print(Node t, int n, bool p)
        {
            Console.Write("".PadLeft(n));
               if ( p != true)
               {
               Console.Write("(");
               }
               if(t.getCar().isPair())
               {
               t.getCar().print(0);
               }
               else
               {
               t.getCar().print(0, true);
               }
               Console.Write(" ");

            if(t.getCdr() is Nil)
            {
                Console.WriteLine(")");
            }
            else
            {
                t.getCdr().print(0, true);
            }
            //  Console.WriteLine();
        }
开发者ID:CSC4101Projects,项目名称:Project1,代码行数:27,代码来源:Set.cs

示例6: print

        public override void print(Node t, int n, bool p)
        {
            // print leading spaces and '('
            if (n < 0)
            {
                n = -(n + 1);
            }
            Console.Write(new string(' ', n) + "(");
            // record the current indent
            // common out due to CursorLeft is not supported in mono
            //int indent = Console.CursorLeft - 1;
            pcount++;
            // first element is parinted with no leading space, no change line
            t.getCar().print(-1);
            // if 'if' is the only element (if) or (if . x)
            if(!t.getCdr().isPair())
            {
                pcount--;
                if (t.getCdr().isNull())
                {
                    t.getCdr().print(0, true);
                }
                else
                {
                    Console.Write(" . ");
                    t.getCdr().print(0);
                }
                return;
            }
            // second element is printed with 1 leading space, change line
            else
            {
                t = t.getCdr();
                t.getCar().print(1);
            }
            // following element is printed with further indent, change line
            while (t.getCdr().isPair())
            {
                t = t.getCdr();
                t.getCar().print(pcount * 4);
            }
            // print last element and ')'
            pcount--;
            if (t.getCdr().isNull())
            {
                // ')' is printed with indent, change line
                t.getCdr().print(pcount * 4, true);
            }
            else
            {
                Console.Write(new string(' ', pcount * 4) + ". ");
                t.getCdr().print(0);
                Console.WriteLine(new string(' ', pcount * 4) + ")");
            }


        }
开发者ID:jktucn,项目名称:SchemePrettyPrinter,代码行数:57,代码来源:If.cs

示例7: eval

 public override Node eval(Node t, Environment env)
 {
     t = t.getCdr();
     while (!t.getCdr().isNull())
     {
         t.getCar().eval(env);
         t = t.getCdr();
     }
     return t.getCar().eval(env); //unsure if this is actual value or just the node
 }
开发者ID:hcross2,项目名称:4330-Project-2,代码行数:10,代码来源:Begin.cs

示例8: print

 public override void print(Node t, int n, bool p)
 {
     // print leading spaces and '('
     if (n < 0)
     {
         n = -(n + 1);
     }
     Console.Write(new string(' ', n) + "(");
     // counting the number of unclosed '('
     pcount++;
     // print the first element after '(', with no leading space no change line 
     t.getCar().print(-1);
     // print the following element, until Nil or a non-list at cdr
     while (t.getCdr().isPair())
     {
         t = t.getCdr();
         // print a space before print an element
         Console.Write(" ");
         t.getCar().print(-1);
     }
     // going to print Nil or a non-list at cdr, change the number of unclosed '('
     pcount--;
     // last element is Nil
     if (t.getCdr().isNull())
     {
         // regular expression is not finished when pcount > 0
         if (pcount > 0)
         {
             t.getCdr().print(-1, true);
             // if n > 0, there is indent, so change line after the sub-expression
             if (n > 0)
             {
                 Console.WriteLine();
             }
         }
         // regular expression is finished, change line after the print
         else
         {
             t.getCdr().print(0, true);
         }
     }
     // last elemet is a non-list at cdr
     else
     {
         Console.Write(" . ");
         t.getCdr().print(-1);
         Console.Write(")");
         if (pcount == 0 || n > 0)
         {
             Console.WriteLine();
         }
     }
 }
开发者ID:jktucn,项目名称:SchemePrettyPrinter,代码行数:53,代码来源:Regular.cs

示例9: print

 public override void print(Node t, int n, bool p)
 {
     var spaces = new string(' ', n);
     Console.Write(spaces + "\'");
     t = t.getCdr();
     do
     {
         if (t.getCar().isPair())
         {
             (t .getCar() as Cons).form = new Regular();
         }
         t.getCar().print(0);
         t = t.getCdr();
     } while (t.getCdr() != null);
 }
开发者ID:tlecom3,项目名称:4101_prog1,代码行数:15,代码来源:Quote.cs

示例10: print

        public override void print(Node t, int n, bool p)
        {
            for (int i = Console.CursorLeft; i < n; i++)
                Console.Write(" ");

            if (!p)
                Console.Write("(");
            //Print "lambda"
            t.getCar().print(n);
            Console.Write(" ");

            Node second = t.getCdr().getCar();
            if (second.isPair())
            {
                second.print(n, false);
            }
            Console.WriteLine();
            Node term = t.getCdr().getCdr();
            while(!term.isNull())
            {
                term.getCar().print(n + 4);
                term = term.getCdr();
                Console.WriteLine();
            }
            Nil.getNil().print(n,true);
        }
开发者ID:matthewjwolff,项目名称:SchemePrettyPrinter,代码行数:26,代码来源:Lambda.cs

示例11: print

 public override void print(Node t, int n, bool p)
 {
     for (int i = Console.CursorLeft; i < n; i++)
         Console.Write(" ");
     if (!p)
     {
         Console.Write("(");
     }
     //print "let"
     t.getCar().print(n);
     Console.WriteLine();
     Node rest = t.getCdr();
     if (rest.isPair())
     {
         rest.getCar().print(n + 4, false);
         Console.WriteLine();
         while ((rest = rest.getCdr()) != Nil.getNil())
         {
             rest.getCar().print(n + 4, false);
             Console.WriteLine();
         }
         Console.Write(")");
     }
     else t.getCdr().print(n, true);
 }
开发者ID:matthewjwolff,项目名称:SchemePrettyPrinter,代码行数:25,代码来源:Let.cs

示例12: apply

 // TODO: The method apply() should be defined in class Node
 // to report an error.  It should be overridden only in classes
 // BuiltIn and Closure.
 public override Node apply (Node args)
 {
     Node param = fun.getCdr().getCar();
     int numArgs = Util.expLength(args);
     int numParam = Util.expLength(param);
     if (numArgs != numParam)
     {
         Console.Error.WriteLine("Error: wrong number of arguments");
     }
     Environment env1 = new Environment(env);
     while (param.isPair() && args.isPair())
     {
         Node id = param.getCar();
         Node val = args.getCar();
         env1.define(id, val);
         param = param.getCdr();
         args = args.getCdr();
     }
     while (param.isPair())
     {
         Node id = param.getCar();
         Node val = Nil.getInstance();
         env1.define(id, val);
         param = param.getCdr();
     }
     Node exp1 = fun.getCdr().getCdr();
     return Begin.evalBody(exp1, env1);
 }
开发者ID:jktucn,项目名称:SchemeInterpreter,代码行数:31,代码来源:Closure.cs

示例13: print

        public override void print(Node t, int n, bool p)
        {
            // TODO: Implement this function.
            //  Console.Write("".PadLeft(n));
            if (!p)
            {
                Console.Write("".PadLeft(n) + '(');
            }
            t.getCar().print(0, !p);
            //  if(!t.getCdr().isNull())
            //  {
            //      Console.Write(" ");
            //  }
            if(t.getCdr().isNull())
            {
                t.getCdr().print(0, true);
                //  Console.WriteLine();
            }
            else {
                Console.Write(" ");
                t.getCdr().print(n, true);
            }

            //  if(t.getCdr().isNull())
            //  {
            //      Console.WriteLine();
            //  }
        }
开发者ID:CSC4101Projects,项目名称:Project1,代码行数:28,代码来源:Regular.cs

示例14: evalCond

 public static Node evalCond(Node exp, Environment env)
 {
     Node list, test, body;
     while (exp.getCdr().isPair())
     {
         list = exp.getCar();
         test = list.getCar();
         body = list.getCdr();
         // else in the middle
         if (test.isSymbol() && test.getName().Equals("else"))
         {
             Console.Error.WriteLine("Error: invalid expression");
             return Nil.getInstance();
         }
         if (test.eval(env) != BoolLit.getInstance(false))
         {
             if (!body.isNull())
             {
                 return Begin.evalBody(body, env);
             }
             return test;
         }
         exp = exp.getCdr();
     }
     // last test case
     list = exp.getCar();
     test = list.getCar();
     body = list.getCdr();
     if (test.isSymbol() && test.getName().Equals("else"))
     {
         if (!body.isNull())
         {
             return Begin.evalBody(body, env);
         }
         Console.Error.WriteLine("Error: invalid expression");
         return Nil.getInstance();
     }
     if (test.eval(env) != BoolLit.getInstance(false))
     {
         if (!body.isNull())
         {
             return Begin.evalBody(body, env);
         }
         return test;
     }
     return Unspecific.getInstance();
 }
开发者ID:jktucn,项目名称:SchemeInterpreter,代码行数:47,代码来源:Cond.cs

示例15: print

        // Boolean p - true if left parenthesis HAS BEEN PRINTED
        //             false if '(' has not been printed
        public override void print(Node t, int n, bool p)
        {
            if (!p) {                   // If '(' has not been printed
                Console.Write("(");     // Print one
            }

            // Regulate the entire subtree
            if (regulate) {
                t.getCdr().setFormToRegular();
            }

            // Print car while handling empty lists inside of lists
            if (t.getCar().isNil()) {
                Console.Write("()");
            }
            else {
                Node car = t.getCar();
                if (regulate && car.isPair()){
                    depth++;
                }
                car.print(n, false);
            }

            // Print a space if we have not reached the end of the list
            // Then print the cdr
            if (!t.getCdr().isNil()) {
                Console.Write(" ");
            }
            Node cdr = t.getCdr();
            if (cdr.isNil()) {
                if (!hasMessage) {
                    cdr.print(n, true);
                    if (regulate) {
                        depth--;
                    }
                    //Console.WriteLine("CR = " + CR);
                    if (depth == 0 && CR) {
                        Console.WriteLine();
                    }
                }

            }
            else {
                cdr.print(n, true);
            }
        }
开发者ID:HurricaneFist,项目名称:cs4101proj1,代码行数:48,代码来源:Regular.cs


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