1 |
/* |
/* |
2 |
* Copyright (c) 2014 Christian Schoenebeck and Andreas Persson |
* Copyright (c) 2014-2016 Christian Schoenebeck and Andreas Persson |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
6 |
* This file is part of LinuxSampler and released under the same terms. |
* This file is part of LinuxSampler and released under the same terms. |
7 |
* See README file for details. |
* See README file for details. |
8 |
*/ |
*/ |
9 |
|
|
10 |
|
/* Parser for NKSP real-time instrument script language. */ |
11 |
|
|
12 |
%{ |
%{ |
13 |
#define YYERROR_VERBOSE 1 |
#define YYERROR_VERBOSE 1 |
20 |
void InstrScript_warning(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* txt); |
void InstrScript_warning(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* txt); |
21 |
int InstrScript_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner); |
int InstrScript_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner); |
22 |
#define scanner context->scanner |
#define scanner context->scanner |
23 |
#define PARSE_ERR(txt) yyerror(&yylloc, context, txt) |
#define PARSE_ERR(loc,txt) yyerror(&loc, context, txt) |
24 |
#define PARSE_WRN(txt) InstrScript_warning(&yylloc, context, txt) |
#define PARSE_WRN(loc,txt) InstrScript_warning(&loc, context, txt) |
25 |
%} |
%} |
26 |
|
|
27 |
// generate reentrant safe parser |
// generate reentrant safe parser |
74 |
eventhandler: |
eventhandler: |
75 |
ON NOTE statements END ON { |
ON NOTE statements END ON { |
76 |
if (context->onNote) |
if (context->onNote) |
77 |
PARSE_ERR("Redeclaration of 'note' event handler."); |
PARSE_ERR(@2, "Redeclaration of 'note' event handler."); |
78 |
context->onNote = new OnNote($3); |
context->onNote = new OnNote($3); |
79 |
$$ = context->onNote; |
$$ = context->onNote; |
80 |
} |
} |
81 |
| ON INIT statements END ON { |
| ON INIT statements END ON { |
82 |
if (context->onInit) |
if (context->onInit) |
83 |
PARSE_ERR("Redeclaration of 'init' event handler."); |
PARSE_ERR(@2, "Redeclaration of 'init' event handler."); |
84 |
context->onInit = new OnInit($3); |
context->onInit = new OnInit($3); |
85 |
$$ = context->onInit; |
$$ = context->onInit; |
86 |
} |
} |
87 |
| ON RELEASE statements END ON { |
| ON RELEASE statements END ON { |
88 |
if (context->onRelease) |
if (context->onRelease) |
89 |
PARSE_ERR("Redeclaration of 'release' event handler."); |
PARSE_ERR(@2, "Redeclaration of 'release' event handler."); |
90 |
context->onRelease = new OnRelease($3); |
context->onRelease = new OnRelease($3); |
91 |
$$ = context->onRelease; |
$$ = context->onRelease; |
92 |
} |
} |
93 |
| ON CONTROLLER statements END ON { |
| ON CONTROLLER statements END ON { |
94 |
if (context->onController) |
if (context->onController) |
95 |
PARSE_ERR("Redeclaration of 'controller' event handler."); |
PARSE_ERR(@2, "Redeclaration of 'controller' event handler."); |
96 |
context->onController = new OnController($3); |
context->onController = new OnController($3); |
97 |
$$ = context->onController; |
$$ = context->onController; |
98 |
} |
} |
103 |
if ($1) { |
if ($1) { |
104 |
if (!isNoOperation($1)) $$->add($1); // filter out NoOperation statements |
if (!isNoOperation($1)) $$->add($1); // filter out NoOperation statements |
105 |
} else |
} else |
106 |
PARSE_WRN("Not a statement."); |
PARSE_WRN(@1, "Not a statement."); |
107 |
} |
} |
108 |
| statements statement { |
| statements statement { |
109 |
$$ = $1; |
$$ = $1; |
110 |
if ($2) { |
if ($2) { |
111 |
if (!isNoOperation($2)) $$->add($2); // filter out NoOperation statements |
if (!isNoOperation($2)) $$->add($2); // filter out NoOperation statements |
112 |
} else |
} else |
113 |
PARSE_WRN("Not a statement."); |
PARSE_WRN(@2, "Not a statement."); |
114 |
} |
} |
115 |
|
|
116 |
statement: |
statement: |
121 |
const char* name = $2; |
const char* name = $2; |
122 |
//printf("declared var '%s'\n", name); |
//printf("declared var '%s'\n", name); |
123 |
if (context->variableByName(name)) |
if (context->variableByName(name)) |
124 |
PARSE_ERR((String("Redeclaration of variable '") + name + "'.").c_str()); |
PARSE_ERR(@2, (String("Redeclaration of variable '") + name + "'.").c_str()); |
125 |
if (name[0] == '@') { |
if (name[0] == '@') { |
126 |
context->vartable[name] = new StringVariable(context); |
context->vartable[name] = new StringVariable(context); |
127 |
$$ = new NoOperation; |
$$ = new NoOperation; |
134 |
const char* name = $3; |
const char* name = $3; |
135 |
//printf("declared polyphonic var '%s'\n", name); |
//printf("declared polyphonic var '%s'\n", name); |
136 |
if (context->variableByName(name)) |
if (context->variableByName(name)) |
137 |
PARSE_ERR((String("Redeclaration of variable '") + name + "'.").c_str()); |
PARSE_ERR(@3, (String("Redeclaration of variable '") + name + "'.").c_str()); |
138 |
if (name[0] != '$') { |
if (name[0] != '$') { |
139 |
PARSE_ERR("Polyphonic variables may only be declared as integers."); |
PARSE_ERR(@3, "Polyphonic variables may only be declared as integers."); |
140 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
141 |
} else { |
} else { |
142 |
context->vartable[name] = new PolyphonicIntVariable(context); |
context->vartable[name] = new PolyphonicIntVariable(context); |
147 |
const char* name = $2; |
const char* name = $2; |
148 |
//printf("declared assign var '%s'\n", name); |
//printf("declared assign var '%s'\n", name); |
149 |
if (context->variableByName(name)) |
if (context->variableByName(name)) |
150 |
PARSE_ERR((String("Redeclaration of variable '") + name + "'.").c_str()); |
PARSE_ERR(@2, (String("Redeclaration of variable '") + name + "'.").c_str()); |
151 |
if ($4->exprType() == STRING_EXPR) { |
if ($4->exprType() == STRING_EXPR) { |
152 |
if (name[0] == '$') |
if (name[0] == '$') |
153 |
PARSE_WRN((String("Variable '") + name + "' declared as integer, string expression assigned though.").c_str()); |
PARSE_WRN(@2, (String("Variable '") + name + "' declared as integer, string expression assigned though.").c_str()); |
154 |
StringExprRef expr = $4; |
StringExprRef expr = $4; |
155 |
if (expr->isConstExpr()) { |
if (expr->isConstExpr()) { |
156 |
const String s = expr->evalStr(); |
const String s = expr->evalStr(); |
164 |
} |
} |
165 |
} else { |
} else { |
166 |
if (name[0] == '@') |
if (name[0] == '@') |
167 |
PARSE_WRN((String("Variable '") + name + "' declared as string, integer expression assigned though.").c_str()); |
PARSE_WRN(@2, (String("Variable '") + name + "' declared as string, integer expression assigned though.").c_str()); |
168 |
IntExprRef expr = $4; |
IntExprRef expr = $4; |
169 |
if (expr->isConstExpr()) { |
if (expr->isConstExpr()) { |
170 |
const int i = expr->evalInt(); |
const int i = expr->evalInt(); |
182 |
//printf("declare array without args\n"); |
//printf("declare array without args\n"); |
183 |
const char* name = $2; |
const char* name = $2; |
184 |
if (!$4->isConstExpr()) { |
if (!$4->isConstExpr()) { |
185 |
PARSE_ERR((String("Array variable '") + name + "' must be declared with constant array size.").c_str()); |
PARSE_ERR(@4, (String("Array variable '") + name + "' must be declared with constant array size.").c_str()); |
186 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
187 |
} else if ($4->exprType() != INT_EXPR) { |
} else if ($4->exprType() != INT_EXPR) { |
188 |
PARSE_ERR((String("Size of array variable '") + name + "' declared with non integer expression.").c_str()); |
PARSE_ERR(@4, (String("Size of array variable '") + name + "' declared with non integer expression.").c_str()); |
189 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
190 |
} else if (context->variableByName(name)) { |
} else if (context->variableByName(name)) { |
191 |
PARSE_ERR((String("Redeclaration of variable '") + name + "'.").c_str()); |
PARSE_ERR(@2, (String("Redeclaration of variable '") + name + "'.").c_str()); |
192 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
193 |
} else { |
} else { |
194 |
IntExprRef expr = $4; |
IntExprRef expr = $4; |
195 |
int size = expr->evalInt(); |
int size = expr->evalInt(); |
196 |
if (size <= 0) { |
if (size <= 0) { |
197 |
PARSE_ERR((String("Array variable '") + name + "' declared with array size " + ToString(size) + ".").c_str()); |
PARSE_ERR(@4, (String("Array variable '") + name + "' declared with array size " + ToString(size) + ".").c_str()); |
198 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
199 |
} else { |
} else { |
200 |
context->vartable[name] = new IntArrayVariable(context, size); |
context->vartable[name] = new IntArrayVariable(context, size); |
205 |
| DECLARE VARIABLE '[' expr ']' ASSIGNMENT '(' args ')' { |
| DECLARE VARIABLE '[' expr ']' ASSIGNMENT '(' args ')' { |
206 |
const char* name = $2; |
const char* name = $2; |
207 |
if (!$4->isConstExpr()) { |
if (!$4->isConstExpr()) { |
208 |
PARSE_ERR((String("Array variable '") + name + "' must be declared with constant array size.").c_str()); |
PARSE_ERR(@4, (String("Array variable '") + name + "' must be declared with constant array size.").c_str()); |
209 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
210 |
} else if ($4->exprType() != INT_EXPR) { |
} else if ($4->exprType() != INT_EXPR) { |
211 |
PARSE_ERR((String("Size of array variable '") + name + "' declared with non integer expression.").c_str()); |
PARSE_ERR(@4, (String("Size of array variable '") + name + "' declared with non integer expression.").c_str()); |
212 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
213 |
} else if (context->variableByName(name)) { |
} else if (context->variableByName(name)) { |
214 |
PARSE_ERR((String("Redeclaration of variable '") + name + "'.").c_str()); |
PARSE_ERR(@2, (String("Redeclaration of variable '") + name + "'.").c_str()); |
215 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
216 |
} else { |
} else { |
217 |
IntExprRef sizeExpr = $4; |
IntExprRef sizeExpr = $4; |
218 |
ArgsRef args = $8; |
ArgsRef args = $8; |
219 |
int size = sizeExpr->evalInt(); |
int size = sizeExpr->evalInt(); |
220 |
if (size <= 0) { |
if (size <= 0) { |
221 |
PARSE_ERR((String("Array variable '") + name + "' must be declared with positive array size.").c_str()); |
PARSE_ERR(@4, (String("Array variable '") + name + "' must be declared with positive array size.").c_str()); |
222 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
223 |
} else if (args->argsCount() > size) { |
} else if (args->argsCount() > size) { |
224 |
PARSE_ERR((String("Variable '") + name + |
PARSE_ERR(@8, (String("Variable '") + name + |
225 |
"' was declared with size " + ToString(size) + |
"' was declared with size " + ToString(size) + |
226 |
" but " + ToString(args->argsCount()) + |
" but " + ToString(args->argsCount()) + |
227 |
" values were assigned." ).c_str()); |
" values were assigned." ).c_str()); |
231 |
for (int i = 0; i < args->argsCount(); ++i) { |
for (int i = 0; i < args->argsCount(); ++i) { |
232 |
if (args->arg(i)->exprType() != INT_EXPR) { |
if (args->arg(i)->exprType() != INT_EXPR) { |
233 |
PARSE_ERR( |
PARSE_ERR( |
234 |
|
@8, |
235 |
(String("Array variable '") + name + |
(String("Array variable '") + name + |
236 |
"' declared with invalid assignment values. Assigned element " + |
"' declared with invalid assignment values. Assigned element " + |
237 |
ToString(i+1) + " is not an integer expression.").c_str() |
ToString(i+1) + " is not an integer expression.").c_str() |
251 |
const char* name = $3; |
const char* name = $3; |
252 |
if ($5->exprType() == STRING_EXPR) { |
if ($5->exprType() == STRING_EXPR) { |
253 |
if (name[0] == '$') |
if (name[0] == '$') |
254 |
PARSE_WRN("Variable declared as integer, string expression assigned though."); |
PARSE_WRN(@5, "Variable declared as integer, string expression assigned though."); |
255 |
String s; |
String s; |
256 |
StringExprRef expr = $5; |
StringExprRef expr = $5; |
257 |
if (expr->isConstExpr()) |
if (expr->isConstExpr()) |
258 |
s = expr->evalStr(); |
s = expr->evalStr(); |
259 |
else |
else |
260 |
PARSE_ERR((String("Assignment to const string variable '") + name + "' requires const expression.").c_str()); |
PARSE_ERR(@5, (String("Assignment to const string variable '") + name + "' requires const expression.").c_str()); |
261 |
ConstStringVariableRef var = new ConstStringVariable(context, s); |
ConstStringVariableRef var = new ConstStringVariable(context, s); |
262 |
context->vartable[name] = var; |
context->vartable[name] = var; |
263 |
//$$ = new Assignment(var, new StringLiteral(s)); |
//$$ = new Assignment(var, new StringLiteral(s)); |
264 |
$$ = new NoOperation(); |
$$ = new NoOperation(); |
265 |
} else { |
} else { |
266 |
if (name[0] == '@') |
if (name[0] == '@') |
267 |
PARSE_WRN("Variable declared as string, integer expression assigned though."); |
PARSE_WRN(@5, "Variable declared as string, integer expression assigned though."); |
268 |
int i = 0; |
int i = 0; |
269 |
IntExprRef expr = $5; |
IntExprRef expr = $5; |
270 |
if (expr->isConstExpr()) |
if (expr->isConstExpr()) |
271 |
i = expr->evalInt(); |
i = expr->evalInt(); |
272 |
else |
else |
273 |
PARSE_ERR((String("Assignment to const integer variable '") + name + "' requires const expression.").c_str()); |
PARSE_ERR(@5, (String("Assignment to const integer variable '") + name + "' requires const expression.").c_str()); |
274 |
ConstIntVariableRef var = new ConstIntVariable(i); |
ConstIntVariableRef var = new ConstIntVariable(i); |
275 |
context->vartable[name] = var; |
context->vartable[name] = var; |
276 |
//$$ = new Assignment(var, new IntLiteral(i)); |
//$$ = new Assignment(var, new IntLiteral(i)); |
284 |
if ($3->exprType() == INT_EXPR) { |
if ($3->exprType() == INT_EXPR) { |
285 |
$$ = new While($3, $5); |
$$ = new While($3, $5); |
286 |
} else { |
} else { |
287 |
PARSE_ERR("Condition for 'while' loops must be integer expression."); |
PARSE_ERR(@3, "Condition for 'while' loops must be integer expression."); |
288 |
$$ = new While(new IntLiteral(0), $5); |
$$ = new While(new IntLiteral(0), $5); |
289 |
} |
} |
290 |
} |
} |
298 |
if ($2->exprType() == INT_EXPR) { |
if ($2->exprType() == INT_EXPR) { |
299 |
$$ = new SelectCase($2, $3); |
$$ = new SelectCase($2, $3); |
300 |
} else { |
} else { |
301 |
PARSE_ERR("Statement 'select' can only by applied to integer expressions."); |
PARSE_ERR(@2, "Statement 'select' can only by applied to integer expressions."); |
302 |
$$ = new SelectCase(new IntLiteral(0), $3); |
$$ = new SelectCase(new IntLiteral(0), $3); |
303 |
} |
} |
304 |
} |
} |
333 |
ArgsRef args = $3; |
ArgsRef args = $3; |
334 |
VMFunction* fn = context->functionProvider->functionByName(name); |
VMFunction* fn = context->functionProvider->functionByName(name); |
335 |
if (!fn) { |
if (!fn) { |
336 |
PARSE_ERR((String("No built-in function with name '") + name + "'.").c_str()); |
PARSE_ERR(@1, (String("No built-in function with name '") + name + "'.").c_str()); |
337 |
$$ = new FunctionCall(name, args, NULL); |
$$ = new FunctionCall(name, args, NULL); |
338 |
} else if (args->argsCount() < fn->minRequiredArgs()) { |
} else if (args->argsCount() < fn->minRequiredArgs()) { |
339 |
PARSE_ERR((String("Built-in function '") + name + "' requires at least " + ToString(fn->minRequiredArgs()) + " arguments.").c_str()); |
PARSE_ERR(@3, (String("Built-in function '") + name + "' requires at least " + ToString(fn->minRequiredArgs()) + " arguments.").c_str()); |
340 |
$$ = new FunctionCall(name, args, NULL); |
$$ = new FunctionCall(name, args, NULL); |
341 |
} else if (args->argsCount() > fn->maxAllowedArgs()) { |
} else if (args->argsCount() > fn->maxAllowedArgs()) { |
342 |
PARSE_ERR((String("Built-in function '") + name + "' accepts max. " + ToString(fn->maxAllowedArgs()) + " arguments.").c_str()); |
PARSE_ERR(@3, (String("Built-in function '") + name + "' accepts max. " + ToString(fn->maxAllowedArgs()) + " arguments.").c_str()); |
343 |
$$ = new FunctionCall(name, args, NULL); |
$$ = new FunctionCall(name, args, NULL); |
344 |
} else { |
} else { |
345 |
bool argsOK = true; |
bool argsOK = true; |
346 |
for (int i = 0; i < args->argsCount(); ++i) { |
for (int i = 0; i < args->argsCount(); ++i) { |
347 |
if (args->arg(i)->exprType() != fn->argType(i) && !fn->acceptsArgType(i, args->arg(i)->exprType())) { |
if (args->arg(i)->exprType() != fn->argType(i) && !fn->acceptsArgType(i, args->arg(i)->exprType())) { |
348 |
PARSE_ERR((String("Argument ") + ToString(i+1) + " of built-in function '" + name + "' expects " + typeStr(fn->argType(i)) + " type, but type " + typeStr(args->arg(i)->exprType()) + " was given instead.").c_str()); |
PARSE_ERR(@3, (String("Argument ") + ToString(i+1) + " of built-in function '" + name + "' expects " + typeStr(fn->argType(i)) + " type, but type " + typeStr(args->arg(i)->exprType()) + " was given instead.").c_str()); |
349 |
argsOK = false; |
argsOK = false; |
350 |
break; |
break; |
351 |
} |
} |
359 |
ArgsRef args = new Args; |
ArgsRef args = new Args; |
360 |
VMFunction* fn = context->functionProvider->functionByName(name); |
VMFunction* fn = context->functionProvider->functionByName(name); |
361 |
if (!fn) { |
if (!fn) { |
362 |
PARSE_ERR((String("No built-in function with name '") + name + "'.").c_str()); |
PARSE_ERR(@1, (String("No built-in function with name '") + name + "'.").c_str()); |
363 |
$$ = new FunctionCall(name, args, NULL); |
$$ = new FunctionCall(name, args, NULL); |
364 |
} else if (fn->minRequiredArgs() > 0) { |
} else if (fn->minRequiredArgs() > 0) { |
365 |
PARSE_ERR((String("Built-in function '") + name + "' requires at least " + ToString(fn->minRequiredArgs()) + " arguments.").c_str()); |
PARSE_ERR(@3, (String("Built-in function '") + name + "' requires at least " + ToString(fn->minRequiredArgs()) + " arguments.").c_str()); |
366 |
$$ = new FunctionCall(name, args, NULL); |
$$ = new FunctionCall(name, args, NULL); |
367 |
} else { |
} else { |
368 |
$$ = new FunctionCall(name, args, fn); |
$$ = new FunctionCall(name, args, fn); |
374 |
ArgsRef args = new Args; |
ArgsRef args = new Args; |
375 |
VMFunction* fn = context->functionProvider->functionByName(name); |
VMFunction* fn = context->functionProvider->functionByName(name); |
376 |
if (!fn) { |
if (!fn) { |
377 |
PARSE_ERR((String("No built-in function with name '") + name + "'.").c_str()); |
PARSE_ERR(@1, (String("No built-in function with name '") + name + "'.").c_str()); |
378 |
$$ = new FunctionCall(name, args, NULL); |
$$ = new FunctionCall(name, args, NULL); |
379 |
} else if (fn->minRequiredArgs() > 0) { |
} else if (fn->minRequiredArgs() > 0) { |
380 |
PARSE_ERR((String("Built-in function '") + name + "' requires at least " + ToString(fn->minRequiredArgs()) + " arguments.").c_str()); |
PARSE_ERR(@1, (String("Built-in function '") + name + "' requires at least " + ToString(fn->minRequiredArgs()) + " arguments.").c_str()); |
381 |
$$ = new FunctionCall(name, args, NULL); |
$$ = new FunctionCall(name, args, NULL); |
382 |
} else { |
} else { |
383 |
$$ = new FunctionCall(name, args, fn); |
$$ = new FunctionCall(name, args, fn); |
403 |
const char* name = $1; |
const char* name = $1; |
404 |
VariableRef var = context->variableByName(name); |
VariableRef var = context->variableByName(name); |
405 |
if (!var) |
if (!var) |
406 |
PARSE_ERR((String("Variable assignment: No variable declared with name '") + name + "'.").c_str()); |
PARSE_ERR(@1, (String("Variable assignment: No variable declared with name '") + name + "'.").c_str()); |
407 |
else if (var->isConstExpr()) |
else if (var->isConstExpr()) |
408 |
PARSE_ERR((String("Variable assignment: Cannot modify const variable '") + name + "'.").c_str()); |
PARSE_ERR(@2, (String("Variable assignment: Cannot modify const variable '") + name + "'.").c_str()); |
409 |
else if (var->exprType() != $3->exprType()) |
else if (var->exprType() != $3->exprType()) |
410 |
PARSE_ERR((String("Variable assignment: Variable '") + name + "' is of type " + typeStr(var->exprType()) + ", assignment is of type " + typeStr($3->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Variable assignment: Variable '") + name + "' is of type " + typeStr(var->exprType()) + ", assignment is of type " + typeStr($3->exprType()) + " though.").c_str()); |
411 |
$$ = new Assignment(var, $3); |
$$ = new Assignment(var, $3); |
412 |
} |
} |
413 |
| VARIABLE '[' expr ']' ASSIGNMENT expr { |
| VARIABLE '[' expr ']' ASSIGNMENT expr { |
414 |
const char* name = $1; |
const char* name = $1; |
415 |
VariableRef var = context->variableByName(name); |
VariableRef var = context->variableByName(name); |
416 |
if (!var) |
if (!var) |
417 |
PARSE_ERR((String("No variable declared with name '") + name + "'.").c_str()); |
PARSE_ERR(@1, (String("No variable declared with name '") + name + "'.").c_str()); |
418 |
else if (var->exprType() != INT_ARR_EXPR) |
else if (var->exprType() != INT_ARR_EXPR) |
419 |
PARSE_ERR((String("Variable '") + name + "' is not an array variable.").c_str()); |
PARSE_ERR(@2, (String("Variable '") + name + "' is not an array variable.").c_str()); |
420 |
else if ($3->exprType() != INT_EXPR) |
else if ($3->exprType() != INT_EXPR) |
421 |
PARSE_ERR((String("Array variable '") + name + "' accessed with non integer expression.").c_str()); |
PARSE_ERR(@3, (String("Array variable '") + name + "' accessed with non integer expression.").c_str()); |
422 |
else if ($6->exprType() != INT_EXPR) |
else if ($6->exprType() != INT_EXPR) |
423 |
PARSE_ERR((String("Value assigned to array variable '") + name + "' must be an integer expression.").c_str()); |
PARSE_ERR(@5, (String("Value assigned to array variable '") + name + "' must be an integer expression.").c_str()); |
424 |
IntArrayElementRef element = new IntArrayElement(var, $3); |
IntArrayElementRef element = new IntArrayElement(var, $3); |
425 |
$$ = new Assignment(element, $6); |
$$ = new Assignment(element, $6); |
426 |
} |
} |
438 |
if (var) |
if (var) |
439 |
$$ = var; |
$$ = var; |
440 |
else { |
else { |
441 |
PARSE_ERR((String("No variable declared with name '") + $1 + "'.").c_str()); |
PARSE_ERR(@1, (String("No variable declared with name '") + $1 + "'.").c_str()); |
442 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
443 |
} |
} |
444 |
} |
} |
446 |
const char* name = $1; |
const char* name = $1; |
447 |
VariableRef var = context->variableByName(name); |
VariableRef var = context->variableByName(name); |
448 |
if (!var) { |
if (!var) { |
449 |
PARSE_ERR((String("No variable declared with name '") + name + "'.").c_str()); |
PARSE_ERR(@1, (String("No variable declared with name '") + name + "'.").c_str()); |
450 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
451 |
} else if (var->exprType() != INT_ARR_EXPR) { |
} else if (var->exprType() != INT_ARR_EXPR) { |
452 |
PARSE_ERR((String("Variable '") + name + "' is not an array variable.").c_str()); |
PARSE_ERR(@2, (String("Variable '") + name + "' is not an array variable.").c_str()); |
453 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
454 |
} else if ($3->exprType() != INT_EXPR) { |
} else if ($3->exprType() != INT_EXPR) { |
455 |
PARSE_ERR((String("Array variable '") + name + "' accessed with non integer expression.").c_str()); |
PARSE_ERR(@3, (String("Array variable '") + name + "' accessed with non integer expression.").c_str()); |
456 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
457 |
} else { |
} else { |
458 |
$$ = new IntArrayElement(var, $3); |
$$ = new IntArrayElement(var, $3); |
469 |
} |
} |
470 |
| NOT unary_expr { |
| NOT unary_expr { |
471 |
if ($2->exprType() != INT_EXPR) { |
if ($2->exprType() != INT_EXPR) { |
472 |
PARSE_ERR((String("Right operand of operator 'not' must be an integer expression, is ") + typeStr($2->exprType()) + " though.").c_str()); |
PARSE_ERR(@2, (String("Right operand of operator 'not' must be an integer expression, is ") + typeStr($2->exprType()) + " though.").c_str()); |
473 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
474 |
} else { |
} else { |
475 |
$$ = new Not($2); |
$$ = new Not($2); |
499 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
500 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
501 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
502 |
PARSE_ERR((String("Left operand of operator 'or' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of operator 'or' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
503 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
504 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
505 |
PARSE_ERR((String("Right operand of operator 'or' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator 'or' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
506 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
507 |
} else { |
} else { |
508 |
$$ = new Or(lhs, rhs); |
$$ = new Or(lhs, rhs); |
517 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
518 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
519 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
520 |
PARSE_ERR((String("Left operand of operator 'and' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of operator 'and' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
521 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
522 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
523 |
PARSE_ERR((String("Right operand of operator 'and' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator 'and' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
524 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
525 |
} else { |
} else { |
526 |
$$ = new And(lhs, rhs); |
$$ = new And(lhs, rhs); |
533 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
534 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
535 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
536 |
PARSE_ERR((String("Left operand of operator '<' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of operator '<' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
537 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
538 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
539 |
PARSE_ERR((String("Right operand of operator '<' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '<' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
540 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
541 |
} else { |
} else { |
542 |
$$ = new Relation(lhs, Relation::LESS_THAN, rhs); |
$$ = new Relation(lhs, Relation::LESS_THAN, rhs); |
546 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
547 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
548 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
549 |
PARSE_ERR((String("Left operand of operator '>' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of operator '>' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
550 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
551 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
552 |
PARSE_ERR((String("Right operand of operator '>' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '>' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
553 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
554 |
} else { |
} else { |
555 |
$$ = new Relation(lhs, Relation::GREATER_THAN, rhs); |
$$ = new Relation(lhs, Relation::GREATER_THAN, rhs); |
559 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
560 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
561 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
562 |
PARSE_ERR((String("Left operand of operator '<=' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of operator '<=' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
563 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
564 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
565 |
PARSE_ERR((String("Right operand of operator '<=' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '<=' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
566 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
567 |
} else { |
} else { |
568 |
$$ = new Relation(lhs, Relation::LESS_OR_EQUAL, rhs); |
$$ = new Relation(lhs, Relation::LESS_OR_EQUAL, rhs); |
572 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
573 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
574 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
575 |
PARSE_ERR((String("Left operand of operator '>=' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of operator '>=' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
576 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
577 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
578 |
PARSE_ERR((String("Right operand of operator '>=' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '>=' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
579 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
580 |
} else { |
} else { |
581 |
$$ = new Relation(lhs, Relation::GREATER_OR_EQUAL, rhs); |
$$ = new Relation(lhs, Relation::GREATER_OR_EQUAL, rhs); |
594 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
595 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
596 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
597 |
PARSE_ERR((String("Left operand of operator '+' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of operator '+' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
598 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
599 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
600 |
PARSE_ERR((String("Right operand of operator '+' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '+' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
601 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
602 |
} else { |
} else { |
603 |
$$ = new Add(lhs,rhs); |
$$ = new Add(lhs,rhs); |
607 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
608 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
609 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
610 |
PARSE_ERR((String("Left operand of operator '-' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of operator '-' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
611 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
612 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
613 |
PARSE_ERR((String("Right operand of operator '-' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '-' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
614 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
615 |
} else { |
} else { |
616 |
$$ = new Sub(lhs,rhs); |
$$ = new Sub(lhs,rhs); |
623 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
624 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
625 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
626 |
PARSE_ERR((String("Left operand of operator '*' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of operator '*' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
627 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
628 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
629 |
PARSE_ERR((String("Right operand of operator '*' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '*' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
630 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
631 |
} else { |
} else { |
632 |
$$ = new Mul(lhs,rhs); |
$$ = new Mul(lhs,rhs); |
636 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
637 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
638 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
639 |
PARSE_ERR((String("Left operand of operator '/' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of operator '/' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
640 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
641 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
642 |
PARSE_ERR((String("Right operand of operator '/' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of operator '/' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
643 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
644 |
} else { |
} else { |
645 |
$$ = new Div(lhs,rhs); |
$$ = new Div(lhs,rhs); |
649 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
650 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
651 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
652 |
PARSE_ERR((String("Left operand of modulo operator must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@1, (String("Left operand of modulo operator must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
653 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
654 |
} else if (rhs->exprType() != INT_EXPR) { |
} else if (rhs->exprType() != INT_EXPR) { |
655 |
PARSE_ERR((String("Right operand of modulo operator must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
PARSE_ERR(@3, (String("Right operand of modulo operator must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
656 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
657 |
} else { |
} else { |
658 |
$$ = new Mod(lhs,rhs); |
$$ = new Mod(lhs,rhs); |
663 |
|
|
664 |
void InstrScript_error(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* err) { |
void InstrScript_error(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* err) { |
665 |
//fprintf(stderr, "%d: %s\n", locp->first_line, err); |
//fprintf(stderr, "%d: %s\n", locp->first_line, err); |
666 |
context->addErr(locp->first_line, err); |
context->addErr(locp->first_line, locp->first_column+1, err); |
667 |
} |
} |
668 |
|
|
669 |
void InstrScript_warning(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* txt) { |
void InstrScript_warning(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* txt) { |
670 |
//fprintf(stderr, "WRN %d: %s\n", locp->first_line, txt); |
//fprintf(stderr, "WRN %d: %s\n", locp->first_line, txt); |
671 |
context->addWrn(locp->first_line, txt); |
context->addWrn(locp->first_line, locp->first_column+1, txt); |
672 |
} |
} |