36 lines
No EOL
794 B
C#
36 lines
No EOL
794 B
C#
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;
|
|
}
|
|
}
|
|
} |