aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-07 19:26:07 +1000
committerDavid Walter Seikel2012-01-07 19:26:07 +1000
commit8e5c2dcb54fc39ad10101bf7e705e7729c62c965 (patch)
treec9ed8fdba83a4ac67d94637db58aacf625c32450 /LuaSL
parentEvaluate expressions using the new token table. (diff)
downloadSledjHamr-8e5c2dcb54fc39ad10101bf7e705e7729c62c965.zip
SledjHamr-8e5c2dcb54fc39ad10101bf7e705e7729c62c965.tar.gz
SledjHamr-8e5c2dcb54fc39ad10101bf7e705e7729c62c965.tar.bz2
SledjHamr-8e5c2dcb54fc39ad10101bf7e705e7729c62c965.tar.xz
We don't need LSL_Expression.
Diffstat (limited to 'LuaSL')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.c39
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h18
2 files changed, 12 insertions, 45 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;
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 0d49737..4764ce8 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -122,7 +122,7 @@ typedef int LSL_Type;
122typedef struct 122typedef struct
123{ 123{
124 LSL_Type type; 124 LSL_Type type;
125 struct LSL_Expression *expressions; 125 struct LSL_AST *expressions;
126} LSL_Statement; 126} LSL_Statement;
127 127
128typedef struct 128typedef struct
@@ -167,7 +167,7 @@ typedef union LSL_Leaf
167 union LSL_Leaf *listValue; 167 union LSL_Leaf *listValue;
168 char *labelValue; 168 char *labelValue;
169 LSL_Operation operationValue; 169 LSL_Operation operationValue;
170 struct LSL_Expression *expressionValue; 170 struct LSL_AST *expressionValue;
171 LSL_Statement *doValue; 171 LSL_Statement *doValue;
172 LSL_Statement *forValue; 172 LSL_Statement *forValue;
173 LSL_Statement *ifValue; 173 LSL_Statement *ifValue;
@@ -209,14 +209,6 @@ typedef struct
209 LSL_Leaf content; 209 LSL_Leaf content;
210} LSL_Identifier; 210} LSL_Identifier;
211 211
212typedef struct LSL_Expression
213{
214 struct LSL_Expression *left;
215 struct LSL_Expression *right;
216 LSL_Token *token;
217 LSL_Leaf content;
218} LSL_Expression;
219
220typedef struct LSL_AST 212typedef struct LSL_AST
221{ 213{
222 struct LSL_AST *left; 214 struct LSL_AST *left;
@@ -251,9 +243,9 @@ typedef struct
251#define YYLEX_PARAM ((LuaSL_yyparseParam*)data)->scanner 243#define YYLEX_PARAM ((LuaSL_yyparseParam*)data)->scanner
252 244
253 245
254LSL_AST *addExpression(LSL_Expression *exp); 246LSL_AST *addExpression(LSL_AST *exp);
255LSL_Expression *addInteger(int value); 247LSL_AST *addInteger(int value);
256LSL_Expression *addOperation(LSL_Operation type, LSL_Expression *left, LSL_Expression *right); 248LSL_AST *addOperation(LSL_Operation type, LSL_AST *left, LSL_AST *right);
257 249
258int yyerror(const char *msg); 250int yyerror(const char *msg);
259int yyparse(void *param); 251int yyparse(void *param);