diff options
Diffstat (limited to 'LuaSL/src')
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.c | 31 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_lexer.l | 36 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_yaccer.y | 50 |
3 files changed, 84 insertions, 33 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c index a69b0d3..88768e0 100644 --- a/LuaSL/src/LuaSL_LSL_tree.c +++ b/LuaSL/src/LuaSL_LSL_tree.c | |||
@@ -139,6 +139,13 @@ int evaluateExpression(LSL_Expression *exp, int old) | |||
139 | #endif | 139 | #endif |
140 | case LSL_EXPRESSION : | 140 | case LSL_EXPRESSION : |
141 | { | 141 | { |
142 | #ifdef LUASL_DEBUG | ||
143 | #ifdef LUASL_USE_ENUM | ||
144 | printf(" %s ", LSL_Tokens[exp->expression - LSL_COMMA].token); | ||
145 | #else | ||
146 | printf(" # "); | ||
147 | #endif | ||
148 | #endif | ||
142 | switch (exp->expression) | 149 | switch (exp->expression) |
143 | { | 150 | { |
144 | #ifdef LUASL_USE_ENUM | 151 | #ifdef LUASL_USE_ENUM |
@@ -162,30 +169,25 @@ int evaluateExpression(LSL_Expression *exp, int old) | |||
162 | case LSL_ANGLE_OPEN : | 169 | case LSL_ANGLE_OPEN : |
163 | case LSL_ANGLE_CLOSE : | 170 | case LSL_ANGLE_CLOSE : |
164 | case LSL_TYPECAST : | 171 | case LSL_TYPECAST : |
165 | case LSL_BIT_NOT : | ||
166 | case LSL_BOOL_NOT : | ||
167 | case LSL_NEGATION : | ||
168 | break; | 172 | break; |
173 | #endif | ||
174 | case LSL_BIT_NOT : return ~ evaluateExpression(exp->right, old); | ||
175 | case LSL_BOOL_NOT : return ! evaluateExpression(exp->right, old); | ||
176 | case LSL_NEGATION : return 0 - evaluateExpression(exp->right, old); | ||
169 | case LSL_DIVIDE : return evaluateExpression(exp->left, old) / evaluateExpression(exp->right, old); | 177 | case LSL_DIVIDE : return evaluateExpression(exp->left, old) / evaluateExpression(exp->right, old); |
178 | #ifdef LUASL_USE_ENUM | ||
170 | case LSL_MODULO : return evaluateExpression(exp->left, old) % evaluateExpression(exp->right, old); | 179 | case LSL_MODULO : return evaluateExpression(exp->left, old) % evaluateExpression(exp->right, old); |
171 | #endif | 180 | #endif |
172 | case LSL_MULTIPLY : | 181 | case LSL_MULTIPLY : return evaluateExpression(exp->left, old) * evaluateExpression(exp->right, old); |
173 | #ifdef LUASL_DEBUG | ||
174 | printf(" * "); | ||
175 | #endif | ||
176 | return evaluateExpression(exp->left, old) * evaluateExpression(exp->right, old); | ||
177 | #ifdef LUASL_USE_ENUM | 182 | #ifdef LUASL_USE_ENUM |
178 | case LSL_DOT_PRODUCT : break; | 183 | case LSL_DOT_PRODUCT : break; |
179 | case LSL_CROSS_PRODUCT : break; | 184 | case LSL_CROSS_PRODUCT : break; |
180 | case LSL_SUBTRACT : return evaluateExpression(exp->left, old) - evaluateExpression(exp->right, old); | ||
181 | #endif | ||
182 | case LSL_ADD : | ||
183 | #ifdef LUASL_DEBUG | ||
184 | printf(" + "); | ||
185 | #endif | 185 | #endif |
186 | return evaluateExpression(exp->left, old) + evaluateExpression(exp->right, old); | 186 | case LSL_SUBTRACT : return evaluateExpression(exp->left, old) - evaluateExpression(exp->right, old); |
187 | case LSL_ADD : return evaluateExpression(exp->left, old) + evaluateExpression(exp->right, old); | ||
187 | #ifdef LUASL_USE_ENUM | 188 | #ifdef LUASL_USE_ENUM |
188 | case LSL_CONCATENATE : break; | 189 | case LSL_CONCATENATE : break; |
190 | #endif | ||
189 | case LSL_LEFT_SHIFT : return evaluateExpression(exp->left, old) << evaluateExpression(exp->right, old); | 191 | 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); | 192 | 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); | 193 | case LSL_LESS_THAN : return evaluateExpression(exp->left, old) < evaluateExpression(exp->right, old); |
@@ -199,7 +201,6 @@ int evaluateExpression(LSL_Expression *exp, int old) | |||
199 | case LSL_BIT_OR : return evaluateExpression(exp->left, old) | evaluateExpression(exp->right, old); | 201 | 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); | 202 | 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); | 203 | case LSL_BOOL_AND : return evaluateExpression(exp->left, old) && evaluateExpression(exp->right, old); |
202 | #endif | ||
203 | } | 204 | } |
204 | break; | 205 | break; |
205 | } | 206 | } |
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l index c496d1d..11c20a0 100644 --- a/LuaSL/src/LuaSL_lexer.l +++ b/LuaSL/src/LuaSL_lexer.l | |||
@@ -17,19 +17,45 @@ | |||
17 | %option bison-bridge | 17 | %option bison-bridge |
18 | 18 | ||
19 | SPACE [ \r\n\t]* | 19 | SPACE [ \r\n\t]* |
20 | NAME [a-zA-Z_][a-zA-Z0-9_]* | 20 | LETTER [A-Za-z] |
21 | NUMBER [0-9]+ | 21 | DECIMAL [0-9] |
22 | HEX [0-9A-Fa-f] | ||
23 | |||
24 | NAME {LETTER}(_|{LETTER}|{DECIMAL})* | ||
25 | INTEGER {DECIMAL}+ | ||
26 | EXPONANT [eE][+-]?{INTEGER} | ||
27 | FLOAT {INTEGER}("."{INTEGER})?{EXPONANT}? | ||
22 | 28 | ||
23 | %% | 29 | %% |
24 | 30 | ||
25 | {SPACE} { ECHO; /* Skip blanks. */ } | 31 | {SPACE} { ECHO; /* Skip blanks. */ } |
26 | {NAME} { ECHO; /* yylval->nameValue=strdup(yytext); return LSL_NAME; */ } | 32 | {NAME} { ECHO; /* yylval->nameValue=strdup(yytext); return LSL_NAME; */ } |
27 | {NUMBER} { ECHO; yylval->integerValue = atoi(yytext); return LSL_INTEGER; } | 33 | {INTEGER} { ECHO; yylval->integerValue = atoi(yytext); return LSL_INTEGER; } |
34 | {FLOAT} { ECHO; /* yylval->floatValue = atof(yytext); return LSL_FLOAT; */ } | ||
28 | 35 | ||
36 | "&&" { ECHO; return LSL_BOOL_AND; } | ||
37 | "||" { ECHO; return LSL_BOOL_OR; } | ||
38 | "|" { ECHO; return LSL_BIT_OR; } | ||
39 | "^" { ECHO; return LSL_BIT_XOR; } | ||
40 | "&" { ECHO; return LSL_BIT_AND; } | ||
41 | "!=" { ECHO; return LSL_NOT_EQUAL; } | ||
42 | "==" { ECHO; return LSL_EQUAL; } | ||
43 | ">=" { ECHO; return LSL_GREATER_EQUAL; } | ||
44 | "<=" { ECHO; return LSL_LESS_EQUAL; } | ||
45 | ">" { ECHO; return LSL_GREATER_THAN; } | ||
46 | "<" { ECHO; return LSL_LESS_THAN; } | ||
47 | ">>" { ECHO; return LSL_RIGHT_SHIFT; } | ||
48 | "<<" { ECHO; return LSL_LEFT_SHIFT; } | ||
49 | "+" { ECHO; return LSL_ADD; } | ||
50 | "-" { ECHO; return LSL_SUBTRACT; } | ||
51 | "*" { ECHO; return LSL_MULTIPLY; } | ||
52 | "%" { ECHO; return LSL_MODULO; } | ||
53 | "/" { ECHO; return LSL_DIVIDE; } | ||
54 | "!" { ECHO; return LSL_BOOL_NOT; } | ||
55 | "~" { ECHO; return LSL_BIT_NOT; } | ||
29 | "(" { ECHO; return LSL_PARENTHESIS_OPEN; } | 56 | "(" { ECHO; return LSL_PARENTHESIS_OPEN; } |
30 | ")" { ECHO; return LSL_PARENTHESIS_CLOSE; } | 57 | ")" { ECHO; return LSL_PARENTHESIS_CLOSE; } |
31 | "*" { ECHO; return LSL_MULTIPLY; } | 58 | |
32 | "+" { ECHO; return LSL_ADD; } | ||
33 | . { ECHO; printf(" unexpected character.\n"); } | 59 | . { ECHO; printf(" unexpected character.\n"); } |
34 | 60 | ||
35 | %% | 61 | %% |
diff --git a/LuaSL/src/LuaSL_yaccer.y b/LuaSL/src/LuaSL_yaccer.y index 5d01f46..fd5a461 100644 --- a/LuaSL/src/LuaSL_yaccer.y +++ b/LuaSL/src/LuaSL_yaccer.y | |||
@@ -9,28 +9,52 @@ | |||
9 | 9 | ||
10 | %define api.pure | 10 | %define api.pure |
11 | 11 | ||
12 | %left '+' LSL_ADD | 12 | %token <integerValue> LSL_INTEGER |
13 | %left '*' LSL_MULTIPLY | ||
14 | 13 | ||
15 | %token LSL_ADD | 14 | %left LSL_BOOL_AND |
16 | %token LSL_MULTIPLY | 15 | %left LSL_BOOL_OR |
17 | %token LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE | 16 | %left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR |
17 | %left LSL_EQUAL LSL_NOT_EQUAL | ||
18 | %left LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL | ||
19 | %left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT | ||
20 | %left LSL_SUBTRACT LSL_ADD | ||
21 | %left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY | ||
22 | %right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION | ||
18 | 23 | ||
19 | %token <integerValue> LSL_INTEGER | 24 | %token LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE |
20 | 25 | ||
21 | %type <expressionValue> expr | 26 | %type <expressionValue> expr |
22 | 27 | ||
23 | %% | 28 | %% |
24 | 29 | ||
25 | input: | 30 | input : |
26 | expr { ((LuaSL_yyparseParam*)data)->expression = $1; } | 31 | expr { ((LuaSL_yyparseParam*)data)->expression = $1; } |
27 | ; | 32 | ; |
28 | 33 | ||
29 | expr: | 34 | expr : |
30 | LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE { $$ = $2; } | 35 | LSL_INTEGER { $$ = addInteger($1); } |
31 | | expr LSL_MULTIPLY expr { $$ = addOperation( LSL_MULTIPLY, $1, $3 ); } | 36 | | expr LSL_BOOL_AND expr { $$ = addOperation( LSL_BOOL_AND, $1, $3 ); } |
37 | | expr LSL_BOOL_OR expr { $$ = addOperation( LSL_BOOL_OR, $1, $3 ); } | ||
38 | | expr LSL_BIT_OR expr { $$ = addOperation( LSL_BIT_OR, $1, $3 ); } | ||
39 | | expr LSL_BIT_XOR expr { $$ = addOperation( LSL_BIT_XOR, $1, $3 ); } | ||
40 | | expr LSL_BIT_AND expr { $$ = addOperation( LSL_BIT_AND, $1, $3 ); } | ||
41 | | expr LSL_NOT_EQUAL expr { $$ = addOperation( LSL_NOT_EQUAL, $1, $3 ); } | ||
42 | | expr LSL_EQUAL expr { $$ = addOperation( LSL_EQUAL, $1, $3 ); } | ||
43 | | expr LSL_GREATER_EQUAL expr { $$ = addOperation( LSL_GREATER_EQUAL, $1, $3 ); } | ||
44 | | expr LSL_LESS_EQUAL expr { $$ = addOperation( LSL_LESS_EQUAL, $1, $3 ); } | ||
45 | | expr LSL_GREATER_THAN expr { $$ = addOperation( LSL_GREATER_THAN, $1, $3 ); } | ||
46 | | expr LSL_LESS_THAN expr { $$ = addOperation( LSL_LESS_THAN, $1, $3 ); } | ||
47 | | expr LSL_RIGHT_SHIFT expr { $$ = addOperation( LSL_RIGHT_SHIFT, $1, $3 ); } | ||
48 | | expr LSL_LEFT_SHIFT expr { $$ = addOperation( LSL_LEFT_SHIFT, $1, $3 ); } | ||
32 | | expr LSL_ADD expr { $$ = addOperation( LSL_ADD, $1, $3 ); } | 49 | | expr LSL_ADD expr { $$ = addOperation( LSL_ADD, $1, $3 ); } |
33 | | LSL_INTEGER { $$ = addInteger($1); } | 50 | | expr LSL_SUBTRACT expr { $$ = addOperation( LSL_SUBTRACT, $1, $3 ); } |
51 | | expr LSL_MULTIPLY expr { $$ = addOperation( LSL_MULTIPLY, $1, $3 ); } | ||
52 | | expr LSL_MODULO expr { $$ = addOperation( LSL_MODULO, $1, $3 ); } | ||
53 | | expr LSL_DIVIDE expr { $$ = addOperation( LSL_DIVIDE, $1, $3 ); } | ||
54 | | LSL_BIT_NOT expr { $$ = addOperation( LSL_BIT_NOT, NULL, $2 ); } | ||
55 | | LSL_BOOL_NOT expr { $$ = addOperation( LSL_BOOL_NOT, NULL, $2 ); } | ||
56 | | LSL_SUBTRACT expr { $$ = addOperation( LSL_NEGATION, NULL, $2 ); } %prec LSL_NEGATION | ||
57 | | LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE { $$ = $2; } | ||
34 | ; | 58 | ; |
35 | 59 | ||
36 | %% | 60 | %% |