SPPCompiler.SemanticAnalysis.Asts.Ast module¶
- class SPPCompiler.SemanticAnalysis.Asts.Ast.Ast(pos=0, *, _ctx=None, _scope=None, is_type_ast=False)¶
Bases:
CompilerStages
The Ast class is the base class of all ASTs created by the parser. Common methods and properties are defined here. The “CompilerStages” class is inherited to allow the AST to be processed by the compiler.
- pos: int¶
The position of the AST (by character in source code).
- is_type_ast: bool¶
Optimization tag to check if this AST is a type. This is used to avoid unnecessary type checks in the compiler.
- clone_at(pos)¶
Clone an AST at a new position. This is used to create a new AST with the same attributes as the original, but with a different position.
- Parameters:
pos (
int
) – The new position of the cloned AST.- Return type:
- Returns:
The cloned AST.
- abstractmethod print(printer)¶
Print an AST with indentation for inner scopes. The decorator and AstPrinter object “printer” work together to auto-format the output. This function will result in almost identical code to the source code being parsed and generated; the only difference will be the preprocessing applications, which mainly focus on function generation. Some ASTs will be re-ordered, with no effect on code execution.
- Parameters:
printer (
AstPrinter
) – The auto-formatting AstPrinter object. It can be created inline, and the top-most AST it is created in will be the most un-tabbed AST.- Return type:
str
- Returns:
The output string to be printed, fully formatted and pre-processed.
- abstract property pos_end: int¶
The
pos_end
property gets the final index spanned to by this AST. Implementations recursively choose the final AST from their attributes and get that AST’s end position. This will end up with either an identifier of token’s end position, and for either AST this is its start position + length of identifier/token.- Returns:
The final index spanned by this AST.
- pre_process(ctx)¶
The default AST steps for pre-processing is to save the context into an attribute. This is used in later analysis stages.
- Parameters:
ctx (
TypeAliasType
) – The pre-processing context.- Return type:
None
- Returns:
None.
- generate_top_level_scopes(sm)¶
The default AST steps for generating top level scopes is to save the scope into an attribute. This is used in later analysis stages.
- Parameters:
sm (ScopeManager) – The scope manager.
- Return type:
None
- Returns:
None.