ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
AST Struct Referenceabstract

Description:

Base class for nodes of abstract syntax trees of module ALib Expressions. Note that AST objects (and their data) are allocated in a MonoAllocator and hence have empty destructors.

Definition at line 24 of file ast.hpp.

#include <ast.hpp>

Inheritance diagram for AST:
[legend]

Public Type Index:

enum class  Types {
  Literal , Identifier , Function , UnaryOp ,
  BinaryOp , TernaryOp
}
 The type of node. More...
 

Public Field Index:

Types NodeType
 Type of derived this AST node.
 
integer Position
 Position in original expression string.
 

Public Method Index:

 AST ()=delete
 Deleted default constructor.
 
 AST (Types type, integer position)
 
virtual ~AST ()
 Virtual destructor.
 
virtual void Assemble (Program &program, MonoAllocator &allocator, AString &normalized)=0
 
virtual ASTOptimize (Normalization normalization)=0
 

Enumeration Details:

◆ Types

enum class Types
strong

The type of node.

Definition at line 27 of file ast.hpp.

Field Details:

◆ NodeType

Types NodeType

Type of derived this AST node.

Definition at line 38 of file ast.hpp.

◆ Position

integer Position

Position in original expression string.

Definition at line 41 of file ast.hpp.

Constructor(s) / Destructor Details:

◆ AST()

AST ( Types type,
integer position )
inline

Constructor

Parameters
typeThe node type.
positionThe index of this AST in the expression string.

Definition at line 49 of file ast.hpp.

◆ ~AST()

virtual ~AST ( )
inlinevirtual

Virtual destructor.

Definition at line 55 of file ast.hpp.

Method Details:

◆ Assemble()

virtual void Assemble ( Program & program,
MonoAllocator & allocator,
AString & normalized )
pure virtual

Recursively compiles nested nodes and invokes one of the add-methods of program for itself.

Parameters
programThe program to be compiled.
allocatorAn allocator usable for temporary objects. Its memory is invalid after the compilation process.
[out]normalizedThe normalized string, built during recursive compilation of the AST.

Implemented in ASTBinaryOp, ASTConditional, ASTFunction, ASTIdentifier, ASTLiteral, and ASTUnaryOp.

◆ Optimize()

virtual AST * Optimize ( Normalization normalization)
pure virtual

Recursively walks through the tree and performs optimizations, dependent on given flags.

As of today, the only optimization performed in this AST itself is to combine nested unary '+' and '-' operators on literals.

Parameters
normalizationThe compiler flags denoting the normalization settings.
Returns
A potentially replaced AST or itself.

Implemented in ASTBinaryOp, ASTConditional, ASTFunction, ASTIdentifier, ASTLiteral, and ASTUnaryOp.


The documentation for this struct was generated from the following file: