Class SymbolTable
Simple symbol table with scope tracking.
public sealed class SymbolTable
- Inheritance
-
SymbolTable
- Inherited Members
Fields
_entries
All symbol entries in stack order.
private readonly List<SymbolEntry> _entries
Field Value
_scopeStarts
Stack of scope start indices.
private readonly Stack<int> _scopeStarts
Field Value
Properties
Count
Gets the number of entries in the symbol table.
public int Count { get; }
Property Value
Methods
EnterScope()
Opens a new scope.
public void EnterScope()
ExitScope()
Closes the current scope and removes scoped entries.
public void ExitScope()
Lookup(string)
Looks up the most recent symbol with the given name.
public SymbolEntry? Lookup(string name)
Parameters
namestringThe symbol name.
Returns
- SymbolEntry
The symbol entry, or null if not found.
TryDeclare(SymbolEntry)
Tries to declare a symbol in the current scope.
public bool TryDeclare(SymbolEntry entry)
Parameters
entrySymbolEntryThe symbol entry to add.
Returns
- bool
True if the symbol was declared; false if it was a duplicate.