Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
IdentifierNode.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 System.Xml;
18 using Irony.Parsing;
19 using Irony.Interpreter;
20 
21 namespace Irony.Interpreter.Ast {
22 
23  public class IdentifierNode : AstNode {
24  public string Symbol;
25 
26  public IdentifierNode() { }
27 
28  public override void Init(ParsingContext context, ParseTreeNode treeNode) {
29  base.Init(context, treeNode);
30  Symbol = treeNode.Token.ValueString;
31  AsString = Symbol;
32  }
33 
34 
35  public override void EvaluateNode(EvaluationContext context, AstMode mode) {
36  switch (mode) {
37  case AstMode.Read:
38  object value;
39  if (context.TryGetValue(Symbol, out value))
40  context.Data.Push(value);
41  else
42  context.ThrowError(Resources.ErrVarNotDefined, Symbol);
43  break;
44  case AstMode.Write:
45  context.SetValue(Symbol, context.Data.Pop());
46  break;
47  }
48  }
49 
50  }//class
51 }//namespace
static string ErrVarNotDefined
Looks up a localized string similar to Variable {0} not defined..
override void EvaluateNode(EvaluationContext context, AstMode mode)
void Push(object item)
Definition: DataStack.cs:54
override void Init(ParsingContext context, ParseTreeNode treeNode)
bool TryGetValue(string name, out object value)