aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_LSL_tree.h
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/src/LuaSL_LSL_tree.h')
-rw-r--r--LuaSL/src/LuaSL_LSL_tree.h368
1 files changed, 308 insertions, 60 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index 9c27a8f..a5d090e 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -8,39 +8,306 @@
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// http://w-hat.com/stackdepth is a useful discussion about some aspects of the LL parser.
11 12
12/** 13typedef enum
13 * @brief The operation type
14 */
15typedef enum tagEOperationType
16{ 14{
17 eVALUE, 15 LSL_LEFT2RIGHT = 0,
18 eMULTIPLY, 16 LSL_RIGHT2LEFT = 1,
19 ePLUS 17 LSL_INNER2OUTER = 2,
20} EOperationType; 18 LSL_UNARY = 4,
19 LSL_ASSIGNMENT = 8,
20 LSL_CREATION = 16
21} LSL_Flags;
21 22
22/** 23typedef enum // In order of precedence, high to low.
23 * @brief The expression structure 24 // Left to right, unless oterwise stated.
24 */ 25 // According to http://wiki.secondlife.com/wiki/Category:LSL_Operators
25typedef struct tagSExpression 26{
27 LSL_COMMA,
28 LSL_INCREMENT_PRE, // Right to left.
29 LSL_INCREMENT_POST, // Right to left.
30 LSL_DECREMENT_PRE, // Right to left.
31 LSL_DECREMENT_POST, // Right to left.
32 LSL_DOT, // Right to left.
33 LSL_ASSIGNMENT_PLAIN, // Right to left.
34 LSL_ASSIGNMENT_DIVIDE, // Right to left.
35 LSL_ASSIGNMENT_MODULO, // Right to left.
36 LSL_ASSIGNMENT_MULTIPLY, // Right to left.
37 LSL_ASSIGNMENT_SUBTRACT, // Right to left.
38 LSL_ASSIGNMENT_ADD, // Right to left.
39 LSL_ASSIGNMENT_CONCATENATE, // Right to left.
40 LSL_PARENTHESIS_OPEN, // Inner to outer.
41 LSL_PARENTHESIS_CLOSE, // Inner to outer.
42 LSL_BRACKET_OPEN, // Inner to outer.
43 LSL_BRACKET_CLOSE, // Inner to outer.
44 LSL_ANGLE_OPEN,
45 LSL_ANGLE_CLOSE,
46 LSL_TYPECAST, // Right to left.
47 LSL_BIT_NOT, // Right to left.
48 LSL_BOOL_NOT, // Right to left.
49 LSL_NEGATION, // Right to left.
50 LSL_DIVIDE,
51 LSL_MODULO,
52 LSL_MULTIPLY,
53 LSL_DOT_PRODUCT,
54 LSL_CROSS_PRODUCT,
55 LSL_SUBTRACT,
56 LSL_ADD,
57 LSL_CONCATENATE,
58 LSL_LEFT_SHIFT,
59 LSL_RIGHT_SHIFT,
60 LSL_LESS_THAN,
61 LSL_GREATER_THAN,
62 LSL_LESS_EQUAL,
63 LSL_GREATER_EQUAL,
64 LSL_EQUAL,
65 LSL_NOT_EQUAL,
66 LSL_BIT_AND,
67 LSL_BIT_XOR,
68 LSL_BIT_OR,
69 LSL_BOOL_OR,
70 LSL_BOOL_AND
71} LSL_Operation;
72
73typedef struct
74{
75// LSL_Operation operation,
76 char *token;
77 LSL_Flags flags;
78} LSL_Operator;
79
80// QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher.
81// QUIRK - Conditionals are executed right to left. Or left to right, depending on who you ask. lol
82// QUIRK - No boolean short circuiting.
83
84#ifdef LSL_Tokens_define
85LSL_Operator LSL_Tokens[] =
26{ 86{
27 EOperationType type;///< type of operation 87 {",", LSL_LEFT2RIGHT},
88 {"++", LSL_RIGHT2LEFT | LSL_UNARY},
89 {"++", LSL_RIGHT2LEFT | LSL_UNARY},
90 {"--", LSL_RIGHT2LEFT | LSL_UNARY},
91 {"--", LSL_RIGHT2LEFT | LSL_UNARY},
92 {".", LSL_RIGHT2LEFT},
93 {"=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
94 {"/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
95 {"%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
96 {"*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
97 {"-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
98 {"+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
99 {"+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
100 {"(", LSL_INNER2OUTER},
101 {")", LSL_INNER2OUTER},
102 {"[", LSL_INNER2OUTER | LSL_CREATION},
103 {"]", LSL_INNER2OUTER | LSL_CREATION},
104 {"<", LSL_LEFT2RIGHT | LSL_CREATION},
105 {">", LSL_LEFT2RIGHT | LSL_CREATION},
106 {"()", LSL_RIGHT2LEFT | LSL_UNARY},
107 {"~", LSL_RIGHT2LEFT | LSL_UNARY},
108 {"!", LSL_RIGHT2LEFT | LSL_UNARY},
109 {"-", LSL_RIGHT2LEFT | LSL_UNARY},
110 {"/", LSL_LEFT2RIGHT},
111 {"%", LSL_LEFT2RIGHT},
112 {"*", LSL_LEFT2RIGHT},
113 {"*", LSL_LEFT2RIGHT},
114 {"%", LSL_LEFT2RIGHT},
115 {"-", LSL_LEFT2RIGHT},
116 {"+", LSL_LEFT2RIGHT},
117 {"+", LSL_LEFT2RIGHT},
118 {"<<", LSL_LEFT2RIGHT},
119 {">>", LSL_LEFT2RIGHT},
120 {"<", LSL_LEFT2RIGHT},
121 {">", LSL_LEFT2RIGHT},
122 {"<=", LSL_LEFT2RIGHT},
123 {">=", LSL_LEFT2RIGHT},
124 {"==", LSL_LEFT2RIGHT},
125 {"!=", LSL_LEFT2RIGHT},
126 {"&", LSL_LEFT2RIGHT},
127 {"^", LSL_LEFT2RIGHT},
128 {"|", LSL_LEFT2RIGHT},
129 {"||", LSL_LEFT2RIGHT},
130 {"&&", LSL_LEFT2RIGHT}
131};
132#endif
133
134typedef enum
135{
136 LSL_COMMENT,
137 LSL_TYPE,
138 LSL_NAME,
139 LSL_IDENTIFIER,
140 LSL_FLOAT,
141 LSL_INTEGER,
142 LSL_STRING,
143 LSL_KEY,
144 LSL_VECTOR,
145 LSL_ROTATION,
146 LSL_LIST,
147 LSL_LABEL,
148 LSL_EXPRESSION,
149 LSL_DO,
150 LSL_FOR,
151 LSL_IF,
152 LSL_ELSE,
153 LSL_ELSEIF,
154 LSL_JUMP,
155 LSL_STATE_CHANGE,
156 LSL_WHILE,
157 LSL_RETURN,
158 LSL_STATEMENT,
159 LSL_BLOCK,
160 LSL_PARAMETER,
161 LSL_FUNCTION,
162 LSL_STATE,
163 LSL_SCRIPT
164} LSL_Type;
165
166#ifdef LSL_Keywords_define
167char *LSL_Keywords[] =
168{
169 "//", // Also "/*",
170 "",
171 "",
172 "",
173 "float",
174 "integer",
175 "string",
176 "key",
177 "vector",
178 "rotation",
179 "list",
180 "@",
181 "",
182 "do",
183 "for",
184 "if",
185 "else",
186 "else if",
187 "jump",
188 "state",
189 "while",
190 "return",
191 ";",
192 "{}",
193 "",
194 "",
195 "",
196 ""
197};
198#endif
199
200typedef union
201{
202 float floatValue;
203 int integerValue;
204 char *stringValue;
205 char *keyValue;
206 float vectorValue[3];
207 float rotationValue[4];
208 union LSL_Leaf *listValue;
209} LSL_Value;
210
211typedef struct
212{
213 char *name;
214 LSL_Type type;
215 LSL_Value value;
216} LSL_Identifier;
217
218typedef struct LSL_Expression
219{
220 struct LSL_Expression *left;
221 struct LSL_Expression *right;
222 LSL_Value value;
223 LSL_Operation expression;
224 LSL_Type type;
225} LSL_Expression;
226
227typedef struct
228{
229 LSL_Type type;
230 LSL_Expression *expressions;
231} LSL_Statement;
232
233typedef struct
234{
235 LSL_Statement *statements;
236} LSL_Block;
237
238typedef struct
239{
240 char *name;
241 LSL_Identifier *parameters;
242 LSL_Block block;
243 LSL_Type type;
244} LSL_Function;
245
246typedef struct
247{
248 char *name;
249 LSL_Function *handlers;
250} LSL_State;
251
252typedef struct
253{
254 char *name;
255 LSL_Identifier *variables;
256 LSL_Function *functions;
257 LSL_State *states;
258} LSL_Script;
259
260typedef union LSL_Leaf
261{
262 char *commentValue;
263 LSL_Type typeValue;
264 char *nameValue;
265 LSL_Identifier *identifierValue;
266 float floatValue;
267 int integerValue;
268 char *stringValue;
269 char *keyValue;
270 float vectorValue[3];
271 float rotationValue[4];
272 union LSL_Leaf *listValue;
273 char *labelValue;
274// LSL_Operation expressionValue;
275 LSL_Expression *expressionValue;
276 LSL_Statement *doValue;
277 LSL_Statement *forValue;
278 LSL_Statement *ifValue;
279 LSL_Statement *elseValue;
280 LSL_Statement *elseIfValue;
281 char *jumpValue;
282 char *stateChangeValue;
283 LSL_Statement *statementValue;
284 LSL_Identifier *parameterValue;
285 LSL_Function *functionValue;
286 LSL_State *stateValue;
287 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;
28 299
29 int value;///< valid only when type is eVALUE
30 struct tagSExpression* left; ///< left side of the tree
31 struct tagSExpression* right;///< right side of the tree
32} SExpression;
33 300
34/** 301/**
35 * @brief The structure used by flex and bison 302 * @brief The structure used by flex and bison
36 */ 303 */
37typedef union tagTypeParser 304//typedef union tagTypeParser
38{ 305//{
39 SExpression *expression; 306// SExpression *expression;
40 int value; 307// int value;
41 int ival; 308// int ival;
42 float fval; 309// float fval;
43 char *sval; 310// char *sval;
44// class LLScriptType *type; 311// class LLScriptType *type;
45// class LLScriptConstant *constant; 312// class LLScriptConstant *constant;
46// class LLScriptIdentifier *identifier; 313// class LLScriptIdentifier *identifier;
@@ -55,10 +322,10 @@ typedef union tagTypeParser
55// class LLScriptState *state; 322// class LLScriptState *state;
56// class LLScritpGlobalStorage *global_store; 323// class LLScritpGlobalStorage *global_store;
57// class LLScriptScript *script; 324// class LLScriptScript *script;
58}STypeParser; 325//}STypeParser;
59 326
60// define the type for flex and bison 327// define the type for flex and bison
61#define YYSTYPE STypeParser 328#define YYSTYPE LSL_Leaf
62 329
63 330
64#ifndef excludeLexer 331#ifndef excludeLexer
@@ -66,47 +333,28 @@ typedef union tagTypeParser
66#endif 333#endif
67 334
68 335
69/** 336typedef struct
70 * @brief structure given as argument to the reentrant 'yyparse' function.
71 */
72typedef struct tagSParserParam
73{ 337{
74 yyscan_t scanner; 338 yyscan_t scanner;
75 SExpression *expression; 339 LSL_Expression *expression;
76}SParserParam; 340} LuaSL_yyparseParam;
77 341
342
343void burnLeaf(LSL_AST *leaf);
344void burnLSLExpression(LSL_Expression *exp);
345LSL_Expression *addInteger(int value);
346LSL_Expression *addOperation(LSL_Operation type, LSL_Expression *left, LSL_Expression *right);
347LSL_Expression *newTree(const char *expr);
348int evaluateExpression(LSL_Expression *exp, int old);
349void outputExpression(LSL_Expression *exp);
350void convertExpression2Lua(LSL_Expression *exp);
351
78// the parameter name (of the reentrant 'yyparse' function) 352// the parameter name (of the reentrant 'yyparse' function)
79// data is a pointer to a 'SParserParam' structure 353// data is a pointer to a 'SParserParam' structure
80#define YYPARSE_PARAM data 354#define YYPARSE_PARAM data
81 355
82// the argument for the 'yylex' function 356// the argument for the 'yylex' function
83#define YYLEX_PARAM ((SParserParam*)data)->scanner 357#define YYLEX_PARAM ((LuaSL_yyparseParam*)data)->scanner
84
85/**
86 * @brief It creates an identifier
87 * @param value The number value
88 * @return The expression or NULL in case of no memory
89 */
90SExpression* createNumber(int value);
91
92/**
93 * @brief It creates an operation
94 * @param type The operation type
95 * @param left The left operand
96 * @param right The right operand
97 * @return The expression or NULL in case of no memory
98 */
99SExpression* createOperation(EOperationType type, SExpression *left, SExpression *right);
100
101/**
102 * @brief Deletes a expression
103 * @param b The expression
104 */
105void deleteExpression(SExpression *b);
106
107SExpression *getAST(const char *expr);
108
109int evaluate(SExpression *e);
110 358
111int yyerror(const char *msg); 359int yyerror(const char *msg);
112int yyparse(void *param); 360int yyparse(void *param);