diff options
author | David Walter Seikel | 2012-01-06 16:27:25 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-06 16:27:25 +1000 |
commit | e85ff16e367aaf3b0e68e6a79615496d179f85ca (patch) | |
tree | 91f7df33ee3d0247c7098bc5d0971b95a05a9712 /LuaSL/src | |
parent | Add more debugging stuff. (diff) | |
download | SledjHamr-e85ff16e367aaf3b0e68e6a79615496d179f85ca.zip SledjHamr-e85ff16e367aaf3b0e68e6a79615496d179f85ca.tar.gz SledjHamr-e85ff16e367aaf3b0e68e6a79615496d179f85ca.tar.bz2 SledjHamr-e85ff16e367aaf3b0e68e6a79615496d179f85ca.tar.xz |
Even more debugging stuff, and make it selectable if the parser uses #defines or enums for tokens.
NOTE - enum does not work anyway with btyacc.
Diffstat (limited to 'LuaSL/src')
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.c | 267 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.h | 28 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_lexer.l | 27 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_yaccer.y | 7 |
4 files changed, 207 insertions, 122 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c index 552de04..a69b0d3 100644 --- a/LuaSL/src/LuaSL_LSL_tree.c +++ b/LuaSL/src/LuaSL_LSL_tree.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #define LSL_Tokens_define | 7 | #define LSL_Tokens_define |
8 | #include "LuaSL_LSL_tree.h" | 8 | #include "LuaSL_LSL_tree.h" |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
10 | #include <stdio.h> | ||
10 | 11 | ||
11 | 12 | ||
12 | /** | 13 | /** |
@@ -88,10 +89,18 @@ LSL_Expression *newTree(const char *expr) | |||
88 | LuaSL_yyparseParam param; | 89 | LuaSL_yyparseParam param; |
89 | YY_BUFFER_STATE state; | 90 | YY_BUFFER_STATE state; |
90 | 91 | ||
92 | #ifdef LUASL_DEBUG | ||
93 | yydebug= 5; | ||
94 | #endif | ||
95 | |||
91 | param.expression = NULL; | 96 | param.expression = NULL; |
92 | if (yylex_init(&(param.scanner))) | 97 | if (yylex_init(&(param.scanner))) |
93 | return NULL; | 98 | return NULL; |
94 | 99 | ||
100 | #ifdef LUASL_DEBUG | ||
101 | yyset_debug(1, param.scanner); | ||
102 | #endif | ||
103 | |||
95 | state = yy_scan_string(expr, param.scanner); | 104 | state = yy_scan_string(expr, param.scanner); |
96 | if (yyparse(¶m)) | 105 | if (yyparse(¶m)) |
97 | return NULL; | 106 | return NULL; |
@@ -106,88 +115,112 @@ int evaluateExpression(LSL_Expression *exp, int old) | |||
106 | { | 115 | { |
107 | switch(exp->type) | 116 | switch(exp->type) |
108 | { | 117 | { |
109 | // case LSL_COMMENT : | 118 | #ifdef LUASL_USE_ENUM |
110 | // case LSL_TYPE : | 119 | case LSL_COMMENT : |
111 | // case LSL_NAME : | 120 | case LSL_TYPE : |
112 | // case LSL_IDENTIFIER : | 121 | case LSL_NAME : |
113 | // break; | 122 | case LSL_IDENTIFIER : |
114 | // case LSL_FLOAT : return (int) exp->value.floatValue; | 123 | break; |
115 | case LSL_INTEGER : return exp->value.integerValue; | 124 | case LSL_FLOAT : return (int) exp->value.floatValue; |
116 | // case LSL_STRING : | 125 | #endif |
117 | // case LSL_KEY : | 126 | case LSL_INTEGER : |
118 | // case LSL_VECTOR : | 127 | #ifdef LUASL_DEBUG |
119 | // case LSL_ROTATION : | 128 | printf("%d", exp->value.integerValue); |
120 | // case LSL_LIST : | 129 | #endif |
121 | // case LSL_LABEL : | 130 | return exp->value.integerValue; |
122 | // break; | 131 | #ifdef LUASL_USE_ENUM |
132 | case LSL_STRING : | ||
133 | case LSL_KEY : | ||
134 | case LSL_VECTOR : | ||
135 | case LSL_ROTATION : | ||
136 | case LSL_LIST : | ||
137 | case LSL_LABEL : | ||
138 | break; | ||
139 | #endif | ||
123 | case LSL_EXPRESSION : | 140 | case LSL_EXPRESSION : |
124 | { | 141 | { |
125 | switch (exp->expression) | 142 | switch (exp->expression) |
126 | { | 143 | { |
127 | // case LSL_COMMA : | 144 | #ifdef LUASL_USE_ENUM |
128 | // case LSL_INCREMENT_PRE : | 145 | case LSL_COMMA : |
129 | // case LSL_INCREMENT_POST : | 146 | case LSL_INCREMENT_PRE : |
130 | // case LSL_DECREMENT_PRE : | 147 | case LSL_INCREMENT_POST : |
131 | // case LSL_DECREMENT_POST : | 148 | case LSL_DECREMENT_PRE : |
132 | // case LSL_DOT : | 149 | case LSL_DECREMENT_POST : |
133 | // case LSL_ASSIGNMENT_PLAIN : | 150 | case LSL_DOT : |
134 | // case LSL_ASSIGNMENT_DIVIDE : | 151 | case LSL_ASSIGNMENT_PLAIN : |
135 | // case LSL_ASSIGNMENT_MODULO : | 152 | case LSL_ASSIGNMENT_DIVIDE : |
136 | // case LSL_ASSIGNMENT_MULTIPLY : | 153 | case LSL_ASSIGNMENT_MODULO : |
137 | // case LSL_ASSIGNMENT_SUBTRACT : | 154 | case LSL_ASSIGNMENT_MULTIPLY : |
138 | // case LSL_ASSIGNMENT_ADD : | 155 | case LSL_ASSIGNMENT_SUBTRACT : |
139 | // case LSL_ASSIGNMENT_CONCATENATE : | 156 | case LSL_ASSIGNMENT_ADD : |
157 | case LSL_ASSIGNMENT_CONCATENATE : | ||
140 | case LSL_PARENTHESIS_OPEN : | 158 | case LSL_PARENTHESIS_OPEN : |
141 | case LSL_PARENTHESIS_CLOSE : | 159 | case LSL_PARENTHESIS_CLOSE : |
142 | // case LSL_BRACKET_OPEN : | 160 | case LSL_BRACKET_OPEN : |
143 | // case LSL_BRACKET_CLOSE : | 161 | case LSL_BRACKET_CLOSE : |
144 | // case LSL_ANGLE_OPEN : | 162 | case LSL_ANGLE_OPEN : |
145 | // case LSL_ANGLE_CLOSE : | 163 | case LSL_ANGLE_CLOSE : |
146 | // case LSL_TYPECAST : | 164 | case LSL_TYPECAST : |
147 | // case LSL_BIT_NOT : | 165 | case LSL_BIT_NOT : |
148 | // case LSL_BOOL_NOT : | 166 | case LSL_BOOL_NOT : |
149 | // case LSL_NEGATION : | 167 | case LSL_NEGATION : |
150 | break; | 168 | break; |
151 | // case LSL_DIVIDE : return evaluateExpression(exp->left, old) / evaluateExpression(exp->right, old); | 169 | case LSL_DIVIDE : return evaluateExpression(exp->left, old) / evaluateExpression(exp->right, old); |
152 | // case LSL_MODULO : return evaluateExpression(exp->left, old) % evaluateExpression(exp->right, old); | 170 | case LSL_MODULO : return evaluateExpression(exp->left, old) % evaluateExpression(exp->right, old); |
153 | case LSL_MULTIPLY : return evaluateExpression(exp->left, old) * evaluateExpression(exp->right, old); | 171 | #endif |
154 | // case LSL_DOT_PRODUCT : break; | 172 | case LSL_MULTIPLY : |
155 | // case LSL_CROSS_PRODUCT : break; | 173 | #ifdef LUASL_DEBUG |
156 | // case LSL_SUBTRACT : return evaluateExpression(exp->left, old) - evaluateExpression(exp->right, old); | 174 | printf(" * "); |
157 | case LSL_ADD : return evaluateExpression(exp->left, old) + evaluateExpression(exp->right, old); | 175 | #endif |
158 | // case LSL_CONCATENATE : break; | 176 | return evaluateExpression(exp->left, old) * evaluateExpression(exp->right, old); |
159 | // case LSL_LEFT_SHIFT : return evaluateExpression(exp->left, old) << evaluateExpression(exp->right, old); | 177 | #ifdef LUASL_USE_ENUM |
160 | // case LSL_RIGHT_SHIFT : return evaluateExpression(exp->left, old) >> evaluateExpression(exp->right, old); | 178 | case LSL_DOT_PRODUCT : break; |
161 | // case LSL_LESS_THAN : return evaluateExpression(exp->left, old) < evaluateExpression(exp->right, old); | 179 | case LSL_CROSS_PRODUCT : break; |
162 | // case LSL_GREATER_THAN : return evaluateExpression(exp->left, old) > evaluateExpression(exp->right, old); | 180 | case LSL_SUBTRACT : return evaluateExpression(exp->left, old) - evaluateExpression(exp->right, old); |
163 | // case LSL_LESS_EQUAL : return evaluateExpression(exp->left, old) <= evaluateExpression(exp->right, old); | 181 | #endif |
164 | // case LSL_GREATER_EQUAL : return evaluateExpression(exp->left, old) >= evaluateExpression(exp->right, old); | 182 | case LSL_ADD : |
165 | // case LSL_EQUAL : return evaluateExpression(exp->left, old) == evaluateExpression(exp->right, old); | 183 | #ifdef LUASL_DEBUG |
166 | // case LSL_NOT_EQUAL : return evaluateExpression(exp->left, old) != evaluateExpression(exp->right, old); | 184 | printf(" + "); |
167 | // case LSL_BIT_AND : return evaluateExpression(exp->left, old) & evaluateExpression(exp->right, old); | 185 | #endif |
168 | // case LSL_BIT_XOR : return evaluateExpression(exp->left, old) ^ evaluateExpression(exp->right, old); | 186 | return evaluateExpression(exp->left, old) + evaluateExpression(exp->right, old); |
169 | // case LSL_BIT_OR : return evaluateExpression(exp->left, old) | evaluateExpression(exp->right, old); | 187 | #ifdef LUASL_USE_ENUM |
170 | // case LSL_BOOL_OR : return evaluateExpression(exp->left, old) || evaluateExpression(exp->right, old); | 188 | case LSL_CONCATENATE : break; |
171 | // case LSL_BOOL_AND : return evaluateExpression(exp->left, old) && evaluateExpression(exp->right, old); | 189 | case LSL_LEFT_SHIFT : return evaluateExpression(exp->left, old) << evaluateExpression(exp->right, old); |
190 | case LSL_RIGHT_SHIFT : return evaluateExpression(exp->left, old) >> evaluateExpression(exp->right, old); | ||
191 | case LSL_LESS_THAN : return evaluateExpression(exp->left, old) < evaluateExpression(exp->right, old); | ||
192 | case LSL_GREATER_THAN : return evaluateExpression(exp->left, old) > evaluateExpression(exp->right, old); | ||
193 | case LSL_LESS_EQUAL : return evaluateExpression(exp->left, old) <= evaluateExpression(exp->right, old); | ||
194 | case LSL_GREATER_EQUAL : return evaluateExpression(exp->left, old) >= evaluateExpression(exp->right, old); | ||
195 | case LSL_EQUAL : return evaluateExpression(exp->left, old) == evaluateExpression(exp->right, old); | ||
196 | case LSL_NOT_EQUAL : return evaluateExpression(exp->left, old) != evaluateExpression(exp->right, old); | ||
197 | case LSL_BIT_AND : return evaluateExpression(exp->left, old) & evaluateExpression(exp->right, old); | ||
198 | case LSL_BIT_XOR : return evaluateExpression(exp->left, old) ^ evaluateExpression(exp->right, old); | ||
199 | case LSL_BIT_OR : return evaluateExpression(exp->left, old) | evaluateExpression(exp->right, old); | ||
200 | case LSL_BOOL_OR : return evaluateExpression(exp->left, old) || evaluateExpression(exp->right, old); | ||
201 | case LSL_BOOL_AND : return evaluateExpression(exp->left, old) && evaluateExpression(exp->right, old); | ||
202 | #endif | ||
172 | } | 203 | } |
173 | break; | 204 | break; |
174 | } | 205 | } |
175 | // case LSL_DO : | 206 | #ifdef LUASL_USE_ENUM |
176 | // case LSL_FOR : | 207 | case LSL_DO : |
177 | // case LSL_IF : | 208 | case LSL_FOR : |
178 | // case LSL_ELSE : | 209 | case LSL_IF : |
179 | // case LSL_ELSEIF : | 210 | case LSL_ELSE : |
180 | // case LSL_JUMP : | 211 | case LSL_ELSEIF : |
181 | // case LSL_STATE_CHANGE : | 212 | case LSL_JUMP : |
182 | // case LSL_WHILE : | 213 | case LSL_STATE_CHANGE : |
183 | // case LSL_RETURN : | 214 | case LSL_WHILE : |
184 | // case LSL_STATEMENT : | 215 | case LSL_RETURN : |
185 | // case LSL_BLOCK : | 216 | case LSL_STATEMENT : |
186 | // case LSL_PARAMETER : | 217 | case LSL_BLOCK : |
187 | // case LSL_FUNCTION : | 218 | case LSL_PARAMETER : |
188 | // case LSL_STATE : | 219 | case LSL_FUNCTION : |
189 | // case LSL_SCRIPT : | 220 | case LSL_STATE : |
190 | // break; | 221 | case LSL_SCRIPT : |
222 | break; | ||
223 | #endif | ||
191 | } | 224 | } |
192 | 225 | ||
193 | return old; | 226 | return old; |
@@ -198,45 +231,54 @@ void outputExpression(LSL_Expression *exp) | |||
198 | { | 231 | { |
199 | switch(exp->type) | 232 | switch(exp->type) |
200 | { | 233 | { |
201 | // case LSL_COMMENT : return; | 234 | #ifdef LUASL_USE_ENUM |
202 | // case LSL_TYPE : return; | 235 | case LSL_COMMENT : return; |
203 | // case LSL_NAME : return; | 236 | case LSL_TYPE : return; |
204 | // case LSL_IDENTIFIER : return; | 237 | case LSL_NAME : return; |
205 | // case LSL_FLOAT : printf("%f", exp->value.floatValue); break; | 238 | case LSL_IDENTIFIER : return; |
239 | case LSL_FLOAT : printf("%f", exp->value.floatValue); break; | ||
240 | #endif | ||
206 | case LSL_INTEGER : printf("%d", exp->value.integerValue); break; | 241 | case LSL_INTEGER : printf("%d", exp->value.integerValue); break; |
207 | // case LSL_STRING : return; | 242 | #ifdef LUASL_USE_ENUM |
208 | // case LSL_KEY : return; | 243 | case LSL_STRING : return; |
209 | // case LSL_VECTOR : return; | 244 | case LSL_KEY : return; |
210 | // case LSL_ROTATION : return; | 245 | case LSL_VECTOR : return; |
211 | // case LSL_LIST : return; | 246 | case LSL_ROTATION : return; |
212 | // case LSL_LABEL : return; | 247 | case LSL_LIST : return; |
248 | case LSL_LABEL : return; | ||
249 | #endif | ||
213 | case LSL_EXPRESSION : | 250 | case LSL_EXPRESSION : |
214 | outputExpression(exp->left); | 251 | outputExpression(exp->left); |
215 | // printf(" %s ", LSL_Tokens[exp->expression].token); | 252 | #ifdef LUASL_USE_ENUM |
216 | printf(" # "); | 253 | printf(" %s ", LSL_Tokens[exp->expression - LSL_COMMA].token); |
254 | #else | ||
255 | printf(" # "); | ||
256 | #endif | ||
217 | outputExpression(exp->right); | 257 | outputExpression(exp->right); |
218 | break; | 258 | break; |
219 | // case LSL_DO : return; | 259 | #ifdef LUASL_USE_ENUM |
220 | // case LSL_FOR : return; | 260 | case LSL_DO : return; |
221 | // case LSL_IF : return; | 261 | case LSL_FOR : return; |
222 | // case LSL_ELSE : return; | 262 | case LSL_IF : return; |
223 | // case LSL_ELSEIF : return; | 263 | case LSL_ELSE : return; |
224 | // case LSL_JUMP : return; | 264 | case LSL_ELSEIF : return; |
225 | // case LSL_STATE_CHANGE : return; | 265 | case LSL_JUMP : return; |
226 | // case LSL_WHILE : return; | 266 | case LSL_STATE_CHANGE : return; |
227 | // case LSL_RETURN : return; | 267 | case LSL_WHILE : return; |
228 | // case LSL_STATEMENT : return; | 268 | case LSL_RETURN : return; |
229 | // case LSL_BLOCK : return; | 269 | case LSL_STATEMENT : return; |
230 | // case LSL_PARAMETER : return; | 270 | case LSL_BLOCK : return; |
231 | // case LSL_FUNCTION : return; | 271 | case LSL_PARAMETER : return; |
232 | // case LSL_STATE : return; | 272 | case LSL_FUNCTION : return; |
233 | // case LSL_SCRIPT : return; | 273 | case LSL_STATE : return; |
274 | case LSL_SCRIPT : return; | ||
275 | #endif | ||
234 | } | 276 | } |
235 | } | 277 | } |
236 | 278 | ||
237 | void convertExpression2Lua(LSL_Expression *exp) | 279 | void convertExpression2Lua(LSL_Expression *exp) |
238 | { | 280 | { |
239 | /* | 281 | #ifdef LUASL_USE_ENUM |
240 | switch(exp->type) | 282 | switch(exp->type) |
241 | { | 283 | { |
242 | case LSL_COMMENT : return; | 284 | case LSL_COMMENT : return; |
@@ -268,7 +310,7 @@ void convertExpression2Lua(LSL_Expression *exp) | |||
268 | case LSL_STATE : return; | 310 | case LSL_STATE : return; |
269 | case LSL_SCRIPT : return; | 311 | case LSL_SCRIPT : return; |
270 | } | 312 | } |
271 | */ | 313 | #endif |
272 | } | 314 | } |
273 | 315 | ||
274 | int yyerror(const char *msg) | 316 | int yyerror(const char *msg) |
@@ -277,3 +319,24 @@ int yyerror(const char *msg) | |||
277 | return 0; | 319 | return 0; |
278 | } | 320 | } |
279 | 321 | ||
322 | int main(void) | ||
323 | { | ||
324 | const char test[] = " 4 + 2 * 10 + 3 * ( 5 + 1 )"; | ||
325 | LSL_Expression *exp; | ||
326 | |||
327 | if ((exp = newTree(test))) | ||
328 | { | ||
329 | int result = evaluateExpression(exp, 0); | ||
330 | |||
331 | #ifdef LUASL_DEBUG | ||
332 | printf("\n"); | ||
333 | #endif | ||
334 | printf("Result of '%s' is %d\n", test, result); | ||
335 | outputExpression(exp); | ||
336 | printf("\n"); | ||
337 | burnLSLExpression(exp); | ||
338 | } | ||
339 | |||
340 | return 0; | ||
341 | } | ||
342 | |||
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 7973509..42cf0ac 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h | |||
@@ -8,7 +8,17 @@ | |||
8 | #define YY_NO_UNISTD_H 1 | 8 | #define YY_NO_UNISTD_H 1 |
9 | #endif // YY_NO_UNISTD_H | 9 | #endif // YY_NO_UNISTD_H |
10 | 10 | ||
11 | //#define LUASL_USE_ENUM | ||
12 | #define LUASL_DEBUG | ||
13 | |||
14 | #ifndef LUASL_USE_ENUM | ||
11 | #include "LuaSL_yaccer.tab.h" | 15 | #include "LuaSL_yaccer.tab.h" |
16 | #endif | ||
17 | |||
18 | #define YYERRCODE 256 | ||
19 | #define YYDEBUG 1 | ||
20 | extern int yydebug; | ||
21 | |||
12 | 22 | ||
13 | // http://w-hat.com/stackdepth is a useful discussion about some aspects of the LL parser. | 23 | // http://w-hat.com/stackdepth is a useful discussion about some aspects of the LL parser. |
14 | 24 | ||
@@ -22,12 +32,12 @@ typedef enum | |||
22 | LSL_CREATION = 16 | 32 | LSL_CREATION = 16 |
23 | } LSL_Flags; | 33 | } LSL_Flags; |
24 | 34 | ||
25 | /* | 35 | #ifdef LUASL_USE_ENUM |
26 | typedef enum // In order of precedence, high to low. | 36 | typedef enum // In order of precedence, high to low. |
27 | // Left to right, unless oterwise stated. | 37 | // Left to right, unless oterwise stated. |
28 | // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators | 38 | // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators |
29 | { | 39 | { |
30 | LSL_COMMA, | 40 | LSL_COMMA = 257, |
31 | LSL_INCREMENT_PRE, // Right to left. | 41 | LSL_INCREMENT_PRE, // Right to left. |
32 | LSL_INCREMENT_POST, // Right to left. | 42 | LSL_INCREMENT_POST, // Right to left. |
33 | LSL_DECREMENT_PRE, // Right to left. | 43 | LSL_DECREMENT_PRE, // Right to left. |
@@ -72,9 +82,9 @@ typedef enum // In order of precedence, high to low. | |||
72 | LSL_BOOL_OR, | 82 | LSL_BOOL_OR, |
73 | LSL_BOOL_AND | 83 | LSL_BOOL_AND |
74 | } LSL_Operation; | 84 | } LSL_Operation; |
75 | */ | 85 | #else |
76 | |||
77 | typedef int LSL_Operation; | 86 | typedef int LSL_Operation; |
87 | #endif | ||
78 | 88 | ||
79 | typedef struct | 89 | typedef struct |
80 | { | 90 | { |
@@ -137,10 +147,11 @@ LSL_Operator LSL_Tokens[] = | |||
137 | }; | 147 | }; |
138 | #endif | 148 | #endif |
139 | 149 | ||
140 | /* | 150 | |
151 | #ifdef LUASL_USE_ENUM | ||
141 | typedef enum | 152 | typedef enum |
142 | { | 153 | { |
143 | LSL_COMMENT, | 154 | LSL_COMMENT = (LSL_BOOL_AND + 1), |
144 | LSL_TYPE, | 155 | LSL_TYPE, |
145 | LSL_NAME, | 156 | LSL_NAME, |
146 | LSL_IDENTIFIER, | 157 | LSL_IDENTIFIER, |
@@ -169,11 +180,10 @@ typedef enum | |||
169 | LSL_STATE, | 180 | LSL_STATE, |
170 | LSL_SCRIPT | 181 | LSL_SCRIPT |
171 | } LSL_Type; | 182 | } LSL_Type; |
172 | */ | 183 | #else |
173 | |||
174 | typedef int LSL_Type; | 184 | typedef int LSL_Type; |
175 | #define LSL_EXPRESSION 1 | 185 | #define LSL_EXPRESSION 1 |
176 | 186 | #endif | |
177 | 187 | ||
178 | #ifdef LSL_Keywords_define | 188 | #ifdef LSL_Keywords_define |
179 | char *LSL_Keywords[] = | 189 | char *LSL_Keywords[] = |
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l index 478e62c..5e7d930 100644 --- a/LuaSL/src/LuaSL_lexer.l +++ b/LuaSL/src/LuaSL_lexer.l | |||
@@ -3,26 +3,35 @@ | |||
3 | #define excludeLexer | 3 | #define excludeLexer |
4 | #include "LuaSL_LSL_tree.h" | 4 | #include "LuaSL_LSL_tree.h" |
5 | 5 | ||
6 | #ifdef LUASL_DEBUG | ||
7 | #undef ECHO | ||
8 | #define ECHO printf ("[%s]\n", yytext) | ||
9 | #else | ||
10 | #undef ECHO | ||
11 | #define ECHO {} | ||
12 | #endif | ||
13 | |||
14 | |||
6 | %} | 15 | %} |
7 | 16 | ||
8 | %option reentrant noyywrap never-interactive nounistd | 17 | %option reentrant noyywrap never-interactive nounistd |
9 | %option bison-bridge | 18 | %option bison-bridge |
10 | 19 | ||
11 | SPACE [ \r\n\t]* | 20 | SPACE [ \r\n\t]* |
21 | NAME [a-zA-Z_][a-zA-Z0-9_]* | ||
12 | NUMBER [0-9]+ | 22 | NUMBER [0-9]+ |
13 | NAME [a-zA-Z][a-zA-Z0-9]* | ||
14 | 23 | ||
15 | %% | 24 | %% |
16 | 25 | ||
17 | {SPACE} { /* Skip blanks. */ } | 26 | {SPACE} { ECHO; /* Skip blanks. */ } |
18 | {NUMBER} { yylval->integerValue = atoi(yytext); return LSL_INTEGER; } | 27 | {NAME} { ECHO; /* yylval->nameValue=strdup(yytext); return LSL_NAME; */ } |
19 | {NAME} { /* yylval->nameValue=strdup(yytext); return LSL_NAME; */ } | 28 | {NUMBER} { ECHO; yylval->integerValue = atoi(yytext); return LSL_INTEGER; } |
20 | 29 | ||
21 | "*" { return LSL_MULTIPLY; } | 30 | "(" { ECHO; return LSL_PARENTHESIS_OPEN; } |
22 | "+" { return LSL_ADD; } | 31 | ")" { ECHO; return LSL_PARENTHESIS_CLOSE; } |
23 | "(" { return LSL_PARENTHESIS_OPEN; } | 32 | "*" { ECHO; return LSL_MULTIPLY; } |
24 | ")" { return LSL_PARENTHESIS_CLOSE; } | 33 | "+" { ECHO; return LSL_ADD; } |
25 | . { /* This should return an "unknown character" error */ } | 34 | . { ECHO; printf(" unexpected character.\n"); } |
26 | 35 | ||
27 | %% | 36 | %% |
28 | 37 | ||
diff --git a/LuaSL/src/LuaSL_yaccer.y b/LuaSL/src/LuaSL_yaccer.y index 897a83e..414b5e9 100644 --- a/LuaSL/src/LuaSL_yaccer.y +++ b/LuaSL/src/LuaSL_yaccer.y | |||
@@ -2,6 +2,9 @@ | |||
2 | 2 | ||
3 | #include "LuaSL_LSL_tree.h" | 3 | #include "LuaSL_LSL_tree.h" |
4 | 4 | ||
5 | //extern char *yytext; | ||
6 | //#define YYDEBUG_LEXER_TEXT yytext | ||
7 | |||
5 | %} | 8 | %} |
6 | 9 | ||
7 | %define api.pure | 10 | %define api.pure |
@@ -25,9 +28,9 @@ input: | |||
25 | ; | 28 | ; |
26 | 29 | ||
27 | expr: | 30 | expr: |
28 | expr LSL_ADD expr { $$ = addOperation( LSL_ADD, $1, $3 ); } | 31 | LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE { $$ = $2; } |
29 | | expr LSL_MULTIPLY expr { $$ = addOperation( LSL_MULTIPLY, $1, $3 ); } | 32 | | expr LSL_MULTIPLY expr { $$ = addOperation( LSL_MULTIPLY, $1, $3 ); } |
30 | | LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE { $$ = $2; } | 33 | | expr LSL_ADD expr { $$ = addOperation( LSL_ADD, $1, $3 ); } |
31 | | LSL_INTEGER { $$ = addInteger($1); } | 34 | | LSL_INTEGER { $$ = addInteger($1); } |
32 | ; | 35 | ; |
33 | 36 | ||