nodes.h
#
Nodes of the AST.
Authors#
TheSilvered
Macros#
Nst_NODE
#
Synopsis:
#define Nst_NODE(expr)
Description:
Casts expr
to Nst_Node *
.
Nst_NODE_RETUNS_VALUE
#
Synopsis:
#define Nst_NODE_RETUNS_VALUE(node_type)
Description:
Evaluates to true
if the specified node type returns a value.
Structs#
Nst_Node
#
Synopsis:
typedef struct _Nst_Node {
Nst_Pos start;
Nst_Pos end;
struct _Nst_NodeType type;
Nst_LList *nodes;
Nst_LList *tokens;
} Nst_Node
Description:
A structure representing a node.
Fields:
start
: the starting position of the nodeend
: the ending position of the nodetype
: the type of the nodenodes
: the child nodes of the nodetokens
: the tokens that the node contains
Functions#
Nst_node_new
#
Synopsis:
Nst_Node *Nst_node_new(Nst_NodeType type)
Description:
Creates and initializes a new AST node on the heap.
Though the position is not in the arguments, its position should be set later
with Nst_node_set_pos
.
Parameters:
type
: the type of the node to initialize
Returns:
The new node or NULL
on failure. The error is set.
Nst_node_new_pos
#
Synopsis:
Nst_Node *Nst_node_new_pos(Nst_NodeType type, Nst_Pos start, Nst_Pos end)
Description:
Creates and initializes a new AST node on the heap.
Parameters:
type
: the type of the node to initializestart
: the start position of the nodeend
: the end position of the node
Returns:
The new node or NULL
on failure. The error is set.
Nst_node_set_pos
#
Synopsis:
void Nst_node_set_pos(Nst_Node *node, Nst_Pos start, Nst_Pos end)
Description:
Sets the position of a node.
Nst_node_destroy
#
Synopsis:
void Nst_node_destroy(Nst_Node *node)
Description:
Destroys a node and its children.
Enums#
Nst_NodeType
#
Synopsis:
typedef enum _Nst_NodeType {
Nst_NT_LONG_S,
Nst_NT_WHILE_L,
Nst_NT_DOWHILE_L,
Nst_NT_FOR_L,
Nst_NT_FOR_AS_L,
Nst_NT_FUNC_DECLR,
Nst_NT_RETURN_S,
Nst_NT_CONTINUE_S,
Nst_NT_BREAK_S,
Nst_NT_SWITCH_S,
Nst_NT_TRY_CATCH_S,
// These nodes return a value
Nst_NT_STACK_OP,
Nst_NT_LOCAL_STACK_OP,
Nst_NT_LOCAL_OP,
Nst_NT_ARR_LIT,
Nst_NT_VEC_LIT,
Nst_NT_MAP_LIT,
Nst_NT_VALUE,
Nst_NT_ACCESS,
Nst_NT_EXTRACT_E,
Nst_NT_ASSIGN_E,
Nst_NT_IF_E,
Nst_NT_LAMBDA
} Nst_NodeType
Description:
The types of nodes in the AST.