Table of Contents

Class SymbolTable

Namespace
Pl0.Core
Assembly
Pl0.Core.dll

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

List<SymbolEntry>

_scopeStarts

Stack of scope start indices.

private readonly Stack<int> _scopeStarts

Field Value

Stack<int>

Properties

Count

Gets the number of entries in the symbol table.

public int Count { get; }

Property Value

int

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

name string

The 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

entry SymbolEntry

The symbol entry to add.

Returns

bool

True if the symbol was declared; false if it was a duplicate.