aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitignore1
-rwxr-xr-xLuaSL/build.sh5
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.c195
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h50
-rw-r--r--LuaSL/src/LuaSL_lexer.l23
-rw-r--r--LuaSL/src/LuaSL_yaccer.y22
6 files changed, 148 insertions, 148 deletions
diff --git a/.gitignore b/.gitignore
index b4f6b51..874fdf5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
1*.edj 1*.edj
2*.o 2*.o
3*.output
3LuaSL/LuaSL 4LuaSL/LuaSL
4LuaSL/LuaSL_parser 5LuaSL/LuaSL_parser
5LuaSL/src/*.tab.* 6LuaSL/src/*.tab.*
diff --git a/LuaSL/build.sh b/LuaSL/build.sh
index bf82075..9e5e2b7 100755
--- a/LuaSL/build.sh
+++ b/LuaSL/build.sh
@@ -51,7 +51,7 @@ names="LuaSL_main LuaSL_compile LuaSL_utilities"
51 51
52EDJE_FLAGS="-id images -fd fonts" 52EDJE_FLAGS="-id images -fd fonts"
53 53
54rm -f ../LuaSL ../LuaSL_parser *.o *.edj LuaSL_lexer.h LuaSL_lexer.c LuaSL_yaccer.h LuaSL_yaccer.tab.c 54rm -f ../LuaSL ../LuaSL_parser ../*.o *.output ../*.edj LuaSL_lexer.h LuaSL_lexer.c LuaSL_yaccer.h LuaSL_yaccer.tab.c
55command="edje_cc $EDJE_FLAGS LuaSL.edc ../LuaSL.edj" 55command="edje_cc $EDJE_FLAGS LuaSL.edc ../LuaSL.edj"
56echo $command 56echo $command
57$command 57$command
@@ -77,7 +77,8 @@ command="flex --outfile=LuaSL_lexer.c --header-file=LuaSL_lexer.h LuaSL_lexer.l"
77echo $command 77echo $command
78$command 78$command
79 79
80command="btyacc -d -b LuaSL_yaccer -S btyacc-c.ske LuaSL_yaccer.y" 80# Should add -t as well for debugging, but it causes errors.
81command="btyacc -d -v -b LuaSL_yaccer -S btyacc-c.ske LuaSL_yaccer.y"
81echo $command 82echo $command
82$command 83$command
83 84
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c
index 9137692..552de04 100644
--- a/LuaSL/src/LuaSL_LSL_tree.c
+++ b/LuaSL/src/LuaSL_LSL_tree.c
@@ -106,88 +106,88 @@ int evaluateExpression(LSL_Expression *exp, int old)
106{ 106{
107 switch(exp->type) 107 switch(exp->type)
108 { 108 {
109 case LSL_COMMENT : 109// case LSL_COMMENT :
110 case LSL_TYPE : 110// case LSL_TYPE :
111 case LSL_NAME : 111// case LSL_NAME :
112 case LSL_IDENTIFIER : 112// case LSL_IDENTIFIER :
113 break; 113// break;
114 case LSL_FLOAT : return (int) exp->value.floatValue; 114// case LSL_FLOAT : return (int) exp->value.floatValue;
115 case LSL_INTEGER : return exp->value.integerValue; 115 case LSL_INTEGER : return exp->value.integerValue;
116 case LSL_STRING : 116// case LSL_STRING :
117 case LSL_KEY : 117// case LSL_KEY :
118 case LSL_VECTOR : 118// case LSL_VECTOR :
119 case LSL_ROTATION : 119// case LSL_ROTATION :
120 case LSL_LIST : 120// case LSL_LIST :
121 case LSL_LABEL : 121// case LSL_LABEL :
122 break; 122// break;
123 case LSL_EXPRESSION : 123 case LSL_EXPRESSION :
124 { 124 {
125 switch (exp->expression) 125 switch (exp->expression)
126 { 126 {
127 case LSL_COMMA : 127// case LSL_COMMA :
128 case LSL_INCREMENT_PRE : 128// case LSL_INCREMENT_PRE :
129 case LSL_INCREMENT_POST : 129// case LSL_INCREMENT_POST :
130 case LSL_DECREMENT_PRE : 130// case LSL_DECREMENT_PRE :
131 case LSL_DECREMENT_POST : 131// case LSL_DECREMENT_POST :
132 case LSL_DOT : 132// case LSL_DOT :
133 case LSL_ASSIGNMENT_PLAIN : 133// case LSL_ASSIGNMENT_PLAIN :
134 case LSL_ASSIGNMENT_DIVIDE : 134// case LSL_ASSIGNMENT_DIVIDE :
135 case LSL_ASSIGNMENT_MODULO : 135// case LSL_ASSIGNMENT_MODULO :
136 case LSL_ASSIGNMENT_MULTIPLY : 136// case LSL_ASSIGNMENT_MULTIPLY :
137 case LSL_ASSIGNMENT_SUBTRACT : 137// case LSL_ASSIGNMENT_SUBTRACT :
138 case LSL_ASSIGNMENT_ADD : 138// case LSL_ASSIGNMENT_ADD :
139 case LSL_ASSIGNMENT_CONCATENATE : 139// case LSL_ASSIGNMENT_CONCATENATE :
140 case LSL_PARENTHESIS_OPEN : 140 case LSL_PARENTHESIS_OPEN :
141 case LSL_PARENTHESIS_CLOSE : 141 case LSL_PARENTHESIS_CLOSE :
142 case LSL_BRACKET_OPEN : 142// case LSL_BRACKET_OPEN :
143 case LSL_BRACKET_CLOSE : 143// case LSL_BRACKET_CLOSE :
144 case LSL_ANGLE_OPEN : 144// case LSL_ANGLE_OPEN :
145 case LSL_ANGLE_CLOSE : 145// case LSL_ANGLE_CLOSE :
146 case LSL_TYPECAST : 146// case LSL_TYPECAST :
147 case LSL_BIT_NOT : 147// case LSL_BIT_NOT :
148 case LSL_BOOL_NOT : 148// case LSL_BOOL_NOT :
149 case LSL_NEGATION : 149// case LSL_NEGATION :
150 break; 150 break;
151 case LSL_DIVIDE : return evaluateExpression(exp->left, old) / evaluateExpression(exp->right, old); 151// 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); 152// 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); 153 case LSL_MULTIPLY : return evaluateExpression(exp->left, old) * evaluateExpression(exp->right, old);
154 case LSL_DOT_PRODUCT : break; 154// case LSL_DOT_PRODUCT : break;
155 case LSL_CROSS_PRODUCT : break; 155// case LSL_CROSS_PRODUCT : break;
156 case LSL_SUBTRACT : return evaluateExpression(exp->left, old) - evaluateExpression(exp->right, old); 156// case LSL_SUBTRACT : return evaluateExpression(exp->left, old) - evaluateExpression(exp->right, old);
157 case LSL_ADD : return evaluateExpression(exp->left, old) + evaluateExpression(exp->right, old); 157 case LSL_ADD : return evaluateExpression(exp->left, old) + evaluateExpression(exp->right, old);
158 case LSL_CONCATENATE : break; 158// case LSL_CONCATENATE : break;
159 case LSL_LEFT_SHIFT : return evaluateExpression(exp->left, old) << evaluateExpression(exp->right, old); 159// case LSL_LEFT_SHIFT : return evaluateExpression(exp->left, old) << evaluateExpression(exp->right, old);
160 case LSL_RIGHT_SHIFT : return evaluateExpression(exp->left, old) >> evaluateExpression(exp->right, old); 160// case LSL_RIGHT_SHIFT : return evaluateExpression(exp->left, old) >> evaluateExpression(exp->right, old);
161 case LSL_LESS_THAN : return evaluateExpression(exp->left, old) < evaluateExpression(exp->right, old); 161// case LSL_LESS_THAN : return evaluateExpression(exp->left, old) < evaluateExpression(exp->right, old);
162 case LSL_GREATER_THAN : return evaluateExpression(exp->left, old) > evaluateExpression(exp->right, old); 162// case LSL_GREATER_THAN : return evaluateExpression(exp->left, old) > evaluateExpression(exp->right, old);
163 case LSL_LESS_EQUAL : return evaluateExpression(exp->left, old) <= evaluateExpression(exp->right, old); 163// case LSL_LESS_EQUAL : return evaluateExpression(exp->left, old) <= evaluateExpression(exp->right, old);
164 case LSL_GREATER_EQUAL : return evaluateExpression(exp->left, old) >= evaluateExpression(exp->right, old); 164// case LSL_GREATER_EQUAL : return evaluateExpression(exp->left, old) >= evaluateExpression(exp->right, old);
165 case LSL_EQUAL : return evaluateExpression(exp->left, old) == evaluateExpression(exp->right, old); 165// case LSL_EQUAL : return evaluateExpression(exp->left, old) == evaluateExpression(exp->right, old);
166 case LSL_NOT_EQUAL : return evaluateExpression(exp->left, old) != evaluateExpression(exp->right, old); 166// case LSL_NOT_EQUAL : return evaluateExpression(exp->left, old) != evaluateExpression(exp->right, old);
167 case LSL_BIT_AND : return evaluateExpression(exp->left, old) & evaluateExpression(exp->right, old); 167// case LSL_BIT_AND : return evaluateExpression(exp->left, old) & evaluateExpression(exp->right, old);
168 case LSL_BIT_XOR : return evaluateExpression(exp->left, old) ^ evaluateExpression(exp->right, old); 168// case LSL_BIT_XOR : return evaluateExpression(exp->left, old) ^ evaluateExpression(exp->right, old);
169 case LSL_BIT_OR : return evaluateExpression(exp->left, old) | evaluateExpression(exp->right, old); 169// case LSL_BIT_OR : return evaluateExpression(exp->left, old) | evaluateExpression(exp->right, old);
170 case LSL_BOOL_OR : return evaluateExpression(exp->left, old) || evaluateExpression(exp->right, old); 170// case LSL_BOOL_OR : return evaluateExpression(exp->left, old) || evaluateExpression(exp->right, old);
171 case LSL_BOOL_AND : return evaluateExpression(exp->left, old) && evaluateExpression(exp->right, old); 171// case LSL_BOOL_AND : return evaluateExpression(exp->left, old) && evaluateExpression(exp->right, old);
172 } 172 }
173 break; 173 break;
174 } 174 }
175 case LSL_DO : 175// case LSL_DO :
176 case LSL_FOR : 176// case LSL_FOR :
177 case LSL_IF : 177// case LSL_IF :
178 case LSL_ELSE : 178// case LSL_ELSE :
179 case LSL_ELSEIF : 179// case LSL_ELSEIF :
180 case LSL_JUMP : 180// case LSL_JUMP :
181 case LSL_STATE_CHANGE : 181// case LSL_STATE_CHANGE :
182 case LSL_WHILE : 182// case LSL_WHILE :
183 case LSL_RETURN : 183// case LSL_RETURN :
184 case LSL_STATEMENT : 184// case LSL_STATEMENT :
185 case LSL_BLOCK : 185// case LSL_BLOCK :
186 case LSL_PARAMETER : 186// case LSL_PARAMETER :
187 case LSL_FUNCTION : 187// case LSL_FUNCTION :
188 case LSL_STATE : 188// case LSL_STATE :
189 case LSL_SCRIPT : 189// case LSL_SCRIPT :
190 break; 190// break;
191 } 191 }
192 192
193 return old; 193 return old;
@@ -198,43 +198,45 @@ void outputExpression(LSL_Expression *exp)
198{ 198{
199 switch(exp->type) 199 switch(exp->type)
200 { 200 {
201 case LSL_COMMENT : return; 201// case LSL_COMMENT : return;
202 case LSL_TYPE : return; 202// case LSL_TYPE : return;
203 case LSL_NAME : return; 203// case LSL_NAME : return;
204 case LSL_IDENTIFIER : return; 204// case LSL_IDENTIFIER : return;
205 case LSL_FLOAT : printf("%f", exp->value.floatValue); break; 205// case LSL_FLOAT : printf("%f", exp->value.floatValue); break;
206 case LSL_INTEGER : printf("%d", exp->value.integerValue); break; 206 case LSL_INTEGER : printf("%d", exp->value.integerValue); break;
207 case LSL_STRING : return; 207// case LSL_STRING : return;
208 case LSL_KEY : return; 208// case LSL_KEY : return;
209 case LSL_VECTOR : return; 209// case LSL_VECTOR : return;
210 case LSL_ROTATION : return; 210// case LSL_ROTATION : return;
211 case LSL_LIST : return; 211// case LSL_LIST : return;
212 case LSL_LABEL : return; 212// case LSL_LABEL : return;
213 case LSL_EXPRESSION : 213 case LSL_EXPRESSION :
214 outputExpression(exp->left); 214 outputExpression(exp->left);
215 printf(" %s ", LSL_Tokens[exp->expression].token); 215// printf(" %s ", LSL_Tokens[exp->expression].token);
216printf(" # ");
216 outputExpression(exp->right); 217 outputExpression(exp->right);
217 break; 218 break;
218 case LSL_DO : return; 219// case LSL_DO : return;
219 case LSL_FOR : return; 220// case LSL_FOR : return;
220 case LSL_IF : return; 221// case LSL_IF : return;
221 case LSL_ELSE : return; 222// case LSL_ELSE : return;
222 case LSL_ELSEIF : return; 223// case LSL_ELSEIF : return;
223 case LSL_JUMP : return; 224// case LSL_JUMP : return;
224 case LSL_STATE_CHANGE : return; 225// case LSL_STATE_CHANGE : return;
225 case LSL_WHILE : return; 226// case LSL_WHILE : return;
226 case LSL_RETURN : return; 227// case LSL_RETURN : return;
227 case LSL_STATEMENT : return; 228// case LSL_STATEMENT : return;
228 case LSL_BLOCK : return; 229// case LSL_BLOCK : return;
229 case LSL_PARAMETER : return; 230// case LSL_PARAMETER : return;
230 case LSL_FUNCTION : return; 231// case LSL_FUNCTION : return;
231 case LSL_STATE : return; 232// case LSL_STATE : return;
232 case LSL_SCRIPT : return; 233// case LSL_SCRIPT : return;
233 } 234 }
234} 235}
235 236
236void convertExpression2Lua(LSL_Expression *exp) 237void convertExpression2Lua(LSL_Expression *exp)
237{ 238{
239/*
238 switch(exp->type) 240 switch(exp->type)
239 { 241 {
240 case LSL_COMMENT : return; 242 case LSL_COMMENT : return;
@@ -266,6 +268,7 @@ void convertExpression2Lua(LSL_Expression *exp)
266 case LSL_STATE : return; 268 case LSL_STATE : return;
267 case LSL_SCRIPT : return; 269 case LSL_SCRIPT : return;
268 } 270 }
271*/
269} 272}
270 273
271int yyerror(const char *msg) 274int yyerror(const char *msg)
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index a5d090e..7973509 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -8,6 +8,8 @@
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#include "LuaSL_yaccer.tab.h"
12
11// http://w-hat.com/stackdepth is a useful discussion about some aspects of the LL parser. 13// http://w-hat.com/stackdepth is a useful discussion about some aspects of the LL parser.
12 14
13typedef enum 15typedef enum
@@ -20,6 +22,7 @@ typedef enum
20 LSL_CREATION = 16 22 LSL_CREATION = 16
21} LSL_Flags; 23} LSL_Flags;
22 24
25/*
23typedef enum // In order of precedence, high to low. 26typedef enum // In order of precedence, high to low.
24 // Left to right, unless oterwise stated. 27 // Left to right, unless oterwise stated.
25 // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators 28 // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators
@@ -69,6 +72,9 @@ typedef enum // In order of precedence, high to low.
69 LSL_BOOL_OR, 72 LSL_BOOL_OR,
70 LSL_BOOL_AND 73 LSL_BOOL_AND
71} LSL_Operation; 74} LSL_Operation;
75*/
76
77typedef int LSL_Operation;
72 78
73typedef struct 79typedef struct
74{ 80{
@@ -131,6 +137,7 @@ LSL_Operator LSL_Tokens[] =
131}; 137};
132#endif 138#endif
133 139
140/*
134typedef enum 141typedef enum
135{ 142{
136 LSL_COMMENT, 143 LSL_COMMENT,
@@ -162,6 +169,11 @@ typedef enum
162 LSL_STATE, 169 LSL_STATE,
163 LSL_SCRIPT 170 LSL_SCRIPT
164} LSL_Type; 171} LSL_Type;
172*/
173
174typedef int LSL_Type;
175#define LSL_EXPRESSION 1
176
165 177
166#ifdef LSL_Keywords_define 178#ifdef LSL_Keywords_define
167char *LSL_Keywords[] = 179char *LSL_Keywords[] =
@@ -285,29 +297,6 @@ typedef union LSL_Leaf
285 LSL_Function *functionValue; 297 LSL_Function *functionValue;
286 LSL_State *stateValue; 298 LSL_State *stateValue;
287 LSL_Script *scriptValue; 299 LSL_Script *scriptValue;
288} LSL_Leaf;
289
290typedef struct LSL_AST
291{
292 struct LSL_AST *left;
293 struct LSL_AST *right;
294 int line;
295 int character;
296 LSL_Type type;
297 LSL_Leaf content;
298} LSL_AST;
299
300
301/**
302 * @brief The structure used by flex and bison
303 */
304//typedef union tagTypeParser
305//{
306// SExpression *expression;
307// int value;
308// int ival;
309// float fval;
310// char *sval;
311// class LLScriptType *type; 300// class LLScriptType *type;
312// class LLScriptConstant *constant; 301// class LLScriptConstant *constant;
313// class LLScriptIdentifier *identifier; 302// class LLScriptIdentifier *identifier;
@@ -322,7 +311,18 @@ typedef struct LSL_AST
322// class LLScriptState *state; 311// class LLScriptState *state;
323// class LLScritpGlobalStorage *global_store; 312// class LLScritpGlobalStorage *global_store;
324// class LLScriptScript *script; 313// class LLScriptScript *script;
325//}STypeParser; 314} LSL_Leaf;
315
316typedef struct LSL_AST
317{
318 struct LSL_AST *left;
319 struct LSL_AST *right;
320 int line;
321 int character;
322 LSL_Type type;
323 LSL_Leaf content;
324} LSL_AST;
325
326 326
327// define the type for flex and bison 327// define the type for flex and bison
328#define YYSTYPE LSL_Leaf 328#define YYSTYPE LSL_Leaf
@@ -359,8 +359,6 @@ void convertExpression2Lua(LSL_Expression *exp);
359int yyerror(const char *msg); 359int yyerror(const char *msg);
360int yyparse(void *param); 360int yyparse(void *param);
361 361
362#include "LuaSL_yaccer.tab.h"
363
364 362
365#endif // __EXPRESSION_H__ 363#endif // __EXPRESSION_H__
366 364
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l
index d204916..478e62c 100644
--- a/LuaSL/src/LuaSL_lexer.l
+++ b/LuaSL/src/LuaSL_lexer.l
@@ -8,24 +8,21 @@
8%option reentrant noyywrap never-interactive nounistd 8%option reentrant noyywrap never-interactive nounistd
9%option bison-bridge 9%option bison-bridge
10 10
11LPAREN "(" 11SPACE [ \r\n\t]*
12RPAREN ")"
13PLUS "+"
14MULTIPLY "*"
15
16NUMBER [0-9]+ 12NUMBER [0-9]+
17WS [ \r\n\t]* 13NAME [a-zA-Z][a-zA-Z0-9]*
18 14
19%% 15%%
20 16
21{WS} { /* Skip blanks. */ } 17{SPACE} { /* Skip blanks. */ }
22{NUMBER} { sscanf(yytext,"%d",&yylval->integerValue); return TOKEN_NUMBER; } 18{NUMBER} { yylval->integerValue = atoi(yytext); return LSL_INTEGER; }
19{NAME} { /* yylval->nameValue=strdup(yytext); return LSL_NAME; */ }
23 20
24{MULTIPLY} { return TOKEN_MULTIPLY; } 21"*" { return LSL_MULTIPLY; }
25{PLUS} { return TOKEN_PLUS; } 22"+" { return LSL_ADD; }
26{LPAREN} { return TOKEN_LPAREN; } 23"(" { return LSL_PARENTHESIS_OPEN; }
27{RPAREN} { return TOKEN_RPAREN; } 24")" { return LSL_PARENTHESIS_CLOSE; }
28. { } 25. { /* This should return an "unknown character" error */ }
29 26
30%% 27%%
31 28
diff --git a/LuaSL/src/LuaSL_yaccer.y b/LuaSL/src/LuaSL_yaccer.y
index 820f7da..897a83e 100644
--- a/LuaSL/src/LuaSL_yaccer.y
+++ b/LuaSL/src/LuaSL_yaccer.y
@@ -6,15 +6,15 @@
6 6
7%define api.pure 7%define api.pure
8 8
9%left '+' TOKEN_PLUS 9%left '+' LSL_ADD
10%left '*' TOKEN_MULTIPLY 10%left '*' LSL_MULTIPLY
11 11
12%token TOKEN_LPAREN 12%token LSL_PARENTHESIS_OPEN
13%token TOKEN_RPAREN 13%token LSL_PARENTHESIS_CLOSE
14%token TOKEN_PLUS 14%token LSL_ADD
15%token TOKEN_MULTIPLY 15%token LSL_MULTIPLY
16 16
17%token <integerValue> TOKEN_NUMBER 17%token <integerValue> LSL_INTEGER
18 18
19%type <expressionValue> expr 19%type <expressionValue> expr
20 20
@@ -25,10 +25,10 @@ input:
25 ; 25 ;
26 26
27expr: 27expr:
28 expr TOKEN_PLUS expr { $$ = addOperation( LSL_ADD, $1, $3 ); } 28 expr LSL_ADD expr { $$ = addOperation( LSL_ADD, $1, $3 ); }
29 | expr TOKEN_MULTIPLY expr { $$ = addOperation( LSL_MULTIPLY, $1, $3 ); } 29 | expr LSL_MULTIPLY expr { $$ = addOperation( LSL_MULTIPLY, $1, $3 ); }
30 | TOKEN_LPAREN expr TOKEN_RPAREN { $$ = $2; } 30 | LSL_PARENTHESIS_OPEN expr LSL_PARENTHESIS_CLOSE { $$ = $2; }
31 | TOKEN_NUMBER { $$ = addInteger($1); } 31 | LSL_INTEGER { $$ = addInteger($1); }
32; 32;
33 33
34%% 34%%