Skip to content

Conversation

@AlexandraNegoita
Copy link
Collaborator

For defining symbols:
(enum) SymbolType - used for determining type of the symbol
(enum) SymScope - used for determining whether symbol is declared globally, locally or is a parameter
(class) SymAttributes - keeps the attributes of a symbol
- if the symbol name is reserved (keyword);
- if the symbol is a constant;
- the location of the symbol (SymScope);
- the tags of the symbol (NodeTag);
(class) Sym - class for a symbol
- keeps the type (SymbolType) and the attributes (SymAttributes) of a symbol

For defining each scope (block level):
(type) symbolBlock - a block in the code
- blockLevel - the level of the block
- symbols - all symbols that are in a block (symbolStorage)
- total - total number of symbol in a block
- blocks - all blocks that can be found in this block (symbolList)
- parent - the block that contains the current block
(class) symbolList - list with all blocks located on the same level
(class) symbolStorage - all the symbols that will be present in one block level

For defining the symbol table:
(class) symbolTable
- is formed of multiple lists within lists
- first list contains a single block 'firstBlock' (block level - 0), which doesn't have any symbols
- 'firstBlock' is the parent of the block 'keywords' (block level - 1), which will contain all reserved symbols from the code
- 'keywords' will contain the block 'global' (block level - 2), which will contain all global symbols (variables, contants, function names, classes etc)
- 'global' will contain all the local blocks with symbols (local variables and parameters) created by each function
- then, each block (scope) declared globally (block level - 3) will have its own symbol table, will have as parent the block 'global', and can contain and be the parent block of other blocks, also having the block level increasing

Functions:
addBlockToList: creates and adds a block named 'blockName' to the list of blocks that are within 'parentBlock'
getBlock: recursively finds and returns block by name, searching all existent lists of blocks
lookup: finds and returns symbol by its name and the name of the block in which is located; find the block using getBlock and calls lookupByBlock
lookupByBlock: recursively finds symbol by its name and the block in which is located, searching all existent lists of symbols
addOrReplaceSymbolToStorage: adds symbol or replaces if it already exists, using the symbol name, type and the block name where it will be added
setSymbolType and setSymbolAttributes: set or replace the type or the attributes of a symbol, using its name and the name of the block where it's located

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant