titus.pfaast.SymbolTable

class titus.pfaast.SymbolTable(parent, symbols, cells, pools, sealedAbove, sealedWithin)[source]

Bases: object

Represents the symbols (variables) and their data types in a lexical scope.

__init__(parent, symbols, cells, pools, sealedAbove, sealedWithin)
Parameters:
  • parent (titus.pfaast.SymbolTable or None) – enclosing scope; symbol lookup defers to the parent scope if not found here
  • symbols (dict from symbol name to titus.datatype.AvroType) – initial symbol names and their types
  • cells (dict from cell name to titus.datatype.AvroType) – initial cell names and their types
  • pools (dict from pool name to titus.datatype.AvroType) – initial pool names and their types
  • sealedAbove (bool) – if True, symbols in the parent scope cannot be modified (but can be accessed); if False, this scope does not restrict access (but a parent might)
  • sealedWithin (bool) – if True, new symbols cannot be created in this scope
allInScope

All symbols (and their types) that are defined in this scope and all parents.

Return type:dict from symbol name to titus.datatype.AvroType
Returns:symbols and their types
static blank()

Create a blank symbol table.

Return type:titus.pfaast.SymbolTable
Returns:a symbol table containing nothing
cell(name)

Get a cell’s type from this scope or a parent’s.

Parameters:name (string) – name of the cell
Return type:titus.datatype.AvroType or None
Returns:the cell’s type if defined, None otherwise
get(name)

Get a symbol’s type from this scope or a parent’s.

Parameters:name (string) – name of the symbol
Return type:titus.datatype.AvroType or None
Returns:the symbol’s type if defined, None otherwise
getAbove(name)

Get a symbol’s type specifically from a parent’s scope, not this one.

Parameters:name (string) – name of the symbol
Return type:titus.datatype.AvroType or None
Returns:the symbol’s type if defined in a parent’s scope, None otherwise
getLocal(name)

Get a symbol’s type specifically from this scope.

Parameters:name (string) – name of the symbol
Return type:titus.datatype.AvroType or None
Returns:the symbol’s type if defined in this scope, None otherwise
inThisScope

All symbols (and their types) that are defined in this scope (not in any parents).

Return type:dict from symbol name to titus.datatype.AvroType
Returns:symbols and their types
newScope(sealedAbove, sealedWithin)

Create a new scope with this as parent.

Parameters:
  • sealedAbove (bool) – if True, symbols in the parent scope cannot be modified (but can be accessed); if False, this scope does not restrict access (but a parent might)
  • sealedWithin (bool) – if True, new symbols cannot be created in this scope
Return type:

titus.pfaast.SymbolTable

Returns:

a new scope, linked to this one

pool(name)

Get a pool’s type from this scope or a parent’s.

Parameters:name (string) – name of the pool
Return type:titus.datatype.AvroType or None
Returns:the pool’s type if defined, None otherwise
put(name, avroType)

Create or overwrite a symbol’s type in the table.

Parameters:
Return type:

None

Returns:

nothing; changes table in-place

writable(name)

Determine if a symbol can be modified in this scope.

Parameters:name (string) – name of the symbol
Return type:bool
Returns:True if the symbol can be modified; False otherwise