diff options
author | David Walter Seikel | 2012-01-12 04:54:17 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-12 04:54:17 +1000 |
commit | b5ba6b85252e5052c64174d6f3abad5a4a5a2a34 (patch) | |
tree | e12191109e9036257a39beea82fec7f167c18123 /LuaSL/src | |
parent | Update .gitignore for lemon. (diff) | |
download | SledjHamr-b5ba6b85252e5052c64174d6f3abad5a4a5a2a34.zip SledjHamr-b5ba6b85252e5052c64174d6f3abad5a4a5a2a34.tar.gz SledjHamr-b5ba6b85252e5052c64174d6f3abad5a4a5a2a34.tar.bz2 SledjHamr-b5ba6b85252e5052c64174d6f3abad5a4a5a2a34.tar.xz |
Some general cleanup.
Diffstat (limited to 'LuaSL/src')
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.c | 32 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_LSL_tree.h | 13 | ||||
-rw-r--r-- | LuaSL/src/LuaSL_lemon_yaccer.y | 51 |
3 files changed, 41 insertions, 55 deletions
diff --git a/LuaSL/src/LuaSL_LSL_tree.c b/LuaSL/src/LuaSL_LSL_tree.c index a0c07f0..beae756 100644 --- a/LuaSL/src/LuaSL_LSL_tree.c +++ b/LuaSL/src/LuaSL_LSL_tree.c | |||
@@ -11,13 +11,12 @@ static void evaluateStatementToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf * | |||
11 | static void outputIntegerToken(LSL_Leaf *content); | 11 | static void outputIntegerToken(LSL_Leaf *content); |
12 | static void outputParenthesisToken(LSL_Leaf *content); | 12 | static void outputParenthesisToken(LSL_Leaf *content); |
13 | static void outputStatementToken(LSL_Leaf *content); | 13 | static void outputStatementToken(LSL_Leaf *content); |
14 | static void outputSpaceToken(LSL_Leaf *content); | ||
15 | 14 | ||
16 | LSL_Token LSL_Tokens[] = | 15 | LSL_Token LSL_Tokens[] = |
17 | { | 16 | { |
18 | {LSL_COMMENT, "/*", LSL_NONE, NULL, NULL, NULL}, | 17 | {LSL_COMMENT, "/*", LSL_NONE, NULL, NULL, NULL}, |
19 | {LSL_COMMENT_LINE, "//", LSL_NONE, NULL, NULL, NULL}, | 18 | {LSL_COMMENT_LINE, "//", LSL_NONE, NULL, NULL, NULL}, |
20 | {LSL_SPACE, " ", LSL_NONE, outputSpaceToken, NULL, NULL}, | 19 | {LSL_SPACE, " ", LSL_NONE, NULL, NULL, NULL}, |
21 | 20 | ||
22 | // Operators, in order of precedence, low to high | 21 | // Operators, in order of precedence, low to high |
23 | // Left to right, unless oterwise stated. | 22 | // Left to right, unless oterwise stated. |
@@ -96,7 +95,7 @@ LSL_Token LSL_Tokens[] = | |||
96 | 95 | ||
97 | // Then the rest of the syntax tokens. | 96 | // Then the rest of the syntax tokens. |
98 | 97 | ||
99 | {LSL_IDENTIFIER, "identifier", LSL_NONE, NULL, NULL, NULL}, | 98 | {LSL_IDENTIFIER, "identifier", LSL_NONE, NULL, NULL, NULL}, |
100 | 99 | ||
101 | {LSL_LABEL, "@", LSL_NONE, NULL, NULL, NULL}, | 100 | {LSL_LABEL, "@", LSL_NONE, NULL, NULL, NULL}, |
102 | 101 | ||
@@ -118,7 +117,7 @@ LSL_Token LSL_Tokens[] = | |||
118 | // {LSL_STATE, "state", LSL_NONE, NULL, NULL, NULL}, | 117 | // {LSL_STATE, "state", LSL_NONE, NULL, NULL, NULL}, |
119 | {LSL_SCRIPT, "", LSL_NONE, NULL, NULL, NULL}, | 118 | {LSL_SCRIPT, "", LSL_NONE, NULL, NULL, NULL}, |
120 | 119 | ||
121 | {LSL_UNKNOWN, "unknown", LSL_NONE, NULL, NULL, NULL}, | 120 | {LSL_UNKNOWN, "unknown", LSL_NONE, NULL, NULL, NULL}, |
122 | 121 | ||
123 | // A sentinal. | 122 | // A sentinal. |
124 | 123 | ||
@@ -129,6 +128,7 @@ LSL_Token **tokens = NULL; | |||
129 | int lowestToken = 999999; | 128 | int lowestToken = 999999; |
130 | 129 | ||
131 | 130 | ||
131 | /* Not actually used, but it might be some day. | ||
132 | static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right) | 132 | static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right) |
133 | { | 133 | { |
134 | LSL_Leaf *leaf = calloc(1, sizeof(LSL_Leaf)); | 134 | LSL_Leaf *leaf = calloc(1, sizeof(LSL_Leaf)); |
@@ -142,6 +142,7 @@ static LSL_Leaf *newLeaf(LSL_Type type, LSL_Leaf *left, LSL_Leaf *right) | |||
142 | 142 | ||
143 | return leaf; | 143 | return leaf; |
144 | } | 144 | } |
145 | */ | ||
145 | 146 | ||
146 | void burnLeaf(LSL_Leaf *leaf) | 147 | void burnLeaf(LSL_Leaf *leaf) |
147 | { | 148 | { |
@@ -155,22 +156,12 @@ void burnLeaf(LSL_Leaf *leaf) | |||
155 | } | 156 | } |
156 | } | 157 | } |
157 | 158 | ||
158 | LSL_Leaf *addOperation(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *left, LSL_Leaf *right) | 159 | LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right) |
159 | { | 160 | { |
160 | printf("******************************addOperation(%s, %d, , )\n", lval->token->token, type); | ||
161 | if (lval) | 161 | if (lval) |
162 | { | 162 | { |
163 | lval->left = left; | 163 | lval->left = left; |
164 | lval->right = right; | 164 | lval->right = right; |
165 | if (LSL_EXPRESSION == type) | ||
166 | { | ||
167 | lval->value.expressionValue = right; | ||
168 | lval->left = NULL; | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | lval->value.operationValue = type; | ||
173 | } | ||
174 | } | 165 | } |
175 | 166 | ||
176 | return lval; | 167 | return lval; |
@@ -194,7 +185,6 @@ LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Leaf *rval) | |||
194 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr) | 185 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr) |
195 | { | 186 | { |
196 | LSL_Statement *stat = malloc(sizeof(LSL_Statement)); | 187 | LSL_Statement *stat = malloc(sizeof(LSL_Statement)); |
197 | printf("******************************addStatement(%s, %d, , )\n", lval->token->token, type); | ||
198 | 188 | ||
199 | if (stat) | 189 | if (stat) |
200 | { | 190 | { |
@@ -270,13 +260,13 @@ static void evaluateNoToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) | |||
270 | 260 | ||
271 | static void evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) | 261 | static void evaluateOperationToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right) |
272 | { | 262 | { |
273 | if ((content) && (content->value.operationValue)) | 263 | if (content) |
274 | { | 264 | { |
275 | #ifdef LUASL_DEBUG | 265 | #ifdef LUASL_DEBUG |
276 | printf(" [%s] ", content->token->token); | 266 | printf(" [%s] ", content->token->token); |
277 | #endif | 267 | #endif |
278 | 268 | ||
279 | switch (content->value.operationValue) | 269 | switch (content->token->type) |
280 | { | 270 | { |
281 | case LSL_COMMA : | 271 | case LSL_COMMA : |
282 | case LSL_INCREMENT_PRE : | 272 | case LSL_INCREMENT_PRE : |
@@ -391,12 +381,6 @@ static void outputStatementToken(LSL_Leaf *content) | |||
391 | } | 381 | } |
392 | } | 382 | } |
393 | 383 | ||
394 | static void outputSpaceToken(LSL_Leaf *content) | ||
395 | { | ||
396 | if (content) | ||
397 | printf("%s", content->value.spaceValue); | ||
398 | } | ||
399 | |||
400 | static void convertLeaf2Lua(LSL_Leaf *leaf) | 384 | static void convertLeaf2Lua(LSL_Leaf *leaf) |
401 | { | 385 | { |
402 | if (leaf) | 386 | if (leaf) |
diff --git a/LuaSL/src/LuaSL_LSL_tree.h b/LuaSL/src/LuaSL_LSL_tree.h index 9db83d0..9493552 100644 --- a/LuaSL/src/LuaSL_LSL_tree.h +++ b/LuaSL/src/LuaSL_LSL_tree.h | |||
@@ -86,13 +86,11 @@ struct _LSL_Leaf | |||
86 | { | 86 | { |
87 | LSL_Leaf *left; | 87 | LSL_Leaf *left; |
88 | LSL_Leaf *right; | 88 | LSL_Leaf *right; |
89 | LSL_Token *token; | ||
90 | char *ignorableText; | ||
91 | int line, column; | ||
89 | union | 92 | union |
90 | { | 93 | { |
91 | char *commentValue; | ||
92 | char *spaceValue; | ||
93 | |||
94 | LSL_Type operationValue; | ||
95 | LSL_Leaf *expressionValue; | ||
96 | LSL_Parenthesis *parenthesis; | 94 | LSL_Parenthesis *parenthesis; |
97 | 95 | ||
98 | float floatValue; | 96 | float floatValue; |
@@ -126,9 +124,6 @@ struct _LSL_Leaf | |||
126 | 124 | ||
127 | char *unknownValue; | 125 | char *unknownValue; |
128 | } value; | 126 | } value; |
129 | char *ignorableText; | ||
130 | LSL_Token *token; | ||
131 | int line, column; | ||
132 | }; | 127 | }; |
133 | 128 | ||
134 | struct _LSL_Parenthesis | 129 | struct _LSL_Parenthesis |
@@ -205,7 +200,7 @@ typedef struct | |||
205 | 200 | ||
206 | void burnLeaf(LSL_Leaf *leaf); | 201 | void burnLeaf(LSL_Leaf *leaf); |
207 | LSL_Leaf *addExpression(LSL_Leaf *exp); | 202 | LSL_Leaf *addExpression(LSL_Leaf *exp); |
208 | LSL_Leaf *addOperation(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *left, LSL_Leaf *right); | 203 | LSL_Leaf *addOperation(LSL_Leaf *left, LSL_Leaf *lval, LSL_Leaf *right); |
209 | LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Leaf *rval); | 204 | LSL_Leaf *addParenthesis(LSL_Leaf *lval, LSL_Leaf *expr, LSL_Leaf *rval); |
210 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr); | 205 | LSL_Leaf *addStatement(LSL_Leaf *lval, LSL_Type type, LSL_Leaf *expr); |
211 | 206 | ||
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 14942b7..2427456 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y | |||
@@ -15,39 +15,46 @@ program ::= script LSL_SCRIPT(A). { A->left = param->ast; param->ast = A; } | |||
15 | 15 | ||
16 | 16 | ||
17 | %left LSL_BOOL_AND. | 17 | %left LSL_BOOL_AND. |
18 | expr(A) ::= expr(B) LSL_BOOL_AND(D) expr(C). { A = addOperation(D, D->token->type, B, C); } | 18 | expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(B, C, D); } |
19 | %left LSL_BOOL_OR. | 19 | %left LSL_BOOL_OR. |
20 | expr(A) ::= expr(B) LSL_BOOL_OR(D) expr(C). { A = addOperation(D, LSL_BOOL_OR, B, C); } | 20 | expr(A) ::= expr(B) LSL_BOOL_OR(C) expr(D). { A = addOperation(B, C, D); } |
21 | |||
21 | %left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR. | 22 | %left LSL_BIT_AND LSL_BIT_XOR LSL_BIT_OR. |
22 | expr(A) ::= expr(B) LSL_BIT_OR(D) expr(C). { A = addOperation(D, LSL_BIT_OR, B, C); } | 23 | expr(A) ::= expr(B) LSL_BIT_OR(C) expr(D). { A = addOperation(B, C, D); } |
23 | expr(A) ::= expr(B) LSL_BIT_XOR(D) expr(C). { A = addOperation(D, LSL_BIT_XOR, B, C); } | 24 | expr(A) ::= expr(B) LSL_BIT_XOR(C) expr(D). { A = addOperation(B, C, D); } |
24 | expr(A) ::= expr(B) LSL_BIT_AND(D) expr(C). { A = addOperation(D, LSL_BIT_AND, B, C); } | 25 | expr(A) ::= expr(B) LSL_BIT_AND(C) expr(D). { A = addOperation(B, C, D); } |
26 | |||
25 | %left LSL_EQUAL LSL_NOT_EQUAL. | 27 | %left LSL_EQUAL LSL_NOT_EQUAL. |
26 | expr(A) ::= expr(B) LSL_NOT_EQUAL(D) expr(C). { A = addOperation(D, LSL_NOT_EQUAL, B, C); } | 28 | expr(A) ::= expr(B) LSL_NOT_EQUAL(C) expr(D). { A = addOperation(B, C, D); } |
27 | expr(A) ::= expr(B) LSL_EQUAL(D) expr(C). { A = addOperation(D, LSL_EQUAL, B, C); } | 29 | expr(A) ::= expr(B) LSL_EQUAL(C) expr(D). { A = addOperation(B, C, D); } |
28 | %left LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL. | 30 | %left LSL_LESS_THAN LSL_GREATER_THAN LSL_LESS_EQUAL LSL_GREATER_EQUAL. |
29 | expr(A) ::= expr(B) LSL_GREATER_EQUAL(D) expr(C). { A = addOperation(D, LSL_GREATER_EQUAL, B, C); } | 31 | expr(A) ::= expr(B) LSL_GREATER_EQUAL(C) expr(D). { A = addOperation(B, C, D); } |
30 | expr(A) ::= expr(B) LSL_LESS_EQUAL(D) expr(C). { A = addOperation(D, LSL_LESS_EQUAL, B, C); } | 32 | expr(A) ::= expr(B) LSL_LESS_EQUAL(C) expr(D). { A = addOperation(B, C, D); } |
31 | expr(A) ::= expr(B) LSL_GREATER_THAN(D) expr(C). { A = addOperation(D, LSL_GREATER_THAN, B, C); } | 33 | expr(A) ::= expr(B) LSL_GREATER_THAN(C) expr(D). { A = addOperation(B, C, D); } |
32 | expr(A) ::= expr(B) LSL_LESS_THAN(D) expr(C). { A = addOperation(D, LSL_LESS_THAN, B, C); } | 34 | expr(A) ::= expr(B) LSL_LESS_THAN(C) expr(D). { A = addOperation(B, C, D); } |
35 | |||
33 | %left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT. | 36 | %left LSL_LEFT_SHIFT LSL_RIGHT_SHIFT. |
34 | expr(A) ::= expr(B) LSL_RIGHT_SHIFT(D) expr(C). { A = addOperation(D, LSL_RIGHT_SHIFT, B, C); } | 37 | expr(A) ::= expr(B) LSL_RIGHT_SHIFT(C) expr(D). { A = addOperation(B, C, D); } |
35 | expr(A) ::= expr(B) LSL_LEFT_SHIFT(D) expr(C). { A = addOperation(D, LSL_LEFT_SHIFT, B, C); } | 38 | expr(A) ::= expr(B) LSL_LEFT_SHIFT(C) expr(D). { A = addOperation(B, C, D); } |
39 | |||
36 | %left LSL_SUBTRACT LSL_ADD. | 40 | %left LSL_SUBTRACT LSL_ADD. |
37 | expr(A) ::= expr(B) LSL_ADD(D) expr(C). { A = addOperation(D, LSL_ADD, B, C); } | 41 | expr(A) ::= expr(B) LSL_ADD(C) expr(D). { A = addOperation(B, C, D); } |
38 | expr(A) ::= expr(B) LSL_SUBTRACT(D) expr(C). { A = addOperation(D, LSL_SUBTRACT, B, C); } | 42 | expr(A) ::= expr(B) LSL_SUBTRACT(C) expr(D). { A = addOperation(B, C, D); } |
39 | %left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY. | 43 | %left LSL_DIVIDE LSL_MODULO LSL_MULTIPLY. |
40 | expr(A) ::= expr(B) LSL_MULTIPLY(D) expr(C). { A = addOperation(D, LSL_MULTIPLY, B, C); } | 44 | expr(A) ::= expr(B) LSL_MULTIPLY(C) expr(D). { A = addOperation(B, C, D); } |
41 | expr(A) ::= expr(B) LSL_MODULO(D) expr(C). { A = addOperation(D, LSL_MODULO, B, C); } | 45 | expr(A) ::= expr(B) LSL_MODULO(C) expr(D). { A = addOperation(B, C, D); } |
42 | expr(A) ::= expr(B) LSL_DIVIDE(D) expr(C). { A = addOperation(D, LSL_DIVIDE, B, C); } | 46 | expr(A) ::= expr(B) LSL_DIVIDE(C) expr(D). { A = addOperation(B, C, D); } |
47 | |||
43 | %right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION. | 48 | %right LSL_BIT_NOT LSL_BOOL_NOT LSL_NEGATION. |
44 | expr(A) ::= LSL_BIT_NOT(D) expr(B). { A = addOperation(D, LSL_BIT_NOT, NULL, B); } | 49 | expr(A) ::= LSL_BIT_NOT(B) expr(C). { A = addOperation(NULL, B, C); } |
45 | expr(A) ::= LSL_BOOL_NOT(D) expr(B). { A = addOperation(D, LSL_BOOL_NOT, NULL, B); } | 50 | expr(A) ::= LSL_BOOL_NOT(B) expr(C). { A = addOperation(NULL, B, C); } |
46 | expr(A) ::= LSL_SUBTRACT(D) expr(B). [LSL_NEGATION] { A = addOperation(D, LSL_NEGATION, NULL, B); } | 51 | expr(A) ::= LSL_SUBTRACT(B) expr(C). [LSL_NEGATION] { A = addOperation(NULL, B, C); } |
52 | |||
47 | %left LSL_ANGLE_OPEN LSL_ANGLE_CLOSE. | 53 | %left LSL_ANGLE_OPEN LSL_ANGLE_CLOSE. |
48 | %nonassoc LSL_BRACKET_OPEN LSL_BRACKET_CLOSE. | 54 | %nonassoc LSL_BRACKET_OPEN LSL_BRACKET_CLOSE. |
49 | %nonassoc LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION. | 55 | %nonassoc LSL_PARENTHESIS_OPEN LSL_PARENTHESIS_CLOSE LSL_EXPRESSION. |
50 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); } | 56 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, D); } |
57 | |||
51 | %right LSL_ASSIGNMENT_ADD LSL_ASSIGNMENT_SUBTRACT LSL_ASSIGNMENT_MULTIPLY LSL_ASSIGNMENT_MODULO LSL_ASSIGNMENT_DIVIDE LSL_ASSIGNMENT_PLAIN. | 58 | %right LSL_ASSIGNMENT_ADD LSL_ASSIGNMENT_SUBTRACT LSL_ASSIGNMENT_MULTIPLY LSL_ASSIGNMENT_MODULO LSL_ASSIGNMENT_DIVIDE LSL_ASSIGNMENT_PLAIN. |
52 | %right LSL_DOT. | 59 | %right LSL_DOT. |
53 | %right LSL_DECREMENT_PRE LSL_INCREMENT_PRE. | 60 | %right LSL_DECREMENT_PRE LSL_INCREMENT_PRE. |