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.h136
1 files changed, 25 insertions, 111 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h
index a392474..1c6710d 100644
--- a/LuaSL/src/LuaSL_LSL_tree.h
+++ b/LuaSL/src/LuaSL_LSL_tree.h
@@ -9,6 +9,8 @@
9#include "LuaSL_yaccer.tab.h" 9#include "LuaSL_yaccer.tab.h"
10#endif 10#endif
11 11
12#include <stddef.h> // So we can have NULL defined.
13
12#define YYERRCODE 256 14#define YYERRCODE 256
13#define YYDEBUG 1 15#define YYDEBUG 1
14extern int yydebug; 16extern int yydebug;
@@ -18,12 +20,13 @@ extern int yydebug;
18 20
19typedef enum 21typedef enum
20{ 22{
21 LSL_LEFT2RIGHT = 0, 23 LSL_NONE = 0,
22 LSL_RIGHT2LEFT = 1, 24 LSL_LEFT2RIGHT = 1,
23 LSL_INNER2OUTER = 2, 25 LSL_RIGHT2LEFT = 2,
24 LSL_UNARY = 4, 26 LSL_INNER2OUTER = 4,
25 LSL_ASSIGNMENT = 8, 27 LSL_UNARY = 8,
26 LSL_CREATION = 16 28 LSL_ASSIGNMENT = 16,
29 LSL_CREATION = 32
27} LSL_Flags; 30} LSL_Flags;
28 31
29#ifdef LUASL_USE_ENUM 32#ifdef LUASL_USE_ENUM
@@ -80,68 +83,6 @@ typedef enum // In order of precedence, high to low.
80typedef int LSL_Operation; 83typedef int LSL_Operation;
81#endif 84#endif
82 85
83typedef struct
84{
85// LSL_Operation operation,
86 char *token;
87 LSL_Flags flags;
88} LSL_Operator;
89
90// QUIRK - Seems to be some disagreement about BOOL_AND/BOOL_OR precedence. Either they are equal, or OR is higher.
91// QUIRK - Conditionals are executed right to left. Or left to right, depending on who you ask. lol
92// QUIRK - No boolean short circuiting.
93
94#ifdef LSL_Tokens_define
95LSL_Operator LSL_Tokens[] =
96{
97 {",", LSL_LEFT2RIGHT},
98 {"++", LSL_RIGHT2LEFT | LSL_UNARY},
99 {"++", LSL_RIGHT2LEFT | LSL_UNARY},
100 {"--", LSL_RIGHT2LEFT | LSL_UNARY},
101 {"--", LSL_RIGHT2LEFT | LSL_UNARY},
102 {".", LSL_RIGHT2LEFT},
103 {"=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
104 {"/=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
105 {"%=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
106 {"*=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
107 {"-=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
108 {"+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
109 {"+=", LSL_RIGHT2LEFT | LSL_ASSIGNMENT},
110 {"(", LSL_INNER2OUTER},
111 {")", LSL_INNER2OUTER},
112 {"[", LSL_INNER2OUTER | LSL_CREATION},
113 {"]", LSL_INNER2OUTER | LSL_CREATION},
114 {"<", LSL_LEFT2RIGHT | LSL_CREATION},
115 {">", LSL_LEFT2RIGHT | LSL_CREATION},
116 {"()", LSL_RIGHT2LEFT | LSL_UNARY},
117 {"~", LSL_RIGHT2LEFT | LSL_UNARY},
118 {"!", LSL_RIGHT2LEFT | LSL_UNARY},
119 {"-", LSL_RIGHT2LEFT | LSL_UNARY},
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 {">", LSL_LEFT2RIGHT},
132 {"<=", LSL_LEFT2RIGHT},
133 {">=", LSL_LEFT2RIGHT},
134 {"==", LSL_LEFT2RIGHT},
135 {"!=", LSL_LEFT2RIGHT},
136 {"&", LSL_LEFT2RIGHT},
137 {"^", LSL_LEFT2RIGHT},
138 {"|", LSL_LEFT2RIGHT},
139 {"||", LSL_LEFT2RIGHT},
140 {"&&", LSL_LEFT2RIGHT}
141};
142#endif
143
144
145#ifdef LUASL_USE_ENUM 86#ifdef LUASL_USE_ENUM
146typedef enum 87typedef enum
147{ 88{
@@ -176,41 +117,6 @@ typedef enum
176} LSL_Type; 117} LSL_Type;
177#else 118#else
178typedef int LSL_Type; 119typedef int LSL_Type;
179#define LSL_EXPRESSION 1
180#endif
181
182#ifdef LSL_Keywords_define
183char *LSL_Keywords[] =
184{
185 "//", // Also "/*",
186 "",
187 "",
188 "",
189 "float",
190 "integer",
191 "string",
192 "key",
193 "vector",
194 "rotation",
195 "list",
196 "@",
197 "",
198 "do",
199 "for",
200 "if",
201 "else",
202 "else if",
203 "jump",
204 "state",
205 "while",
206 "return",
207 ";",
208 "{}",
209 "",
210 "",
211 "",
212 ""
213};
214#endif 120#endif
215 121
216typedef struct 122typedef struct
@@ -276,6 +182,20 @@ typedef union LSL_Leaf
276 LSL_Script *scriptValue; 182 LSL_Script *scriptValue;
277} LSL_Leaf; 183} LSL_Leaf;
278 184
185typedef void (*convertToken2Lua) (LSL_Leaf *content);
186typedef void (*outputToken) (LSL_Leaf *content);
187typedef LSL_Leaf *(*evaluateToken) (LSL_Leaf *content, LSL_Type oldType, LSL_Leaf *old);
188
189typedef struct
190{
191 LSL_Type type;
192 char *token;
193 LSL_Flags flags;
194 outputToken output;
195 convertToken2Lua convert;
196 evaluateToken evaluate;
197} LSL_Token;
198
279typedef struct 199typedef struct
280{ 200{
281 char *name; 201 char *name;
@@ -287,6 +207,7 @@ typedef struct LSL_Expression
287{ 207{
288 struct LSL_Expression *left; 208 struct LSL_Expression *left;
289 struct LSL_Expression *right; 209 struct LSL_Expression *right;
210 LSL_Token *token;
290 LSL_Type type; 211 LSL_Type type;
291 LSL_Leaf content; 212 LSL_Leaf content;
292} LSL_Expression; 213} LSL_Expression;
@@ -297,6 +218,7 @@ typedef struct LSL_AST
297 struct LSL_AST *right; 218 struct LSL_AST *right;
298 int line; 219 int line;
299 int character; 220 int character;
221 LSL_Token *token;
300 LSL_Type type; 222 LSL_Type type;
301 LSL_Leaf content; 223 LSL_Leaf content;
302} LSL_AST; 224} LSL_AST;
@@ -325,17 +247,9 @@ typedef struct
325#define YYLEX_PARAM ((LuaSL_yyparseParam*)data)->scanner 247#define YYLEX_PARAM ((LuaSL_yyparseParam*)data)->scanner
326 248
327 249
328void burnLSLExpression(LSL_Expression *exp);
329void burnAST(LSL_AST *ast);
330LSL_AST *addExpression(LSL_Expression *exp); 250LSL_AST *addExpression(LSL_Expression *exp);
331LSL_Expression *addInteger(int value); 251LSL_Expression *addInteger(int value);
332LSL_Expression *addOperation(LSL_Operation type, LSL_Expression *left, LSL_Expression *right); 252LSL_Expression *addOperation(LSL_Operation type, LSL_Expression *left, LSL_Expression *right);
333int evaluateExpression(LSL_Expression *exp, int old);
334int evaluateAST(LSL_AST *ast, int old);
335void outputExpression(LSL_Expression *exp);
336void outputAST(LSL_AST *ast);
337void convertAST2Lua(LSL_AST *ast);
338LSL_AST *newTree(const char *expr);
339 253
340int yyerror(const char *msg); 254int yyerror(const char *msg);
341int yyparse(void *param); 255int yyparse(void *param);