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]; }
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]; }
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]; }
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; }
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]; } }
/// <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++; } } }
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); }
//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++; } }
/// <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); }
protected static bool CheckCondition(ScriptAst cond, IScriptContext context) { cond.Evaluate(context); return((bool)context.Result); }
public ScriptUsingStatement(AstNodeArgs args) : base(args) { name = args.ChildNodes[1] as ScriptQualifiedName; statement = args.ChildNodes[2] as ScriptAst; }
protected static bool CheckCondition(ScriptAst cond, IScriptContext context) { cond.Evaluate(context); return (bool)context.Result; }