Class ScopedSymbolTable<TSymbol, TValue>
Represents a scoped symbol table with standard lexical scoping rules, allowing for lookup of the closest declaring scope of a symbol.
Inheritance
Implements
Namespace: System.Linq.CompilerServices
Assembly: Nuqleon.Linq.CompilerServices.dll
Syntax
public class ScopedSymbolTable<TSymbol, TValue> : Object, IEnumerable<Indexed<SymbolTable<TSymbol, TValue>>>, IEnumerable
Type Parameters
Name | Description |
---|---|
TSymbol | Type of the symbols stored in the table. |
TValue | Type of the values associated with the symbols stored in the table. |
Constructors
ScopedSymbolTable()
Creates a new empty scoped symbol table with an empty initial global scope.
Declaration
public ScopedSymbolTable()
ScopedSymbolTable(IEqualityComparer<TSymbol>)
Creates a new empty scoped symbol table with an empty initial global scope, using the specified equality comparer for symbols.
Declaration
public ScopedSymbolTable(IEqualityComparer<TSymbol> symbolComparer)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEqualityComparer<TSymbol> | symbolComparer | Equality comparer to compare symbols. A scoped symbol table can only contain distinct symbols within each level. Symbols can shadow declarations in the enclosing scope. |
Properties
CurrentScope
Gets the current scope in the scoped symbol table. This may return the global scope if no other scopes were created.
Declaration
public SymbolTable<TSymbol, TValue> CurrentScope { get; }
Property Value
Type | Description |
---|---|
SymbolTable<TSymbol, TValue> |
GlobalScope
Gets the global scope associated with the scoped symbol table.
Declaration
public SymbolTable<TSymbol, TValue> GlobalScope { get; }
Property Value
Type | Description |
---|---|
SymbolTable<TSymbol, TValue> |
Methods
Add(TSymbol, TValue)
Adds an entry to the current scope in the scoped symbol table.
Declaration
public Indexed<KeyValuePair<TSymbol, TValue>> Add(TSymbol symbol, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TSymbol | symbol | Symbol to add to the current scope in the table. |
TValue | value | Value to associate to the symbol. |
Returns
Type | Description |
---|---|
Indexed<System.Collections.Generic.KeyValuePair<TSymbol, TValue>> | Indexed entry in the current scope in the scoped symbol table. |
GetEnumerator()
Gets an enumerator to enumerate the symbol tables in the scoped symbol table, starting from the current scope. The last element with index -1 represents the global scope.
Declaration
public IEnumerator<Indexed<SymbolTable<TSymbol, TValue>>> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<Indexed<SymbolTable<TSymbol, TValue>>> | Enumerator over the scoped symbol table entries. |
Pop()
Pops the most recent scope from the scoped symbol table.
Declaration
public void Pop()
Push()
Pushes a new scope onto the scoped symbol table.
Declaration
public void Push()
TryLookup(TSymbol, out Indexed<Indexed<TValue>>)
Looks up the specified symbol by scanning the scoped symbol table, starting from the current scope.
Declaration
public bool TryLookup(TSymbol symbol, out Indexed<Indexed<TValue>> value)
Parameters
Type | Name | Description |
---|---|---|
TSymbol | symbol | Symbol to look up in the scope symbol table. |
Indexed<Indexed<TValue>> | value | Indexed value matching the specified symbol. The outer index represents the scope relative to the current scope, with a value of -1 representing the global scope. The inner index represents the index in the declaring symbol table. |
Returns
Type | Description |
---|---|
System.Boolean | true if the symbol was found; otherwise, false. |