Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
IfNode.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.Text;
16 using Irony.Interpreter;
17 using Irony.Parsing;
18 
19 namespace Irony.Interpreter.Ast {
20  public class IfNode : AstNode {
21  public AstNode Test;
22  public AstNode IfTrue;
23  public AstNode IfFalse;
24 
25  public IfNode() { }
26 
27  public override void Init(ParsingContext context, ParseTreeNode treeNode) {
28  base.Init(context, treeNode);
29  Test = AddChild("Test", treeNode.ChildNodes[0]);
30  IfTrue = AddChild("IfTrue", treeNode.ChildNodes[1]);
31  if (treeNode.ChildNodes.Count > 2)
32  IfFalse = AddChild("IfFalse", treeNode.ChildNodes[2]);
33  }
34 
35  public override void EvaluateNode(EvaluationContext context, AstMode mode) {
36  Test.Evaluate(context, AstMode.Write);
37  var result = context.Data.Pop();
38  if (context.Runtime.IsTrue(result)) {
39  if (IfTrue != null) IfTrue.Evaluate(context, AstMode.Read);
40  } else {
41  if (IfFalse != null) IfFalse.Evaluate(context, AstMode.Read);
42  }
43  }
44  }//class
45 
46 }//namespace
override void Init(ParsingContext context, ParseTreeNode treeNode)
Definition: IfNode.cs:27
override void EvaluateNode(EvaluationContext context, AstMode mode)
Definition: IfNode.cs:35
ParseTreeNodeList ChildNodes
Definition: ParseTree.cs:41