SymbolTable class

Manages symbols (variables and functions) within a scope during compilation.

The SymbolTable class implements a hierarchical symbol table that supports lexical scoping. Each symbol table can have a parent, forming a scope chain that allows variables to be looked up in enclosing scopes.

The symbol table tracks:

  • Local variables within the current scope
  • Function definitions (stored globally)
  • String constants for deduplication
  • Parent-child relationships for scope resolution

Example usage:

final globalScope = SymbolTable();
final localScope = globalScope.createChild();

Constructors

SymbolTable.new()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

canSet(String key, LangVal<LangType> value) → void
Validates that a variable assignment is type-safe and the variable exists.
clear() → void
Clears all variables from the current scope.
create(String key, LangVar<LangType> value) LangVar<LangType>
Declares a new variable in the current scope.
createChild() SymbolTable
Creates a new child symbol table for nested scope management.
get(String key) LangVar<LangType>?
Retrieves a variable definition by name, searching through scope hierarchy.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
remove(String key) → void
Removes a variable from the current scope.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

strings Map<String, String>
Global storage for string constants to enable deduplication.
getter/setter pair

Static Methods

createFunction(String key, LangFunc value) LangFunc
Registers a function definition in the global function table.
getFunction(String key) LangFunc?
Retrieves a function definition by name from the global function table.