Purple  0.1
Standard Language Specification
Classes | Macros | Typedefs | Functions
tree.h File Reference

Function headers for abstract syntax tree parsing. More...

#include <stdlib.h>
#include "scan.h"
#include "translate/symbol_table.h"
#include "utils/logging.h"
Include dependency graph for tree.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ASTNode
 Component of the abstract syntax tree built during parsing. More...
 

Macros

#define PRINT_ASTNODE(node)
 

Typedefs

typedef struct ASTNode ASTNode
 Component of the abstract syntax tree built during parsing. More...
 

Functions

ASTNodecreate_ast_node (TokenType ttype, ASTNode *left, ASTNode *mid, ASTNode *right, Type type, char *symbol_name)
 Constructs a new AST Node with the provided values. More...
 
void add_position_info (ASTNode *dest, position p)
 Add position information to an ASTNode. More...
 
ASTNodecreate_ast_nonidentifier_leaf (TokenType ttype, Type type)
 Constructs a new AST Leaf Node with the provided values for a token that is not an identifier. More...
 
ASTNodecreate_ast_identifier_leaf (TokenType ttype, char *symbol_name)
 Constructs a new AST Leaf Node with the provided values for a token that is an identifier. More...
 
ASTNodecreate_unary_ast_node (TokenType ttype, ASTNode *child, Type type, char *symbol_name)
 Constructs a new AST Unary Parent Node with the provided values. More...
 
void ast_debug_level_order (ASTNode *root, LogLevel log_level)
 Print out an AST's level order traversal. More...
 
void free_ast_node (ASTNode *root)
 

Detailed Description

Function headers for abstract syntax tree parsing.

Author
Charles Averill
Date
09-Sep-2022

Macro Definition Documentation

◆ PRINT_ASTNODE

#define PRINT_ASTNODE (   node)
Value:
printf("ASTNode Information\n-------------------\n"); \
printf("TokenType: %s\nLeft: %d\nMiddle: %d\nRight: %d\n", tokenStrings[node->ttype], \
(int)node->left, (int)node->mid, (int)node->right); \
printf("Is RValue: %s\n", node->is_rvalue ? "true" : "false"); \
printf("# of Func Call Args: %llu\n", node->num_args); \
printf("Value (int): %lld\n", node->value.number_value); \
printf("Value (str): %s\n", node->value.symbol_name);
static char * tokenStrings[]
Token string equivalents.
Definition: scan.h:96

Typedef Documentation

◆ ASTNode

typedef struct ASTNode ASTNode

Component of the abstract syntax tree built during parsing.

Function Documentation

◆ add_position_info()

void add_position_info ( ASTNode dest,
position  p 
)

Add position information to an ASTNode.

Parameters
destDestination ASTNode pointer
pPosition information

◆ ast_debug_level_order()

void ast_debug_level_order ( ASTNode root,
LogLevel  log_level 
)

Print out an AST's level order traversal.

Parameters
rootRoot of AST
log_levelLog level to print at

◆ create_ast_identifier_leaf()

ASTNode * create_ast_identifier_leaf ( TokenType  ttype,
char *  symbol_name 
)

Constructs a new AST Leaf Node with the provided values for a token that is an identifier.

Parameters
ttypeTokenType of the new AST Node
symbol_nameThe identifier for the provided Token information
Returns
ASTNode* The pointer to a new AST Leaf Node with the provided values

◆ create_ast_node()

ASTNode * create_ast_node ( TokenType  ttype,
ASTNode left,
ASTNode mid,
ASTNode right,
Type  type,
char *  symbol_name 
)

Constructs a new AST Node with the provided values.

Parameters
ttypeTokenType of the new AST Node
leftLeft child subtree of the new AST Node
midMiddle child subtree of the new AST Node
rightRight child subtree of the new AST Node
typeType of the new AST Node
symbol_nameThe identifier for the provided Token information
Returns
ASTNode* The pointer to a new AST Node with the provided values

◆ create_ast_nonidentifier_leaf()

ASTNode * create_ast_nonidentifier_leaf ( TokenType  ttype,
Type  type 
)

Constructs a new AST Leaf Node with the provided values for a token that is not an identifier.

Parameters
ttypeTokenType of the new AST Node
typeType of the new AST Node
Returns
ASTNode* The pointer to a new AST Leaf Node with the provided values

◆ create_unary_ast_node()

ASTNode * create_unary_ast_node ( TokenType  ttype,
ASTNode child,
Type  type,
char *  symbol_name 
)

Constructs a new AST Unary Parent Node with the provided values.

Parameters
ttypeTokenType of the new AST Node
childThe AST Node's single child
typeType of the new AST Node
symbol_nameThe identifier for the provided Token information
Returns
ASTNode* The pointer to a new AST Unary Parent Node with the provided values

◆ free_ast_node()

void free_ast_node ( ASTNode root)