Show / Hide Table of Contents

Class SymbolTable<TSymbol, TValue>

Represents a symbol table that associates symbols to values.

Inheritance
System.Object
SymbolTable<TSymbol, TValue>
Implements
System.Collections.Generic.IEnumerable<Indexed<System.Collections.Generic.KeyValuePair<TSymbol, TValue>>>
System.Collections.IEnumerable
Namespace: System.Linq.CompilerServices
Assembly: Nuqleon.Linq.CompilerServices.dll
Syntax
public class SymbolTable<TSymbol, TValue> : Object, IEnumerable<Indexed<KeyValuePair<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

SymbolTable(SymbolTable<TSymbol, TValue>)

Creates a new empty symbol table with the specified (optional) parent symbol table and using the default equality comparer for symbols.

Declaration
public SymbolTable(SymbolTable<TSymbol, TValue> parent)
Parameters
Type Name Description
SymbolTable<TSymbol, TValue> parent

Parent symbol table (optional).

SymbolTable(SymbolTable<TSymbol, TValue>, IEqualityComparer<TSymbol>)

Creates a new empty symbol table with the specified (optional) parent symbol table and using the specified equality comparer for symbols.

Declaration
public SymbolTable(SymbolTable<TSymbol, TValue> parent, IEqualityComparer<TSymbol> symbolComparer)
Parameters
Type Name Description
SymbolTable<TSymbol, TValue> parent

Parent symbol type (optional).

System.Collections.Generic.IEqualityComparer<TSymbol> symbolComparer

Equality comparer to compare symbols. A symbol table can only contain distinct symbols.

Properties

Item[TSymbol]

Gets the value associated with the specified symbol.

Declaration
public Indexed<TValue> this[TSymbol symbol] { get; }
Parameters
Type Name Description
TSymbol symbol

Symbol to look up in the symbol table.

Property Value
Type Description
Indexed<TValue>

Value associated with the specified symbol.

Parent

Gets the parent symbol table. Returns null if no parent table was specified during creation of the symbol table.

Declaration
public SymbolTable<TSymbol, TValue> Parent { get; }
Property Value
Type Description
SymbolTable<TSymbol, TValue>

Symbols

Gets the symbols defined in the symbol table, in order of definition.

Declaration
public IEnumerable<TSymbol> Symbols { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<TSymbol>

Methods

Add(TSymbol, TValue)

Adds an entry to the symbol table.

Declaration
public Indexed<KeyValuePair<TSymbol, TValue>> Add(TSymbol symbol, TValue value)
Parameters
Type Name Description
TSymbol symbol

Symbol to add to the table.

TValue value

Value to associate to the symbol.

Returns
Type Description
Indexed<System.Collections.Generic.KeyValuePair<TSymbol, TValue>>

Indexed entry in the symbol table.

GetEnumerator()

Gets an enumerator to enumerate the entries in the symbol table, in order of their index value.

Declaration
public IEnumerator<Indexed<KeyValuePair<TSymbol, TValue>>> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<Indexed<System.Collections.Generic.KeyValuePair<TSymbol, TValue>>>

Enumerator over the symbol table entries.

TryGetValue(TSymbol, out Indexed<TValue>)

Gets the symbol table entry associated with the specified symbol.

Declaration
public bool TryGetValue(TSymbol symbol, out Indexed<TValue> value)
Parameters
Type Name Description
TSymbol symbol

Symbol to look up in the symbol table.

Indexed<TValue> value

Indexed value matching the specified symbol.

Returns
Type Description
System.Boolean

true if the symbol was found; otherwise, false.

TryLookup(TSymbol, out Indexed<Indexed<TValue>>)

Looks up the specified symbol by following the symbol table's parent chain.

Declaration
public bool TryLookup(TSymbol symbol, out Indexed<Indexed<TValue>> value)
Parameters
Type Name Description
TSymbol symbol

Symbol to look up in the symbol table and its parents.

Indexed<Indexed<TValue>> value

Indexed value matching the specified symbol. The outer index represents the scope relative to the current table. The inner index represents the index in the declaring symbol table.

Returns
Type Description
System.Boolean

true if the symbol was found; otherwise, false.

Implements

System.Collections.Generic.IEnumerable<>
System.Collections.IEnumerable
In This Article
Back to top Generated by DocFX