Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
StatementListNode.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  public class StatementListNode : AstNode {
23 
24  public override void Init(ParsingContext context, ParseTreeNode treeNode) {
25  base.Init(context, treeNode);
26  foreach (var child in treeNode.ChildNodes) {
27  //don't add if it is null; it can happen that "statement" is a comment line and statement's node is null.
28  // So to make life easier for language creator, we just skip if it is null
29  if (child.AstNode != null)
30  AddChild(string.Empty, child);
31  }
32  AsString = "Statement List";
33  }
34 
35  public override void EvaluateNode(EvaluationContext context, AstMode mode) {
36  if (ChildNodes.Count == 0) return;
37  ChildNodes[ChildNodes.Count - 1].Flags |= AstNodeFlags.IsTail;
38  int iniCount = context.Data.Count;
39  foreach(var stmt in ChildNodes) {
40  stmt.Evaluate(context, AstMode.Read);
41  //restore position, in case a statement left something (like standalone expression vs assignment)
42  context.Data.PopUntil(iniCount);
43  }
44  context.Data.Push(context.LastResult); //push it back again
45  }
46 
47  }//class
48 
49 }//namespace
override void EvaluateNode(EvaluationContext context, AstMode mode)
override void Init(ParsingContext context, ParseTreeNode treeNode)