aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_lemon_yaccer.y
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-02-03 21:08:47 +1000
committerDavid Walter Seikel2012-02-03 21:08:47 +1000
commit860a32f27a44542a4a97134cf57028276c33851c (patch)
tree544fcd6b16ae8cdc4e9d06819a75d9171bb89626 /LuaSL/src/LuaSL_lemon_yaccer.y
parentProperly implement Lua crements. (diff)
downloadSledjHamr-860a32f27a44542a4a97134cf57028276c33851c.zip
SledjHamr-860a32f27a44542a4a97134cf57028276c33851c.tar.gz
SledjHamr-860a32f27a44542a4a97134cf57028276c33851c.tar.bz2
SledjHamr-860a32f27a44542a4a97134cf57028276c33851c.tar.xz
Put assignments in their right place.
Diffstat (limited to '')
-rw-r--r--LuaSL/src/LuaSL_lemon_yaccer.y54
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
104exprList(A) ::= expr(D). { A = collectArguments(compiler, NULL, NULL, D); } 104exprList(A) ::= expr(D). { A = collectArguments(compiler, NULL, NULL, D); }
105exprList(A) ::= . { A = collectArguments(compiler, NULL, NULL, NULL); } 105exprList(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
112expr(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
115expr(A) ::= identifier(B) LSL_ASSIGNMENT_CONCATENATE(C) expr(D). { A = addOperation(compiler, B, C, D); }
116expr(A) ::= identifier(B) LSL_ASSIGNMENT_ADD(C) expr(D). { A = addOperation(compiler, B, C, D); }
117expr(A) ::= identifier(B) LSL_ASSIGNMENT_SUBTRACT(C) expr(D). { A = addOperation(compiler, B, C, D); }
118expr(A) ::= identifier(B) LSL_ASSIGNMENT_MULTIPLY(C) expr(D). { A = addOperation(compiler, B, C, D); }
119expr(A) ::= identifier(B) LSL_ASSIGNMENT_MODULO(C) expr(D). { A = addOperation(compiler, B, C, D); }
120expr(A) ::= identifier(B) LSL_ASSIGNMENT_DIVIDE(C) expr(D). { A = addOperation(compiler, B, C, D); }
121expr(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); ...
126statement(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); }
127statement(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.
108expr(A) ::= expr(B) LSL_BOOL_AND(C) expr(D). { A = addOperation(compiler, B, C, D); } 132expr(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; }
159expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, LSL_EXPRESSION, D); } 183expr(A) ::= LSL_PARENTHESIS_OPEN(B) expr(C) LSL_PARENTHESIS_CLOSE(D). { A = addParenthesis(B, C, LSL_EXPRESSION, D); }
160expr(A) ::= LSL_PARENTHESIS_OPEN(B) type(C) LSL_PARENTHESIS_CLOSE(D) expr(E). { A = addTypecast(B, C, D, E); } 184expr(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.
165expr(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
169expr(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.
173expr(A) ::= identifier(B) LSL_ASSIGNMENT_CONCATENATE(C) expr(D). { A = addOperation(compiler, B, C, D); }
174expr(A) ::= identifier(B) LSL_ASSIGNMENT_ADD(C) expr(D). { A = addOperation(compiler, B, C, D); }
175expr(A) ::= identifier(B) LSL_ASSIGNMENT_SUBTRACT(C) expr(D). { A = addOperation(compiler, B, C, D); }
176expr(A) ::= identifier(B) LSL_ASSIGNMENT_MULTIPLY(C) expr(D). { A = addOperation(compiler, B, C, D); }
177expr(A) ::= identifier(B) LSL_ASSIGNMENT_MODULO(C) expr(D). { A = addOperation(compiler, B, C, D); }
178expr(A) ::= identifier(B) LSL_ASSIGNMENT_DIVIDE(C) expr(D). { A = addOperation(compiler, B, C, D); }
179expr(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); ...
184statement(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); }
185statement(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.
188identifier(A) ::= identifier(I) LSL_DOT(D) LSL_IDENTIFIER(B). { A = checkVariable(compiler, I, D, B); } 187identifier(A) ::= identifier(I) LSL_DOT(D) LSL_IDENTIFIER(B). { A = checkVariable(compiler, I, D, B); }
189identifier(A) ::= LSL_IDENTIFIER(B). { A = checkVariable(compiler, B, NULL, NULL); } 188identifier(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,
194expr(A) ::= LSL_DECREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C, LSL_DECREMENT_PRE); } 193expr(A) ::= LSL_DECREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C, LSL_DECREMENT_PRE); }
195expr(A) ::= LSL_INCREMENT_PRE(C) identifier(B). { A = addCrement(compiler, B, C, LSL_INCREMENT_PRE); } 194expr(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.
199expr(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.