diff options
Diffstat (limited to 'LuaSL/src/LuaSL_lemon_yaccer.y')
-rw-r--r-- | LuaSL/src/LuaSL_lemon_yaccer.y | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/LuaSL/src/LuaSL_lemon_yaccer.y b/LuaSL/src/LuaSL_lemon_yaccer.y index 716c65a..1290832 100644 --- a/LuaSL/src/LuaSL_lemon_yaccer.y +++ b/LuaSL/src/LuaSL_lemon_yaccer.y | |||
@@ -104,6 +104,30 @@ exprList(A) ::= exprList(B) LSL_COMMA(C) expr(D). { A = collectArguments(com | |||
104 | exprList(A) ::= expr(D). { A = collectArguments(compiler, NULL, NULL, D); } | 104 | exprList(A) ::= expr(D). { A = collectArguments(compiler, NULL, NULL, D); } |
105 | exprList(A) ::= . { A = collectArguments(compiler, NULL, NULL, NULL); } | 105 | exprList(A) ::= . { A = collectArguments(compiler, NULL, NULL, NULL); } |
106 | 106 | ||
107 | // Assignments and variable declarations. | ||
108 | |||
109 | %right LSL_ASSIGNMENT_CONCATENATE LSL_ASSIGNMENT_ADD LSL_ASSIGNMENT_SUBTRACT LSL_ASSIGNMENT_MULTIPLY LSL_ASSIGNMENT_MODULO LSL_ASSIGNMENT_DIVIDE LSL_ASSIGNMENT_PLAIN. | ||
110 | // Variables and dealing with them. | ||
111 | |||
112 | expr(A) ::= identifier(B). { A = B; } | ||
113 | |||
114 | // Yes, these can be expressions, and can happen in if statements and such. In Lua they are NOT expressions. sigh | ||
115 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_CONCATENATE(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
116 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_ADD(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
117 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_SUBTRACT(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
118 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_MULTIPLY(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
119 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_MODULO(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
120 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_DIVIDE(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
121 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_PLAIN(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
122 | |||
123 | // Hmm think this can have commas seperating the assignment parts, or is that only in C?. If so, best to separate them when converting to Lua, as it uses that syntax for something else. | ||
124 | // Well, not in OpenSim at least, nor in SL. So we are safe. B-) | ||
125 | // On the other hand, it might be legal to have comma separated bits in a for loop - for ((i = 1), (j=1); ... | ||
126 | statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_ASSIGNMENT_PLAIN(D) expr(E) LSL_STATEMENT(S). { A = addStatement(compiler, S, I, NULL, addVariable(compiler, T, I, D, E, S), NULL, NULL, I); } | ||
127 | statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, I, NULL, addVariable(compiler, T, I, NULL, NULL, S), NULL, NULL, I); } | ||
128 | |||
129 | // Basic operators. | ||
130 | |||
107 | %right LSL_BOOL_AND. | 131 | %right LSL_BOOL_AND. |
108 | expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(compiler, B, C, D); } | 132 | expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(compiler, B, C, D); } |
109 | %right LSL_BOOL_OR. | 133 | %right LSL_BOOL_OR. |
@@ -159,31 +183,6 @@ type(A) ::= LSL_TYPE_VECTOR(B). { B->basicType = OT_vector; A = B; } | |||
159 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, LSL_EXPRESSION, D); } | 183 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, LSL_EXPRESSION, D); } |
160 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } | 184 | expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } |
161 | 185 | ||
162 | // Function call. | ||
163 | |||
164 | // Causes a conflict when exprList is empty with a function definition with no type and no parameters. | ||
165 | expr(A) ::= LSL_IDENTIFIER(B) LSL_PARENTHESIS_OPEN(C) exprList(D) LSL_PARENTHESIS_CLOSE(E). { A = addFunctionCall(compiler, B, C, D, E); } | ||
166 | |||
167 | // Variables and dealing with them. | ||
168 | |||
169 | expr(A) ::= identifier(B). { A = B; } | ||
170 | |||
171 | %right LSL_ASSIGNMENT_CONCATENATE LSL_ASSIGNMENT_ADD LSL_ASSIGNMENT_SUBTRACT LSL_ASSIGNMENT_MULTIPLY LSL_ASSIGNMENT_MODULO LSL_ASSIGNMENT_DIVIDE LSL_ASSIGNMENT_PLAIN. | ||
172 | // Yes, these can be expressions, and can happen in if statements and such. | ||
173 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_CONCATENATE(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
174 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_ADD(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
175 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_SUBTRACT(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
176 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_MULTIPLY(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
177 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_MODULO(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
178 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_DIVIDE(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
179 | expr(A) ::= identifier(B) LSL_ASSIGNMENT_PLAIN(C) expr(D). { A = addOperation(compiler, B, C, D); } | ||
180 | |||
181 | // Hmm think this can have commas seperating the assignment parts, or is that only in C?. If so, best to separate them when converting to Lua, as it uses that syntax for something else. | ||
182 | // Well, not in OpenSim at least, nor in SL. So we are safe. B-) | ||
183 | // On the other hand, it might be legal to have comma separated bits in a for loop - for ((i = 1), (j=1); ... | ||
184 | statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_ASSIGNMENT_PLAIN(D) expr(E) LSL_STATEMENT(S). { A = addStatement(compiler, S, I, NULL, addVariable(compiler, T, I, D, E), NULL, NULL, I); } | ||
185 | statement(A) ::= type(T) LSL_IDENTIFIER(I) LSL_STATEMENT(S). { A = addStatement(compiler, S, I, NULL, addVariable(compiler, T, I, NULL, NULL), NULL, NULL, I); } | ||
186 | |||
187 | %right LSL_DOT LSL_IDENTIFIER LSL_FUNCTION_CALL LSL_VARIABLE. | 186 | %right LSL_DOT LSL_IDENTIFIER LSL_FUNCTION_CALL LSL_VARIABLE. |
188 | identifier(A) ::= identifier(I) LSL_DOT(D) LSL_IDENTIFIER(B). { A = checkVariable(compiler, I, D, B); } | 187 | identifier(A) ::= identifier(I) LSL_DOT(D) LSL_IDENTIFIER(B). { A = checkVariable(compiler, I, D, B); } |
189 | identifier(A) ::= LSL_IDENTIFIER(B). { A = checkVariable(compiler, B, NULL, NULL); } | 188 | identifier(A) ::= LSL_IDENTIFIER(B). { A = checkVariable(compiler, B, NULL, NULL); } |
@@ -194,6 +193,11 @@ expr(A) ::= identifier(B) LSL_INCREMENT_PRE(C). { A = addCrement(compiler, | |||
194 | expr(A) ::= LSL_DECREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C, LSL_DECREMENT_PRE); } | 193 | expr(A) ::= LSL_DECREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C, LSL_DECREMENT_PRE); } |
195 | expr(A) ::= LSL_INCREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C, LSL_INCREMENT_PRE); } | 194 | expr(A) ::= LSL_INCREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C, LSL_INCREMENT_PRE); } |
196 | 195 | ||
196 | // Function call. | ||
197 | |||
198 | // Causes a conflict when exprList is empty with a function definition with no type and no parameters. | ||
199 | expr(A) ::= LSL_IDENTIFIER(B) LSL_PARENTHESIS_OPEN(C) exprList(D) LSL_PARENTHESIS_CLOSE(E). { A = addFunctionCall(compiler, B, C, D, E); } | ||
200 | |||
197 | %nonassoc LSL_COMMA. | 201 | %nonassoc LSL_COMMA. |
198 | 202 | ||
199 | // Values. | 203 | // Values. |