Exemplo n.º 1
0
 public SObject Evaluate(SScope scope)
 {
     if (this.Children.Count == 0)
     {
         Int64 number;
         if (Int64.TryParse(this.Value, out number))
         {
             return(number);
         }
     }
     else
     {
         SExpression first = this.Children[0];
         if (SScope.BuiltinFunctions.ContainsKey(first.Value))
         {
             var arguments = this.Children.Skip(1).ToArray();
             return(SScope.BuiltinFunctions[first.Value](arguments, scope));
         }
     }
     throw new Exception("THIS IS JUST TEMPORARY!");
 }
Exemplo n.º 2
0
        //抽象语法树的构建过程
        public static SExpression ParseAsIScheme(this String code)
        {
            SExpression program = new SExpression(value: "", parent: null);
            SExpression current = program;

            foreach (var lex in Tokenize(code))
            {
                if (lex == "(")
                {
                    SExpression newNode = new SExpression(value: "(", parent: current);
                    current.Children.Add(newNode);
                    current = newNode;
                }
                else if (lex == ")")
                {
                    current = current.Parent;
                }
                else
                {
                    current.Children.Add(new SExpression(value: lex, parent: current));
                }
            }
            return(program.Children[0]);
        }
Exemplo n.º 3
0
 //构造函数
 public SExpression(string value, SExpression parent)
 {
     this.Value    = value;
     this.Children = new List <SExpression>();
     this.Parent   = parent;
 }
Exemplo n.º 4
0
 public SFunction(SExpression sExpression, String[] parameters, SScope scope)
 {
     this.Body       = sExpression;
     this.Parameters = parameters;
     this.Scope      = scope;
 }
Exemplo n.º 5
0
 public static String[] ForeachSEx(SExpression sExpression)
 {
     String[] tokens = null;
     return(tokens);
 }