Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
FunctionDefNode.cs
Go to the documentation of this file.
1 #region License
2 /* **********************************************************************************
3  * Copyright (c) Roman Ivantsov
4  * This source code is subject to terms and conditions of the MIT License
5  * for Irony. A copy of the license can be found in the License.txt file
6  * at the root of this distribution.
7  * By using this source code in any fashion, you are agreeing to be bound by the terms of the
8  * MIT License.
9  * You must not remove this notice from this software.
10  * **********************************************************************************/
11 #endregion
12 
13 using System;
14 using System.Collections.Generic;
15 using System.Linq;
16 using System.Text;
17 using Irony.Interpreter;
18 using Irony.Parsing;
19 
20 namespace Irony.Interpreter.Ast {
21 
22  //A node representing function definition
24  AstNode NameNode;
25  AstNode Parameters;
26  AstNode Body;
27 
28  public override void Init(ParsingContext context, ParseTreeNode treeNode) {
29  base.Init(context, treeNode);
30  //child #0 is usually a keyword like "def"
31  NameNode = AddChild("Name", treeNode.ChildNodes[1]);
32  Parameters = AddChild("Parameters", treeNode.ChildNodes[2]);
33  Body = AddChild("Body", treeNode.ChildNodes[3]);
34  AsString = "<Function " + NameNode.AsString + ">";
35  }
36 
37  public override void EvaluateNode(EvaluationContext context, AstMode mode) {
38  //push the function into the stack
39  context.Data.Push(this);
40  NameNode.Evaluate(context, AstMode.Write);
41  }
42 
43 
44  #region ICallTarget Members
45 
46  public void Call(EvaluationContext context) {
47  context.PushFrame(this.NameNode.ToString(), this, context.CurrentFrame);
48  Parameters.Evaluate(context, AstMode.None);
49  Body.Evaluate(context, AstMode.None);
50  context.PopFrame();
51  }
52 
53  #endregion
54  }//class
55 
56 }//namespace
override void Init(ParsingContext context, ParseTreeNode treeNode)
ParseTreeNodeList ChildNodes
Definition: ParseTree.cs:41
override void EvaluateNode(EvaluationContext context, AstMode mode)
void Call(EvaluationContext context)