Base class for Script.NET Ast's nodes
Наследование: AstNode
        public ScriptFunctionDefinition(AstNodeArgs args)
            : base(args)
        {
            Token funcName = ChildNodes[1] as Token;
              int index = 0;

              if (funcName != null)
              {
            Name = funcName.Text;
              }
              else
              //Function expression
              {
            Name = null;
            index = 1;
              }

              if (ChildNodes.Count == 5-index)
              {
            Contract = ChildNodes[3 - index] as ScriptFuncContract;
            Parameters = ChildNodes[3 - index] as ScriptFuncParameters;
              }

              if (ChildNodes.Count == 6 - index)
              {
            Parameters = ChildNodes[2 - index] as ScriptFuncParameters;
            GlobalList = ChildNodes[3 - index] as ScriptGlobalList;
            Contract = ChildNodes[4 - index] as ScriptFuncContract;
              }

              Body = (ScriptAst)ChildNodes[ChildNodes.Count - 1];
        }
Пример #2
0
        public ScriptFunctionDefinition(AstNodeArgs args)
            : base(args)
        {
            Token funcName = ChildNodes[1] as Token;
            int   index    = 0;

            if (funcName != null)
            {
                Name = funcName.Text;
            }
            else
            //Function expression
            {
                Name  = null;
                index = 1;
            }

            if (ChildNodes.Count == 5 - index)
            {
                Contract   = ChildNodes[3 - index] as ScriptFuncContract;
                Parameters = ChildNodes[3 - index] as ScriptFuncParameters;
            }

            if (ChildNodes.Count == 6 - index)
            {
                Parameters = ChildNodes[2 - index] as ScriptFuncParameters;
                GlobalList = ChildNodes[3 - index] as ScriptGlobalList;
                Contract   = ChildNodes[4 - index] as ScriptFuncContract;
            }

            Body = (ScriptAst)ChildNodes[ChildNodes.Count - 1];
        }
Пример #3
0
 public ScriptForStatement(AstNodeArgs args)
     : base(args)
 {
     init      = (ScriptAst)args.ChildNodes[1];
     cond      = (ScriptAst)args.ChildNodes[2];
     next      = (ScriptAst)args.ChildNodes[3];
     statement = (ScriptStatement)args.ChildNodes[4];
 }
Пример #4
0
 public ScriptForStatement(AstNodeArgs args)
     : base(args)
 {
     init = (ScriptAst)args.ChildNodes[1];
       cond = (ScriptAst)args.ChildNodes[2];
       next = (ScriptAst)args.ChildNodes[3];
       statement = (ScriptStatement)args.ChildNodes[4];
 }
        public ScriptFlowControlStatement(AstNodeArgs args)
            : base(args)
        {
            Token oper = ChildNodes[0] as Token;
              operation = oper.Text;
              Debug.Assert(oper.Text == "return" || oper.Text == "break" || oper.Text == "continue" || oper.Text == "throw");

              if (operation == "return" || operation == "throw")
            expression = (ScriptExpr)ChildNodes[1];
        }
Пример #6
0
        public ScriptMetaExpr(AstNodeArgs args)
            : base(args)
        {
            AstNodeArgs progArgs = new AstNodeArgs();
              progArgs.ChildNodes = new AstNodeList();
              progArgs.ChildNodes.Add(ChildNodes[1]);
              progArgs.Span = args.Span;
              progArgs.Term = args.Term;

              metaProg = new ScriptProg(progArgs);
              metaProg.Parent = this;
        }
Пример #7
0
        public ScriptMetaExpr(AstNodeArgs args)
            : base(args)
        {
            AstNodeArgs progArgs = new AstNodeArgs();

            progArgs.ChildNodes = new AstNodeList();
            progArgs.ChildNodes.Add(ChildNodes[1]);
            progArgs.Span = args.Span;
            progArgs.Term = args.Term;

            metaProg        = new ScriptProg(progArgs);
            metaProg.Parent = this;
        }
Пример #8
0
        public ScriptFlowControlStatement(AstNodeArgs args)
            : base(args)
        {
            Token oper = ChildNodes[0] as Token;

            operation = oper.Text;
            Debug.Assert(oper.Text == "return" || oper.Text == "break" || oper.Text == "continue" || oper.Text == "throw");

            if (operation == "return" || operation == "throw")
            {
                expression = (ScriptExpr)ChildNodes[1];
            }
        }
Пример #9
0
 /// <summary>
 /// Evaluates script
 /// </summary>
 /// <param name="Context">ScriptContext</param>
 public virtual void Evaluate(IScriptContext context)
 {
     if (ChildNodes.Count > 0)
     {
         int index = 0;
         while (index < ChildNodes.Count)
         {
             ScriptAst node = ChildNodes[index] as ScriptAst;
             if (node != null)
             {
                 node.Evaluate(context);
             }
             index++;
         }
     }
 }
Пример #10
0
        private string ConcreteSyntaxTree(string inted)
        {
            string tree = Term.Name + "\r\n";

            inted += " ";
            foreach (AstNode node in ChildNodes)
            {
                ScriptAst scriptNode = node as ScriptAst;
                if (scriptNode != null)
                {
                    tree += inted + scriptNode.ConcreteSyntaxTree(inted);
                }
                else
                {
                    if (!string.IsNullOrEmpty(node.Term.DisplayName))
                    {
                        tree += inted + node.ToString() + "\r\n";
                    }
                }
            }
            return(tree);
        }
Пример #11
0
        //TODO: Implement Breaking, Returning, etc. here
        public override void Evaluate(IScriptContext context)
        {
            if (ChildNodes.Count == 0)
            {
                return;
            }

            int index = 0;

            while (index < ChildNodes.Count)
            {
                ScriptAst node = (ScriptAst)ChildNodes[index];
                node.Evaluate(context);

                if (context.IsBreak() || context.IsReturn() || context.IsContinue())
                {
                    break;
                }

                index++;
            }
        }
Пример #12
0
 /// <summary>
 /// Returns source code for given node
 /// </summary>
 /// <param name="node">Node</param>
 /// <returns>source code</returns>
 public string Code(ScriptAst node)
 {
     return SourceCode.Substring(node.Span.Start.Position, node.Span.Length);
 }
Пример #13
0
 protected static bool CheckCondition(ScriptAst cond, IScriptContext context)
 {
     cond.Evaluate(context);
     return((bool)context.Result);
 }
Пример #14
0
 public ScriptUsingStatement(AstNodeArgs args)
     : base(args)
 {
     name = args.ChildNodes[1] as ScriptQualifiedName;
       statement = args.ChildNodes[2] as ScriptAst;
 }
Пример #15
0
 public ScriptUsingStatement(AstNodeArgs args)
     : base(args)
 {
     name      = args.ChildNodes[1] as ScriptQualifiedName;
     statement = args.ChildNodes[2] as ScriptAst;
 }
Пример #16
0
 protected static bool CheckCondition(ScriptAst cond, IScriptContext context)
 {
     cond.Evaluate(context);
       return (bool)context.Result;
 }