diff options
Diffstat (limited to '')
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.c | 210 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_yaccer.y | 4 |
2 files changed, 102 insertions, 112 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c index 78414fe..83c6779 100644 --- a/LuaSL/src/LuaSL_LSL_tree.c +++ b/LuaSL/src/LuaSL_LSL_tree.c | |||
@@ -3,9 +3,9 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | 5 | ||
6 | static void outputExpressionToken(LSL_Leaf *content); | ||
7 | static void evaluateExpressionToken(LSL_Leaf *content, LSL_Value *result); | 6 | static void evaluateExpressionToken(LSL_Leaf *content, LSL_Value *result); |
8 | static void outputIntegerToken(LSL_Leaf *content); | 7 | static void outputIntegerToken(LSL_Leaf *content); |
8 | static void outputOperationToken(LSL_Leaf *content); | ||
9 | static void evaluateIntegerToken(LSL_Leaf *content, LSL_Value *result); | 9 | static void evaluateIntegerToken(LSL_Leaf *content, LSL_Value *result); |
10 | 10 | ||
11 | LSL_Token LSL_Tokens[] = | 11 | LSL_Token LSL_Tokens[] = |
@@ -15,62 +15,62 @@ LSL_Token LSL_Tokens[] = | |||
15 | // Left to right, unless oterwise stated. | 15 | // Left to right, unless oterwise stated. |
16 | // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators | 16 | // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators |
17 | 17 | ||
18 | // {LSL_COMMA, ",", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 18 | // {LSL_COMMA, ",", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
19 | // {LSL_INCREMENT_PRE, "++", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, NULL}, | 19 | // {LSL_INCREMENT_PRE, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, NULL}, |
20 | // {LSL_INCREMENT_POST, "++", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, NULL}, | 20 | // {LSL_INCREMENT_POST, "++", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, NULL}, |
21 | // {LSL_DECREMENT_PRE, "--", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, NULL}, | 21 | // {LSL_DECREMENT_PRE, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, NULL}, |
22 | // {LSL_DECREMENT_POST, "--", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, NULL}, | 22 | // {LSL_DECREMENT_POST, "--", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, NULL}, |
23 | // {LSL_DOT, ".", LSL_RIGHT2LEFT, NULL, NULL, NULL}, | 23 | // {LSL_DOT, ".", LSL_RIGHT2LEFT, outputOperationToken, NULL, NULL}, |
24 | // {LSL_ASSIGNMENT_PLAIN, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, NULL}, | 24 | // {LSL_ASSIGNMENT_PLAIN, "=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, NULL}, |
25 | // {LSL_ASSIGNMENT_DIVIDE, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, NULL}, | 25 | // {LSL_ASSIGNMENT_DIVIDE, "/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, NULL}, |
26 | // {LSL_ASSIGNMENT_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, NULL}, | 26 | // {LSL_ASSIGNMENT_MODULO, "%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, NULL}, |
27 | // {LSL_ASSIGNMENT_MULTIPLY, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, NULL}, | 27 | // {LSL_ASSIGNMENT_MULTIPLY, "*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, NULL}, |
28 | // {LSL_ASSIGNMENT_SUBTRACT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, NULL}, | 28 | // {LSL_ASSIGNMENT_SUBTRACT, "-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, NULL}, |
29 | // {LSL_ASSIGNMENT_ADD, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, NULL}, | 29 | // {LSL_ASSIGNMENT_ADD, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, NULL}, |
30 | // {LSL_ASSIGNMENT_CONCATENATE, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, NULL, NULL, NULL}, | 30 | // {LSL_ASSIGNMENT_CONCATENATE, "+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT, outputOperationToken, NULL, NULL}, |
31 | {LSL_PARENTHESIS_OPEN, "(", LSL_INNER2OUTER, NULL, NULL, NULL}, | 31 | {LSL_PARENTHESIS_OPEN, "(", LSL_INNER2OUTER, outputOperationToken, NULL, NULL}, |
32 | {LSL_PARENTHESIS_CLOSE, ")", LSL_INNER2OUTER, NULL, NULL, NULL}, | 32 | {LSL_PARENTHESIS_CLOSE, ")", LSL_INNER2OUTER, outputOperationToken, NULL, NULL}, |
33 | // {LSL_BRACKET_OPEN, "[", LSL_INNER2OUTER | LSL_CREATION, NULL, NULL, NULL}, | 33 | // {LSL_BRACKET_OPEN, "[", LSL_INNER2OUTER | LSL_CREATION, outputOperationToken, NULL, NULL}, |
34 | // {LSL_BRACKET_CLOSE, "]", LSL_INNER2OUTER | LSL_CREATION, NULL, NULL, NULL}, | 34 | // {LSL_BRACKET_CLOSE, "]", LSL_INNER2OUTER | LSL_CREATION, outputOperationToken, NULL, NULL}, |
35 | // {LSL_ANGLE_OPEN, "<", LSL_LEFT2RIGHT | LSL_CREATION, NULL, NULL, NULL}, | 35 | // {LSL_ANGLE_OPEN, "<", LSL_LEFT2RIGHT | LSL_CREATION, outputOperationToken, NULL, NULL}, |
36 | // {LSL_ANGLE_CLOSE, ">", LSL_LEFT2RIGHT | LSL_CREATION, NULL, NULL, NULL}, | 36 | // {LSL_ANGLE_CLOSE, ">", LSL_LEFT2RIGHT | LSL_CREATION, outputOperationToken, NULL, NULL}, |
37 | // {LSL_TYPECAST_OPEN, "(", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, NULL}, | 37 | // {LSL_TYPECAST_OPEN, "(", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, NULL}, |
38 | // {LSL_TYPECAST_CLOSE, ")", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, NULL}, | 38 | // {LSL_TYPECAST_CLOSE, ")", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, NULL}, |
39 | {LSL_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, NULL}, | 39 | {LSL_BIT_NOT, "~", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, NULL}, |
40 | {LSL_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, NULL}, | 40 | {LSL_BOOL_NOT, "!", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, NULL}, |
41 | {LSL_NEGATION, "-", LSL_RIGHT2LEFT | LSL_UNARY, NULL, NULL, NULL}, | 41 | {LSL_NEGATION, "-", LSL_RIGHT2LEFT | LSL_UNARY, outputOperationToken, NULL, NULL}, |
42 | {LSL_DIVIDE, "/", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 42 | {LSL_DIVIDE, "/", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
43 | {LSL_MODULO, "%", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 43 | {LSL_MODULO, "%", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
44 | {LSL_MULTIPLY, "*", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 44 | {LSL_MULTIPLY, "*", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
45 | // {LSL_DOT_PRODUCT, "*", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 45 | // {LSL_DOT_PRODUCT, "*", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
46 | // {LSL_CROSS_PRODUCT, "%", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 46 | // {LSL_CROSS_PRODUCT, "%", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
47 | {LSL_SUBTRACT, "-", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 47 | {LSL_SUBTRACT, "-", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
48 | {LSL_ADD, "+", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 48 | {LSL_ADD, "+", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
49 | // {LSL_CONCATENATE, "+", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 49 | // {LSL_CONCATENATE, "+", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
50 | {LSL_LEFT_SHIFT, "<<", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 50 | {LSL_LEFT_SHIFT, "<<", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
51 | {LSL_RIGHT_SHIFT, ">>", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 51 | {LSL_RIGHT_SHIFT, ">>", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
52 | // QUIRK - Conditionals are executed right to left. Or left to right, depending on who you ask. lol | 52 | // QUIRK - Conditionals are executed right to left. Or left to right, depending on who you ask. lol |
53 | {LSL_LESS_THAN, "<", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 53 | {LSL_LESS_THAN, "<", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
54 | {LSL_GREATER_THAN, ">", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 54 | {LSL_GREATER_THAN, ">", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
55 | {LSL_LESS_EQUAL, "<=", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 55 | {LSL_LESS_EQUAL, "<=", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
56 | {LSL_GREATER_EQUAL, ">=", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 56 | {LSL_GREATER_EQUAL, ">=", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
57 | {LSL_EQUAL, "==", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 57 | {LSL_EQUAL, "==", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
58 | {LSL_NOT_EQUAL, "!=", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 58 | {LSL_NOT_EQUAL, "!=", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
59 | {LSL_BIT_AND, "&", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 59 | {LSL_BIT_AND, "&", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
60 | {LSL_BIT_XOR, "^", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 60 | {LSL_BIT_XOR, "^", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
61 | {LSL_BIT_OR, "|", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 61 | {LSL_BIT_OR, "|", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
62 | // QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher. | 62 | // QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher. |
63 | // QUIRK - No boolean short circuiting. | 63 | // QUIRK - No boolean short circuiting. |
64 | {LSL_BOOL_OR, "||", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 64 | {LSL_BOOL_OR, "||", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
65 | {LSL_BOOL_AND, "&&", LSL_LEFT2RIGHT, NULL, NULL, NULL}, | 65 | {LSL_BOOL_AND, "&&", LSL_LEFT2RIGHT, outputOperationToken, NULL, NULL}, |
66 | 66 | ||
67 | // Then the rest of the syntax tokens. | 67 | // Then the rest of the syntax tokens. |
68 | 68 | ||
69 | // {LSL_COMMENT_LINE, "//", LSL_NONE, NULL, NULL, NULL}, | 69 | // {LSL_COMMENT_LINE, "//", LSL_NONE, NULL, NULL, NULL}, |
70 | // {LSL_COMMENT, "/*", LSL_NONE, NULL, NULL, NULL}, | 70 | // {LSL_COMMENT, "/*", LSL_NONE, NULL, NULL, NULL}, |
71 | // {LSL_TYPE, "", LSL_NONE, NULL, NULL, NULL}, | 71 | // {LSL_TYPE, "type", LSL_NONE, NULL, NULL, NULL}, |
72 | // {LSL_NAME, "", LSL_NONE, NULL, NULL, NULL}, | 72 | // {LSL_NAME, "name", LSL_NONE, NULL, NULL, NULL}, |
73 | // {LSL_IDENTIFIER, "", LSL_NONE, NULL, NULL, NULL}, | 73 | // {LSL_IDENTIFIER, "identifier", LSL_NONE, NULL, NULL, NULL}, |
74 | // {LSL_FLOAT, "float", LSL_NONE, NULL, NULL, NULL}, | 74 | // {LSL_FLOAT, "float", LSL_NONE, NULL, NULL, NULL}, |
75 | {LSL_INTEGER, "integer", LSL_NONE, outputIntegerToken, NULL, evaluateIntegerToken}, | 75 | {LSL_INTEGER, "integer", LSL_NONE, outputIntegerToken, NULL, evaluateIntegerToken}, |
76 | // {LSL_STRING, "string", LSL_NONE, NULL, NULL, NULL}, | 76 | // {LSL_STRING, "string", LSL_NONE, NULL, NULL, NULL}, |
@@ -79,7 +79,7 @@ LSL_Token LSL_Tokens[] = | |||
79 | // {LSL_ROTATION, "rotation", LSL_NONE, NULL, NULL, NULL}, | 79 | // {LSL_ROTATION, "rotation", LSL_NONE, NULL, NULL, NULL}, |
80 | // {LSL_LIST, "list", LSL_NONE, NULL, NULL, NULL}, | 80 | // {LSL_LIST, "list", LSL_NONE, NULL, NULL, NULL}, |
81 | // {LSL_LABEL, "@", LSL_NONE, NULL, NULL, NULL}, | 81 | // {LSL_LABEL, "@", LSL_NONE, NULL, NULL, NULL}, |
82 | {LSL_EXPRESSION, "", LSL_NONE, outputExpressionToken, NULL, evaluateExpressionToken}, | 82 | {LSL_EXPRESSION, "expression", LSL_NONE, NULL, NULL, evaluateExpressionToken}, |
83 | // {LSL_DO, "do", LSL_NONE, NULL, NULL, NULL}, | 83 | // {LSL_DO, "do", LSL_NONE, NULL, NULL, NULL}, |
84 | // {LSL_FOR, "for", LSL_NONE, NULL, NULL, NULL}, | 84 | // {LSL_FOR, "for", LSL_NONE, NULL, NULL, NULL}, |
85 | // {LSL_IF, "if", LSL_NONE, NULL, NULL, NULL}, | 85 | // {LSL_IF, "if", LSL_NONE, NULL, NULL, NULL}, |
@@ -92,11 +92,11 @@ LSL_Token LSL_Tokens[] = | |||
92 | // {LSL_STATEMENT, ";", LSL_NONE, NULL, NULL, NULL}, | 92 | // {LSL_STATEMENT, ";", LSL_NONE, NULL, NULL, NULL}, |
93 | // {LSL_BLOCK_OPEN, "{", LSL_NONE, NULL, NULL, NULL}, | 93 | // {LSL_BLOCK_OPEN, "{", LSL_NONE, NULL, NULL, NULL}, |
94 | // {LSL_BLOCK_CLOSE, "}", LSL_NONE, NULL, NULL, NULL}, | 94 | // {LSL_BLOCK_CLOSE, "}", LSL_NONE, NULL, NULL, NULL}, |
95 | // {LSL_PARAMETER, "", LSL_NONE, NULL, NULL, NULL}, | 95 | // {LSL_PARAMETER, "parameter", LSL_NONE, NULL, NULL, NULL}, |
96 | // {LSL_FUNCTION, "", LSL_NONE, NULL, NULL, NULL}, | 96 | // {LSL_FUNCTION, "function", LSL_NONE, NULL, NULL, NULL}, |
97 | // {LSL_STATE, "", LSL_NONE, NULL, NULL, NULL}, | 97 | // {LSL_STATE, "state", LSL_NONE, NULL, NULL, NULL}, |
98 | // {LSL_SCRIPT, "", LSL_NONE, NULL, NULL, NULL}, | 98 | // {LSL_SCRIPT, "script", LSL_NONE, NULL, NULL, NULL}, |
99 | // {LSL_UNKNOWN, "", LSL_NONE, NULL, NULL, NULL}, | 99 | // {LSL_UNKNOWN, "unknown", LSL_NONE, NULL, NULL, NULL}, |
100 | {999999, NULL, LSL_NONE, NULL, NULL, NULL} | 100 | {999999, NULL, LSL_NONE, NULL, NULL, NULL} |
101 | }; | 101 | }; |
102 | 102 | ||
@@ -128,37 +128,32 @@ static void burnAST(LSL_AST *ast) | |||
128 | free(ast); | 128 | free(ast); |
129 | } | 129 | } |
130 | 130 | ||
131 | LSL_AST *addExpression(LSL_AST *exp) | 131 | LSL_AST *addInteger(int value) |
132 | { | 132 | { |
133 | LSL_AST *ast = newAST(LSL_EXPRESSION, NULL, NULL); | 133 | LSL_AST *ast = newAST(LSL_INTEGER, NULL, NULL); |
134 | 134 | ||
135 | if (ast) | 135 | if (ast) |
136 | ast->content.expressionValue = exp; | 136 | ast->content.integerValue = value; |
137 | 137 | ||
138 | return ast; | 138 | return ast; |
139 | } | 139 | } |
140 | 140 | ||
141 | LSL_AST *addInteger(int value) | ||
142 | { | ||
143 | LSL_AST *exp = newAST(LSL_INTEGER, NULL, NULL); | ||
144 | |||
145 | if (exp) | ||
146 | exp->content.integerValue = value; | ||
147 | |||
148 | return exp; | ||
149 | } | ||
150 | |||
151 | LSL_AST *addOperation(LSL_Operation type, LSL_AST *left, LSL_AST *right) | 141 | LSL_AST *addOperation(LSL_Operation type, LSL_AST *left, LSL_AST *right) |
152 | { | 142 | { |
153 | LSL_AST *exp = newAST(LSL_EXPRESSION, left, right); | 143 | LSL_AST *ast = newAST(type, left, right); |
154 | 144 | ||
155 | if (exp) | 145 | if (ast) |
156 | { | 146 | { |
157 | exp->content.operationValue = type; | 147 | if (LSL_EXPRESSION == type) |
158 | exp->token = tokens[type - lowestToken]; | 148 | { |
149 | ast->content.expressionValue = left; | ||
150 | ast->right = NULL; | ||
151 | } | ||
152 | else | ||
153 | ast->content.operationValue = type; | ||
159 | } | 154 | } |
160 | 155 | ||
161 | return exp; | 156 | return ast; |
162 | } | 157 | } |
163 | 158 | ||
164 | static void evaluateIntegerToken(LSL_Leaf *content, LSL_Value *result) | 159 | static void evaluateIntegerToken(LSL_Leaf *content, LSL_Value *result) |
@@ -173,39 +168,39 @@ static void evaluateIntegerToken(LSL_Leaf *content, LSL_Value *result) | |||
173 | } | 168 | } |
174 | } | 169 | } |
175 | 170 | ||
176 | static void evaluateExpression(LSL_AST *exp, LSL_Value *result) | 171 | static void evaluateExpression(LSL_AST *ast, LSL_Value *result) |
177 | { | 172 | { |
178 | LSL_Value left, right; | 173 | LSL_Value left, right; |
179 | 174 | ||
180 | if ((NULL == exp) || (NULL == result)) | 175 | if ((NULL == ast) || (NULL == result)) |
181 | return; | 176 | return; |
182 | 177 | ||
183 | if (LSL_INTEGER == exp->token->type) | 178 | if (LSL_INTEGER == ast->token->type) |
184 | { | 179 | { |
185 | evaluateIntegerToken(&(exp->content), result); | 180 | evaluateIntegerToken(&(ast->content), result); |
186 | return; | 181 | return; |
187 | } | 182 | } |
188 | else if (LSL_LEFT2RIGHT & exp->token->flags) | 183 | else if (LSL_LEFT2RIGHT & ast->token->flags) |
189 | { | 184 | { |
190 | evaluateExpression(exp->left, &left); | 185 | evaluateExpression(ast->left, &left); |
191 | if (!(LSL_UNARY & exp->token->flags)) | 186 | if (!(LSL_UNARY & ast->token->flags)) |
192 | evaluateExpression(exp->right, &right); | 187 | evaluateExpression(ast->right, &right); |
193 | } | 188 | } |
194 | else if (LSL_RIGHT2LEFT & exp->token->flags) | 189 | else if (LSL_RIGHT2LEFT & ast->token->flags) |
195 | { | 190 | { |
196 | evaluateExpression(exp->right, &right); | 191 | evaluateExpression(ast->right, &right); |
197 | if (!(LSL_UNARY & exp->token->flags)) | 192 | if (!(LSL_UNARY & ast->token->flags)) |
198 | evaluateExpression(exp->left, &left); | 193 | evaluateExpression(ast->left, &left); |
199 | } | 194 | } |
200 | else | 195 | else |
201 | { | 196 | { |
202 | } | 197 | } |
203 | 198 | ||
204 | #ifdef LUASL_DEBUG | 199 | #ifdef LUASL_DEBUG |
205 | printf(" %s ", exp->token->token); | 200 | printf(" %s ", ast->token->token); |
206 | #endif | 201 | #endif |
207 | 202 | ||
208 | switch (exp->content.operationValue) | 203 | switch (ast->content.operationValue) |
209 | { | 204 | { |
210 | #ifdef LUASL_USE_ENUM | 205 | #ifdef LUASL_USE_ENUM |
211 | case LSL_COMMA : | 206 | case LSL_COMMA : |
@@ -271,31 +266,26 @@ static void evaluateExpressionToken(LSL_Leaf *content, LSL_Value *result) | |||
271 | 266 | ||
272 | static void evaluateAST(LSL_AST *ast, LSL_Value *result) | 267 | static void evaluateAST(LSL_AST *ast, LSL_Value *result) |
273 | { | 268 | { |
274 | if ((ast) && (ast->token) && (ast->token->evaluate)) | 269 | if (ast) |
275 | ast->token->evaluate(&(ast->content), result); | ||
276 | } | ||
277 | |||
278 | static void outputExpression(LSL_AST *exp) | ||
279 | { | ||
280 | if (NULL == exp) | ||
281 | return; | ||
282 | |||
283 | if (LSL_INTEGER == exp->token->type) | ||
284 | { | ||
285 | printf("%d", exp->content.integerValue); | ||
286 | } | ||
287 | else | ||
288 | { | 270 | { |
289 | outputExpression(exp->left); | 271 | evaluateAST(ast->left, result); |
290 | printf(" %s ", exp->token->token); | 272 | if ((ast->token) && (ast->token->evaluate)) |
291 | outputExpression(exp->right); | 273 | ast->token->evaluate(&(ast->content), result); |
274 | evaluateAST(ast->right, result); | ||
292 | } | 275 | } |
293 | } | 276 | } |
294 | 277 | ||
295 | static void outputExpressionToken(LSL_Leaf *content) | 278 | static void outputAST(LSL_AST *ast) |
296 | { | 279 | { |
297 | if (content) | 280 | if (ast) |
298 | outputExpression(content->expressionValue); | 281 | { |
282 | outputAST(ast->left); | ||
283 | if ((ast->token) && (ast->token->output)) | ||
284 | ast->token->output(&(ast->content)); | ||
285 | else | ||
286 | printf(" <%s> ", ast->token->token); | ||
287 | outputAST(ast->right); | ||
288 | } | ||
299 | } | 289 | } |
300 | 290 | ||
301 | static void outputIntegerToken(LSL_Leaf *content) | 291 | static void outputIntegerToken(LSL_Leaf *content) |
@@ -304,10 +294,10 @@ static void outputIntegerToken(LSL_Leaf *content) | |||
304 | printf("%d", content->integerValue); | 294 | printf("%d", content->integerValue); |
305 | } | 295 | } |
306 | 296 | ||
307 | static void outputAST(LSL_AST *ast) | 297 | static void outputOperationToken(LSL_Leaf *content) |
308 | { | 298 | { |
309 | if ((ast) && (ast->token) && (ast->token->output)) | 299 | if (content) |
310 | ast->token->output(&(ast->content)); | 300 | printf(" [%s] ", tokens[content->operationValue - lowestToken]->token); |
311 | } | 301 | } |
312 | 302 | ||
313 | static void convertAST2Lua(LSL_AST *ast) | 303 | static void convertAST2Lua(LSL_AST *ast) |
diff --git a/LuaSL/src/LuaSL_yaccer.y b/LuaSL/src/LuaSL_yaccer.y index bbec1be..a3bf1a3 100644 --- a/LuaSL/src/LuaSL_yaccer.y +++ b/LuaSL/src/LuaSL_yaccer.y | |||
@@ -27,8 +27,8 @@ | |||
27 | 27 | ||
28 | %% | 28 | %% |
29 | 29 | ||
30 | input : | 30 | input : |
31 | expr { ((LuaSL_yyparseParam*)data)->ast = addExpression($1); } | 31 | expr { ((LuaSL_yyparseParam*)data)->ast = addOperation(LSL_EXPRESSION, $1, $1); } |
32 | ; | 32 | ; |
33 | 33 | ||
34 | expr : | 34 | expr : |