The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
ConstantTable.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: ConstantTable.cs //
6 // Author: Cristina Gonzalez Muñoz - cristi.gm@gmail.com
7 // Daniel Zapico Rodríguez - daniel.zapico.rodriguez@gmail.com
8 // Description: //
9 // Implementation of a table of constants. //
10 // -------------------------------------------------------------------------- //
11 // Create date: 11-07-2007 //
12 // Modification date: 11-07-2007 //
14 
15 using System;
16 using System.Collections.Generic;
17 using System.Text;
18 
19 
20 using ErrorManagement;
21 using AST;
22 
23 namespace CodeGeneration {
27  class ConstantTable {
28  #region Fields
29 
33  private List<Dictionary<string, Expression>> constants;
34 
35  #endregion
36 
37  #region Constructor
38 
42  public ConstantTable() {
43  this.constants = new List<Dictionary<string, Expression>>();
44  }
45 
46  #endregion
47 
48  #region Set()
49 
53  public void Set() {
54  this.constants.Add(new Dictionary<string, Expression>());
55  }
56 
57  #endregion
58 
59  #region Reset()
60 
64  public void Reset() {
65  this.constants.RemoveAt(this.constants.Count - 1);
66  }
67 
68  #endregion
69 
70  #region Insert()
71 
78  public bool Insert(string id, Expression init) {
79  if (this.constants[this.constants.Count - 1].ContainsKey(id))
80  return false;
81  this.constants[this.constants.Count - 1].Add(id, init);
82  return true;
83  }
84 
85  #endregion
86 
87  #region Search()
88 
96  public Expression Search(string id, out int scope) {
97  scope = this.constants.Count - 1 ;
98 
99  while (scope >= 0) {
100  if (this.constants[scope].ContainsKey(id))
101  return this.constants[scope][id];
102  else
103  scope--;
104  }
105  return null;
106  }
113  public Expression Search(string id) {
114  int scope;
115  return Search(id, out scope);
116  }
117 
118  #endregion
119 
120 
121  }
122 }
Abstract class encapsulate a programming language expression.
Definition: Expression.cs:37
bool Insert(string id, Expression init)
Insert a new constant in the current scope.
Expression Search(string id)
Searches the initialization of constant identifier. It performs a full search.
Expression Search(string id, out int scope)
Searches the initialization of constant identifier.
void Set()
Add a new scope
void Reset()
Removes the last scope
ConstantTable()
Constructor of ConstantTable.