aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_LSL_tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/src/LuaSL_LSL_tree.c')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c
new file mode 100644
index 0000000..78da8e7
--- /dev/null
+++ b/LuaSL/src/LuaSL_LSL_tree.c
@@ -0,0 +1,63 @@
1/*
2 * Implementation of functions used to build the abstract syntax tree.
3 */
4
5#include "LuaSL_LSL_tree.h"
6#include <stdlib.h>
7
8/**
9 * @brief Allocates space for expression
10 * @return The expression or NULL if not enough memory
11 */
12static SExpression* allocateExpression()
13{
14 SExpression* b = malloc(sizeof *b);
15
16 if( b == NULL ) return NULL;
17
18 b->type = eVALUE;
19 b->value = 0;
20
21 b->left = NULL;
22 b->right = NULL;
23
24 return b;
25}
26
27SExpression* createNumber(int value)
28{
29 SExpression* b = allocateExpression();
30
31 if( b == NULL ) return NULL;
32
33 b->type = eVALUE;
34 b->value = value;
35
36 return b;
37}
38
39SExpression *createOperation(
40 EOperationType type,
41 SExpression *left,
42 SExpression *right)
43{
44 SExpression* b = allocateExpression();
45
46 if( b == NULL ) return NULL;
47
48 b->type = type;
49 b->left = left;
50 b->right = right;
51
52 return b;
53}
54
55void deleteExpression(SExpression *b)
56{
57 if (b == NULL) return;
58
59 deleteExpression(b->left);
60 deleteExpression(b->right);
61
62 free(b);
63}