Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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