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.c39
1 files changed, 7 insertions, 32 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c
index e6dfa4c..78414fe 100644
--- a/LuaSL/src/LuaSL_LSL_tree.c
+++ b/LuaSL/src/LuaSL_LSL_tree.c
@@ -104,28 +104,6 @@ LSL_Token **tokens = NULL;
104int lowestToken = 999999; 104int lowestToken = 999999;
105 105
106 106
107static LSL_Expression *newLSLExpression(LSL_Type type, LSL_Expression *left, LSL_Expression *right)
108{
109 LSL_Expression *exp = malloc(sizeof(LSL_Expression));
110
111 if (exp == NULL) return NULL;
112
113 exp->left = left;
114 exp->right = right;
115 exp->token = tokens[type - lowestToken];
116
117 return exp;
118}
119
120static void burnLSLExpression(LSL_Expression *exp)
121{
122 if (exp == NULL) return;
123
124 burnLSLExpression(exp->left);
125 burnLSLExpression(exp->right);
126 free(exp);
127}
128
129static LSL_AST *newAST(LSL_Type type, LSL_AST *left, LSL_AST *right) 107static LSL_AST *newAST(LSL_Type type, LSL_AST *left, LSL_AST *right)
130{ 108{
131 LSL_AST *ast = malloc(sizeof(LSL_AST)); 109 LSL_AST *ast = malloc(sizeof(LSL_AST));
@@ -147,13 +125,10 @@ static void burnAST(LSL_AST *ast)
147 125
148 burnAST(ast->left); 126 burnAST(ast->left);
149 burnAST(ast->right); 127 burnAST(ast->right);
150 // Burn the contents to.
151 if ((ast->token) && (ast->token->type == LSL_EXPRESSION))
152 burnLSLExpression(ast->content.expressionValue);
153 free(ast); 128 free(ast);
154} 129}
155 130
156LSL_AST *addExpression(LSL_Expression *exp) 131LSL_AST *addExpression(LSL_AST *exp)
157{ 132{
158 LSL_AST *ast = newAST(LSL_EXPRESSION, NULL, NULL); 133 LSL_AST *ast = newAST(LSL_EXPRESSION, NULL, NULL);
159 134
@@ -163,9 +138,9 @@ LSL_AST *addExpression(LSL_Expression *exp)
163 return ast; 138 return ast;
164} 139}
165 140
166LSL_Expression *addInteger(int value) 141LSL_AST *addInteger(int value)
167{ 142{
168 LSL_Expression *exp = newLSLExpression(LSL_INTEGER, NULL, NULL); 143 LSL_AST *exp = newAST(LSL_INTEGER, NULL, NULL);
169 144
170 if (exp) 145 if (exp)
171 exp->content.integerValue = value; 146 exp->content.integerValue = value;
@@ -173,9 +148,9 @@ LSL_Expression *addInteger(int value)
173 return exp; 148 return exp;
174} 149}
175 150
176LSL_Expression *addOperation(LSL_Operation type, LSL_Expression *left, LSL_Expression *right) 151LSL_AST *addOperation(LSL_Operation type, LSL_AST *left, LSL_AST *right)
177{ 152{
178 LSL_Expression *exp = newLSLExpression(LSL_EXPRESSION, left, right); 153 LSL_AST *exp = newAST(LSL_EXPRESSION, left, right);
179 154
180 if (exp) 155 if (exp)
181 { 156 {
@@ -198,7 +173,7 @@ static void evaluateIntegerToken(LSL_Leaf *content, LSL_Value *result)
198 } 173 }
199} 174}
200 175
201static void evaluateExpression(LSL_Expression *exp, LSL_Value *result) 176static void evaluateExpression(LSL_AST *exp, LSL_Value *result)
202{ 177{
203 LSL_Value left, right; 178 LSL_Value left, right;
204 179
@@ -300,7 +275,7 @@ static void evaluateAST(LSL_AST *ast, LSL_Value *result)
300 ast->token->evaluate(&(ast->content), result); 275 ast->token->evaluate(&(ast->content), result);
301} 276}
302 277
303static void outputExpression(LSL_Expression *exp) 278static void outputExpression(LSL_AST *exp)
304{ 279{
305 if (NULL == exp) 280 if (NULL == exp)
306 return; 281 return;