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


C# Node.isPair方法代码示例

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


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

示例1: 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

示例2: expLength

        //obtain experession length of a statement
        public static int expLength(Node exp)
        {
            if (exp.isNull())
                return 0;

            if (!exp.isPair())
                return -1;

            int num = Util.expLength(exp.getCdr());
            if (num == -1)
                return -1;

            return num + 1;
        }
开发者ID:Profitlol,项目名称:prog2-baum,代码行数:15,代码来源:Util.cs

示例3: find

 // This is not in an object-oriented style, it's more or less a
 // translation of the Scheme assq function.
 private static Node find(Node id, Node alist)
 {
     if (! alist.isPair())
         return null;	// in Scheme we'd return #f
     else
     {
         Node bind = alist.getCar();
         if (id.getName().Equals(bind.getCar().getName()))
             // return a list containing the value as only element
             return bind.getCdr();
         else
             return find(id, alist.getCdr());
     }
 }
开发者ID:jktucn,项目名称:SchemeInterpreter,代码行数:16,代码来源:Environment.cs

示例4: eval

 public override Node eval(Node t, Environment env)
 {
     Node expression;
     if ((!t.isPair()))
     {
         Console.Write("Invalid Cond statement");
     }
     expression = t.getCdr();
     while (!(expression.getCar().getCar().eval(env).isBool())) //This step skips all the false bools to find the one that returns true
     {
         expression = expression.getCdr();
     }
     if(expression.isNull()) //if it is of the empty list form, return it, which is what this does
     {
         return new Nil();
     }
     else
     {
         return (expression.getCar().getCdr().eval(env));
     }
 }
开发者ID:hcross2,项目名称:4330-Project-2,代码行数:21,代码来源:Cond.cs

示例5: print

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

示例6: apply1

 //if arg's length = 1
 private Node apply1(Node arg1)
 {
     string name = this.symbol.getName();
     bool flag = name.Equals("car");
     Node result;
     if (flag)
     {
         result = arg1.getCar();
     }//end if
     else
     {
         bool flag2 = name.Equals("cdr");
         if (flag2)
         {
             result = arg1.getCdr();
         }//end if
         else
         {
             bool flag3 = name.Equals("number?");
             if (flag3)
             {
                 result = BoolLit.getInstance(arg1.isNumber());
             }//end if
             else
             {
                 bool flag4 = name.Equals("symbol?");
                 if (flag4)
                 {
                     result = BoolLit.getInstance(arg1.isSymbol());
                 }//end if
                 else
                 {
                     bool flag5 = name.Equals("null?");
                     if (flag5)
                     {
                         result = BoolLit.getInstance(arg1.isNull());
                     }//end if
                     else
                     {
                         bool flag6 = name.Equals("pair?");
                         if (flag6)
                         {
                             result = BoolLit.getInstance(arg1.isPair());
                         }//end if
                         else
                         {
                             bool flag7 = name.Equals("procedure?");
                             if (flag7)
                             {
                                 result = BoolLit.getInstance(arg1.isProcedure());
                             }//end if
                             else
                             {
                                 bool flag8 = name.Equals("write");// i am not sure if im handling this correctly
                                 if (flag8)
                                 {
                                     arg1.print(-1);
                                     result = Unspecific.getInstance();
                                 }//end if
                                 else
                                 {
                                     bool flag9 = name.Equals("display"); // i am not sure if im handling this correctly
                                     if (flag9)
                                     {
                                         StringLit.printDoubleQuotes = false;
                                         arg1.print(-1);
                                         StringLit.printDoubleQuotes = true;
                                         result = Unspecific.getInstance();
                                     }//end if
                                     else
                                     {
                                         bool flag10 = name.Equals("load");
                                         if (flag10)
                                         {
                                             bool flag11 = !arg1.isString();
                                             if (flag11)
                                             {
                                                 Console.Error.WriteLine("Error: wrong type of argument");
                                                 result = Nil.getInstance();
                                             }
                                             else
                                             {
                                                 string stringVal = arg1.getStringVal();
                                                 try
                                                 {
                                                     //not sure why it has to be Parse.Scanner to call this
                                                     Parse.Scanner s = new Parse.Scanner(File.OpenText(stringVal));
                                                     TreeBuilder b = new TreeBuilder();
                                                     Parse.Parser parser = new Parse.Parser(s, b);
                                                     for (Node node = (Node)parser.parseExp(); node != null; node = (Node)parser.parseExp())
                                                     {
                                                         node.eval(Scheme4101.env);
                                                     }
                                                 }
                                                 catch (SystemException)
                                                 {
                                                     Console.Error.WriteLine("Could not find file " + stringVal);
                                                 }
                                                 result = Unspecific.getInstance();
//.........这里部分代码省略.........
开发者ID:Profitlol,项目名称:prog2-baum,代码行数:101,代码来源:BuiltIn.cs

示例7: checkSymbols

 //check if valid statement
 private bool checkSymbols(Node parms)
 {
     return parms.isNull() || parms.isSymbol() || (parms.isPair() && parms.getCar().isSymbol() && this.checkSymbols(parms.getCdr()));
 }
开发者ID:Profitlol,项目名称:prog2-baum,代码行数:5,代码来源:Define.cs

示例8: pairup

 //Function for pairing up arguments with corresponding symbols
 private static void pairup(Node parms, Node args, Environment env)
 {
     //if null return nothing
     if (parms.isNull() && args.isNull())
     {
         return;
     }
     //check the symbol type
     if (parms.isSymbol())
     {
         env.define(parms, args);
     }
     //depending on the parameter, check the # of required valid arguments
     else if (parms.isNull() || args.isNull())
     {
         Console.get_Error().WriteLine("Error: wrong number of arguments");
     }
     //look for values in different env w/ closure pointer? idk how to explain this
     else if (parms.isPair() && args.isPair())
     {
         env.define(parms.getCar(), args.getCar());
         Closure.pairup(parms.getCdr(), args.getCdr(), env);
     }
     else
     {
         Console.get_Error().WriteLine("Error: invalid expression");
     }
 }
开发者ID:Profitlol,项目名称:prog2-baum,代码行数:29,代码来源:Closure.cs


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