1 |
/* |
/* |
2 |
* Copyright (c) 2014-2016 Christian Schoenebeck and Andreas Persson |
* Copyright (c) 2014-2017 Christian Schoenebeck and Andreas Persson |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
52 |
%token CONST_ "keyword 'const'" |
%token CONST_ "keyword 'const'" |
53 |
%token POLYPHONIC "keyword 'polyphonic'" |
%token POLYPHONIC "keyword 'polyphonic'" |
54 |
%token WHILE "keyword 'while'" |
%token WHILE "keyword 'while'" |
55 |
|
%token SYNCHRONIZED "keyword 'synchronized'" |
56 |
%token IF "keyword 'if'" |
%token IF "keyword 'if'" |
57 |
%token ELSE "keyword 'else'" |
%token ELSE "keyword 'else'" |
58 |
%token SELECT "keyword 'select'" |
%token SELECT "keyword 'select'" |
70 |
%token LE "operator '<='" |
%token LE "operator '<='" |
71 |
%token GE "operator '>='" |
%token GE "operator '>='" |
72 |
%token END_OF_FILE 0 "end of file" |
%token END_OF_FILE 0 "end of file" |
73 |
|
%token UNKNOWN_CHAR "unknown character" |
74 |
|
|
75 |
%type <nEventHandlers> script sections |
%type <nEventHandlers> script sections |
76 |
%type <nEventHandler> section eventhandler |
%type <nEventHandler> section eventhandler |
282 |
PARSE_ERR(@4, (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()); |
283 |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
284 |
} else if (args->argsCount() > size) { |
} else if (args->argsCount() > size) { |
285 |
PARSE_ERR(@8, (String("Variable '") + name + |
PARSE_ERR(@8, (String("Array variable '") + name + |
286 |
"' was declared with size " + ToString(size) + |
"' was declared with size " + ToString(size) + |
287 |
" but " + ToString(args->argsCount()) + |
" but " + ToString(args->argsCount()) + |
288 |
" values were assigned." ).c_str()); |
" values were assigned." ).c_str()); |
309 |
} |
} |
310 |
} |
} |
311 |
} |
} |
312 |
|
| DECLARE CONST_ VARIABLE '[' expr ']' ASSIGNMENT '(' args ')' { |
313 |
|
const char* name = $3; |
314 |
|
if (!$5->isConstExpr()) { |
315 |
|
PARSE_ERR(@5, (String("Array variable '") + name + "' must be declared with constant array size.").c_str()); |
316 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
317 |
|
} else if ($5->exprType() != INT_EXPR) { |
318 |
|
PARSE_ERR(@5, (String("Size of array variable '") + name + "' declared with non integer expression.").c_str()); |
319 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
320 |
|
} else if (context->variableByName(name)) { |
321 |
|
PARSE_ERR(@3, (String("Redeclaration of variable '") + name + "'.").c_str()); |
322 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
323 |
|
} else { |
324 |
|
IntExprRef sizeExpr = $5; |
325 |
|
ArgsRef args = $9; |
326 |
|
int size = sizeExpr->evalInt(); |
327 |
|
if (size <= 0) { |
328 |
|
PARSE_ERR(@5, (String("Array variable '") + name + "' must be declared with positive array size.").c_str()); |
329 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
330 |
|
} else if (args->argsCount() > size) { |
331 |
|
PARSE_ERR(@9, (String("Array variable '") + name + |
332 |
|
"' was declared with size " + ToString(size) + |
333 |
|
" but " + ToString(args->argsCount()) + |
334 |
|
" values were assigned." ).c_str()); |
335 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
336 |
|
} else { |
337 |
|
bool argsOK = true; |
338 |
|
for (int i = 0; i < args->argsCount(); ++i) { |
339 |
|
if (args->arg(i)->exprType() != INT_EXPR) { |
340 |
|
PARSE_ERR( |
341 |
|
@9, |
342 |
|
(String("Array variable '") + name + |
343 |
|
"' declared with invalid assignment values. Assigned element " + |
344 |
|
ToString(i+1) + " is not an integer expression.").c_str() |
345 |
|
); |
346 |
|
argsOK = false; |
347 |
|
break; |
348 |
|
} |
349 |
|
if (!args->arg(i)->isConstExpr()) { |
350 |
|
PARSE_ERR( |
351 |
|
@9, |
352 |
|
(String("const array variable '") + name + |
353 |
|
"' must be defined with const values. Assigned element " + |
354 |
|
ToString(i+1) + " is not a const expression though.").c_str() |
355 |
|
); |
356 |
|
argsOK = false; |
357 |
|
break; |
358 |
|
} |
359 |
|
} |
360 |
|
if (argsOK) { |
361 |
|
context->vartable[name] = new IntArrayVariable(context, size, args, true); |
362 |
|
$$ = new NoOperation; |
363 |
|
} else |
364 |
|
$$ = new FunctionCall("nothing", new Args, NULL); // whatever |
365 |
|
} |
366 |
|
} |
367 |
|
} |
368 |
| DECLARE CONST_ VARIABLE ASSIGNMENT expr { |
| DECLARE CONST_ VARIABLE ASSIGNMENT expr { |
369 |
const char* name = $3; |
const char* name = $3; |
370 |
if ($5->exprType() == STRING_EXPR) { |
if ($5->exprType() == STRING_EXPR) { |
406 |
$$ = new While(new IntLiteral(0), $5); |
$$ = new While(new IntLiteral(0), $5); |
407 |
} |
} |
408 |
} |
} |
409 |
|
| SYNCHRONIZED opt_statements END SYNCHRONIZED { |
410 |
|
$$ = new SyncBlock($2); |
411 |
|
} |
412 |
| IF '(' expr ')' opt_statements ELSE opt_statements END IF { |
| IF '(' expr ')' opt_statements ELSE opt_statements END IF { |
413 |
$$ = new If($3, $5, $7); |
$$ = new If($3, $5, $7); |
414 |
} |
} |
568 |
PARSE_ERR(@1, (String("No variable declared with name '") + name + "'.").c_str()); |
PARSE_ERR(@1, (String("No variable declared with name '") + name + "'.").c_str()); |
569 |
else if (var->exprType() != INT_ARR_EXPR) |
else if (var->exprType() != INT_ARR_EXPR) |
570 |
PARSE_ERR(@2, (String("Variable '") + name + "' is not an array variable.").c_str()); |
PARSE_ERR(@2, (String("Variable '") + name + "' is not an array variable.").c_str()); |
571 |
|
else if (var->isConstExpr()) |
572 |
|
PARSE_ERR(@5, (String("Variable assignment: Cannot modify const array variable '") + name + "'.").c_str()); |
573 |
|
else if (!var->isAssignable()) |
574 |
|
PARSE_ERR(@5, (String("Variable assignment: Array variable '") + name + "' is not assignable.").c_str()); |
575 |
else if ($3->exprType() != INT_EXPR) |
else if ($3->exprType() != INT_EXPR) |
576 |
PARSE_ERR(@3, (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()); |
577 |
else if ($6->exprType() != INT_EXPR) |
else if ($6->exprType() != INT_EXPR) |
578 |
PARSE_ERR(@5, (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()); |
579 |
|
else if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize()) |
580 |
|
PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) + |
581 |
|
" exceeds size of array variable '" + name + |
582 |
|
"' which was declared with size " + |
583 |
|
ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str()); |
584 |
IntArrayElementRef element = new IntArrayElement(var, $3); |
IntArrayElementRef element = new IntArrayElement(var, $3); |
585 |
$$ = new Assignment(element, $6); |
$$ = new Assignment(element, $6); |
586 |
} |
} |
615 |
PARSE_ERR(@3, (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()); |
616 |
$$ = new IntLiteral(0); |
$$ = new IntLiteral(0); |
617 |
} else { |
} else { |
618 |
|
if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize()) |
619 |
|
PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) + |
620 |
|
" exceeds size of array variable '" + name + |
621 |
|
"' which was declared with size " + |
622 |
|
ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str()); |
623 |
$$ = new IntArrayElement(var, $3); |
$$ = new IntArrayElement(var, $3); |
624 |
} |
} |
625 |
} |
} |
913 |
} |
} |
914 |
|
|
915 |
if (! yyres) |
if (! yyres) |
916 |
return yystrlen (yystr); |
return (int) yystrlen (yystr); |
917 |
|
|
918 |
return yystpcpy (yyres, yystr) - yyres; |
return int( yystpcpy (yyres, yystr) - yyres ); |
919 |
} |
} |