Purple  0.1
Standard Language Specification
tree.h
Go to the documentation of this file.
1
8#ifndef TREE
9#define TREE
10
11#include <stdlib.h>
12
13#include "scan.h"
15#include "utils/logging.h"
16
20typedef struct ASTNode {
24 struct ASTNode* left;
26 struct ASTNode* mid;
28 struct ASTNode* right;
36 char filename[256];
42 unsigned long long int num_args;
46 union {
53
54#define PRINT_ASTNODE(node) \
55 printf("ASTNode Information\n-------------------\n"); \
56 printf("TokenType: %s\nLeft: %d\nMiddle: %d\nRight: %d\n", tokenStrings[node->ttype], \
57 (int)node->left, (int)node->mid, (int)node->right); \
58 printf("Is RValue: %s\n", node->is_rvalue ? "true" : "false"); \
59 printf("# of Func Call Args: %llu\n", node->num_args); \
60 printf("Value (int): %lld\n", node->value.number_value); \
61 printf("Value (str): %s\n", node->value.symbol_name);
62
63ASTNode* create_ast_node(TokenType ttype, ASTNode* left, ASTNode* mid, ASTNode* right, Type type,
64 char* symbol_name);
67ASTNode* create_ast_identifier_leaf(TokenType ttype, char* symbol_name);
68ASTNode* create_unary_ast_node(TokenType ttype, ASTNode* child, Type type, char* symbol_name);
69void ast_debug_level_order(ASTNode* root, LogLevel log_level);
70void free_ast_node(ASTNode* root);
71
72#endif /* TREE */
#define MAX_IDENTIFIER_LENGTH
Definition: identifier.h:12
Function headers, ANSI defines, and enums for raising internal warnings and errors.
LogLevel
Severity levels of logging statements emitted by the compiler.
Definition: logging.h:35
NumberType
Types of numbers supported by Purple.
Definition: number.h:17
Lexical Scanner function headers.
#define number_literal_type
Number literals can have a max value of 2^63 - 1 and a min value of -2^63.
Definition: scan.h:144
TokenType
Types of scannable tokens.
Definition: scan.h:20
Component of the abstract syntax tree built during parsing.
Definition: tree.h:20
char symbol_name[MAX_IDENTIFIER_LENGTH]
Definition: tree.h:50
struct ASTNode ** function_call_arguments
Definition: tree.h:44
NumberType largest_number_type
Definition: tree.h:32
bool is_rvalue
Definition: tree.h:34
union ASTNode::@2 value
struct ASTNode * left
Definition: tree.h:24
char filename[256]
Definition: tree.h:36
struct ASTNode * right
Definition: tree.h:28
int char_number
Definition: tree.h:40
TokenType ttype
The TokenType of the given token.
Definition: tree.h:22
Number tree_type
Definition: tree.h:30
number_literal_type number_value
Definition: tree.h:48
struct ASTNode * mid
Definition: tree.h:26
unsigned long long int num_args
Definition: tree.h:42
int line_number
Definition: tree.h:38
Container for various kinds of number data.
Definition: number.h:56
Container for type data.
Definition: type.h:18
Structure containing information about a Token's position in the input.
Definition: scan.h:154
Function headers and definitions for the global and local symbol tables.
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.
Definition: tree.c:104
void free_ast_node(ASTNode *root)
Definition: tree.c:197
void ast_debug_level_order(ASTNode *root, LogLevel log_level)
Print out an AST's level order traversal.
Definition: tree.c:187
void add_position_info(ASTNode *dest, position p)
Add position information to an ASTNode.
Definition: tree.c:90
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.
Definition: tree.c:116
struct ASTNode ASTNode
Component of the abstract syntax tree built during parsing.
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.
Definition: tree.c:130
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.
Definition: tree.c:26