The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
SymbolTable.cs
Go to the documentation of this file.
1 // -------------------------------------------------------------------------- //
3 // Project rROTOR //
4 // -------------------------------------------------------------------------- //
5 // File: SymbolTable.cs //
6 // Author: Cristina Gonzalez Muņoz - cristi.gm@gmail.com //
7 // Description: //
8 // Implementation of a symbol table. //
9 // -------------------------------------------------------------------------- //
10 // Create date: 30-03-2007 //
11 // Modification date: 30-03-2007 //
13 
14 using System;
15 using System.Collections.Generic;
16 using System.Text;
17 
18 using ErrorManagement;
19 using TypeSystem;
20 
21 namespace Symbols
22 {
27  {
28  #region Fields
29 
33  private List<Dictionary<string, Symbol>> table;
34 
35  #endregion
36 
37  #region Constructors
38 
42  public SymbolTable()
43  {
44  this.table = new List<Dictionary<string, Symbol>>();
45  }
46 
47  #endregion
48 
49  #region Set()
50 
54  public void Set()
55  {
56  //scope++;
57  this.table.Add(new Dictionary<string, Symbol>());
58  }
59 
60  #endregion
61 
62  #region Reset()
63 
67  public void Reset()
68  {
69  //scope--;
70  this.table.RemoveAt(this.table.Count - 1);
71  }
72 
73  #endregion
74 
75  #region Insert()
76 
84  public Symbol Insert(string id, TypeExpression type, bool isDynamic)
85  {
86  if (this.table[this.table.Count - 1].ContainsKey(id))
87  return null;
88  Symbol s = new Symbol(id, this.table.Count - 1, type, isDynamic);
89  this.table[this.table.Count - 1].Add(id, s);
90  //Console.WriteLine(s.ToString());
91  return s;
92  }
93 
94  #endregion
95 
96  #region Search()
97 
103  public Symbol Search(string id)
104  {
105  int scope = this.table.Count - 1;
106 
107  while (scope >= 0)
108  {
109  if (this.table[scope].ContainsKey(id))
110  return this.table[scope][id];
111  else
112  scope--;
113  }
114  return null;
115  }
116 
117  #endregion
118  }
119 }
void Set()
Add a new scope
Definition: SymbolTable.cs:54
SymbolTable()
Constructor of SymbolTable.
Definition: SymbolTable.cs:42
Symbol Insert(string id, TypeExpression type, bool isDynamic)
Insert a new symbol in the current scope.
Definition: SymbolTable.cs:84
Abstract class that represents all different types.
Implementation of a symbol table.
Definition: SymbolTable.cs:26
This class represents a symbol associated with its identifier.
Definition: Symbol.cs:26
Symbol Search(string id)
Searches in the symbol table for a symbol matching the specified name.
Definition: SymbolTable.cs:103
void Reset()
Removes the last scope
Definition: SymbolTable.cs:67