Purple  0.1
Standard Language Specification
Functions
tree.c File Reference

Logic for constructing an Abstract Syntax Tree (AST) More...

#include <stdio.h>
#include <string.h>
#include "data.h"
#include "tree.h"
Include dependency graph for tree.c:

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...
 
static int ast_node_height (ASTNode *node)
 Get the height of an AST Node. More...
 
static void ast_debug_current_level (ASTNode *root, int height, LogLevel log_level)
 Print out a single level of an AST in order from left to right. More...
 
void ast_debug_level_order (ASTNode *root, LogLevel log_level)
 Print out an AST's level order traversal. More...
 

Detailed Description

Logic for constructing an Abstract Syntax Tree (AST)

Author
Charles Averill
Date
09-Sep-2022

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_current_level()

static void ast_debug_current_level ( ASTNode root,
int  height,
LogLevel  log_level 
)
static

Print out a single level of an AST in order from left to right.

Parameters
rootRoot of AST
heightLevel of tree to be printed out
log_levelLog level to print at

◆ 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

◆ ast_node_height()

static int ast_node_height ( ASTNode node)
static

Get the height of an AST Node.

Parameters
nodeNode to get height of
Returns
int Height of node

◆ 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