KumiScript/reader/SymbolTable.cs

36 lines
794 B
C#
Raw Normal View History

using KumiScript.Interpreter;
namespace KumiScript.Reader
{
public class SymbolTable
{
static SymbolTable? _instance;
readonly Dictionary<string, Symbol> _table;
private SymbolTable()
{
_instance = this;
_table = new Dictionary<string, Symbol>();
}
public static SymbolTable GetInstance()
{
if (_instance is null)
return new SymbolTable();
return _instance;
}
public Symbol FromString(string s)
{
Symbol? sym;
_table.TryGetValue(s, out sym);
if (sym is null)
{
sym = new Symbol(s);
_table.Add(s, sym);
}
return sym;
}
}
}