39 |
%token <sValue> IDENTIFIER |
%token <sValue> IDENTIFIER |
40 |
%token <sValue> VARIABLE |
%token <sValue> VARIABLE |
41 |
%token ON END INIT NOTE DECLARE ASSIGNMENT WHILE IF OR RELEASE AND ELSE |
%token ON END INIT NOTE DECLARE ASSIGNMENT WHILE IF OR RELEASE AND ELSE |
42 |
|
%token BITWISE_OR BITWISE_AND BITWISE_NOT |
43 |
%token CONTROLLER SELECT CASE TO NOT CONST_ POLYPHONIC MOD |
%token CONTROLLER SELECT CASE TO NOT CONST_ POLYPHONIC MOD |
44 |
%token LE GE |
%token LE GE |
45 |
|
|
46 |
%type <nEventHandlers> script eventhandlers |
%type <nEventHandlers> script eventhandlers |
47 |
%type <nEventHandler> eventhandler |
%type <nEventHandler> eventhandler |
48 |
%type <nStatements> statements |
%type <nStatements> statements body |
49 |
%type <nStatement> statement assignment |
%type <nStatement> statement assignment |
50 |
%type <nFunctionCall> functioncall |
%type <nFunctionCall> functioncall |
51 |
%type <nArgs> args |
%type <nArgs> args |
52 |
%type <nExpression> arg expr or_expr and_expr rel_expr add_expr mul_expr unary_expr concat_expr |
%type <nExpression> arg expr logical_or_expr logical_and_expr bitwise_or_expr bitwise_and_expr rel_expr add_expr mul_expr unary_expr concat_expr |
53 |
%type <nCaseBranch> caseclause |
%type <nCaseBranch> caseclause |
54 |
%type <nCaseBranches> caseclauses |
%type <nCaseBranches> caseclauses |
55 |
|
|
73 |
} |
} |
74 |
|
|
75 |
eventhandler: |
eventhandler: |
76 |
ON NOTE statements END ON { |
ON NOTE body END ON { |
77 |
if (context->onNote) |
if (context->onNote) |
78 |
PARSE_ERR(@2, "Redeclaration of 'note' event handler."); |
PARSE_ERR(@2, "Redeclaration of 'note' event handler."); |
79 |
context->onNote = new OnNote($3); |
context->onNote = new OnNote($3); |
80 |
$$ = context->onNote; |
$$ = context->onNote; |
81 |
} |
} |
82 |
| ON INIT statements END ON { |
| ON INIT body END ON { |
83 |
if (context->onInit) |
if (context->onInit) |
84 |
PARSE_ERR(@2, "Redeclaration of 'init' event handler."); |
PARSE_ERR(@2, "Redeclaration of 'init' event handler."); |
85 |
context->onInit = new OnInit($3); |
context->onInit = new OnInit($3); |
86 |
$$ = context->onInit; |
$$ = context->onInit; |
87 |
} |
} |
88 |
| ON RELEASE statements END ON { |
| ON RELEASE body END ON { |
89 |
if (context->onRelease) |
if (context->onRelease) |
90 |
PARSE_ERR(@2, "Redeclaration of 'release' event handler."); |
PARSE_ERR(@2, "Redeclaration of 'release' event handler."); |
91 |
context->onRelease = new OnRelease($3); |
context->onRelease = new OnRelease($3); |
92 |
$$ = context->onRelease; |
$$ = context->onRelease; |
93 |
} |
} |
94 |
| ON CONTROLLER statements END ON { |
| ON CONTROLLER body END ON { |
95 |
if (context->onController) |
if (context->onController) |
96 |
PARSE_ERR(@2, "Redeclaration of 'controller' event handler."); |
PARSE_ERR(@2, "Redeclaration of 'controller' event handler."); |
97 |
context->onController = new OnController($3); |
context->onController = new OnController($3); |
98 |
$$ = context->onController; |
$$ = context->onController; |
99 |
} |
} |
100 |
|
|
101 |
|
body: |
102 |
|
/* epsilon (empty argument) */ { |
103 |
|
$$ = new Statements(); |
104 |
|
} |
105 |
|
| statements { |
106 |
|
$$ = $1; |
107 |
|
} |
108 |
|
|
109 |
statements: |
statements: |
110 |
statement { |
statement { |
111 |
$$ = new Statements(); |
$$ = new Statements(); |
357 |
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()); |
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()); |
358 |
argsOK = false; |
argsOK = false; |
359 |
break; |
break; |
360 |
|
} else if (fn->modifiesArg(i) && !args->arg(i)->isModifyable()) { |
361 |
|
PARSE_ERR(@3, (String("Argument ") + ToString(i+1) + " of built-in function '" + name + "' expects an assignable variable.").c_str()); |
362 |
|
argsOK = false; |
363 |
|
break; |
364 |
} |
} |
365 |
} |
} |
366 |
$$ = new FunctionCall(name, args, argsOK ? fn : NULL); |
$$ = new FunctionCall(name, args, argsOK ? fn : NULL); |
419 |
PARSE_ERR(@1, (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()); |
420 |
else if (var->isConstExpr()) |
else if (var->isConstExpr()) |
421 |
PARSE_ERR(@2, (String("Variable assignment: Cannot modify const variable '") + name + "'.").c_str()); |
PARSE_ERR(@2, (String("Variable assignment: Cannot modify const variable '") + name + "'.").c_str()); |
422 |
|
else if (!var->isAssignable()) |
423 |
|
PARSE_ERR(@2, (String("Variable assignment: Variable '") + name + "' is not assignable.").c_str()); |
424 |
else if (var->exprType() != $3->exprType()) |
else if (var->exprType() != $3->exprType()) |
425 |
PARSE_ERR(@3, (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()); |
426 |
$$ = new Assignment(var, $3); |
$$ = new Assignment(var, $3); |
482 |
| '-' unary_expr { |
| '-' unary_expr { |
483 |
$$ = new Neg($2); |
$$ = new Neg($2); |
484 |
} |
} |
485 |
|
| BITWISE_NOT unary_expr { |
486 |
|
if ($2->exprType() != INT_EXPR) { |
487 |
|
PARSE_ERR(@2, (String("Right operand of bitwise operator '.not.' must be an integer expression, is ") + typeStr($2->exprType()) + " though.").c_str()); |
488 |
|
$$ = new IntLiteral(0); |
489 |
|
} else { |
490 |
|
$$ = new BitwiseNot($2); |
491 |
|
} |
492 |
|
} |
493 |
| NOT unary_expr { |
| NOT unary_expr { |
494 |
if ($2->exprType() != INT_EXPR) { |
if ($2->exprType() != INT_EXPR) { |
495 |
PARSE_ERR(@2, (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()); |
503 |
concat_expr |
concat_expr |
504 |
|
|
505 |
concat_expr: |
concat_expr: |
506 |
or_expr |
logical_or_expr |
507 |
| concat_expr '&' or_expr { |
| concat_expr '&' logical_or_expr { |
508 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
509 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
510 |
if (lhs->isConstExpr() && rhs->isConstExpr()) { |
if (lhs->isConstExpr() && rhs->isConstExpr()) { |
516 |
} |
} |
517 |
} |
} |
518 |
|
|
519 |
or_expr: |
logical_or_expr: |
520 |
and_expr |
logical_and_expr |
521 |
| or_expr OR and_expr { |
| logical_or_expr OR logical_and_expr { |
522 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
523 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
524 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
532 |
} |
} |
533 |
} |
} |
534 |
|
|
535 |
and_expr: |
logical_and_expr: |
536 |
rel_expr { |
bitwise_or_expr { |
537 |
$$ = $1; |
$$ = $1; |
538 |
} |
} |
539 |
| and_expr AND rel_expr { |
| logical_and_expr AND bitwise_or_expr { |
540 |
ExpressionRef lhs = $1; |
ExpressionRef lhs = $1; |
541 |
ExpressionRef rhs = $3; |
ExpressionRef rhs = $3; |
542 |
if (lhs->exprType() != INT_EXPR) { |
if (lhs->exprType() != INT_EXPR) { |
550 |
} |
} |
551 |
} |
} |
552 |
|
|
553 |
|
bitwise_or_expr: |
554 |
|
bitwise_and_expr |
555 |
|
| bitwise_or_expr BITWISE_OR bitwise_and_expr { |
556 |
|
ExpressionRef lhs = $1; |
557 |
|
ExpressionRef rhs = $3; |
558 |
|
if (lhs->exprType() != INT_EXPR) { |
559 |
|
PARSE_ERR(@1, (String("Left operand of bitwise operator '.or.' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
560 |
|
$$ = new IntLiteral(0); |
561 |
|
} else if (rhs->exprType() != INT_EXPR) { |
562 |
|
PARSE_ERR(@3, (String("Right operand of bitwise operator '.or.' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
563 |
|
$$ = new IntLiteral(0); |
564 |
|
} else { |
565 |
|
$$ = new BitwiseOr(lhs, rhs); |
566 |
|
} |
567 |
|
} |
568 |
|
|
569 |
|
bitwise_and_expr: |
570 |
|
rel_expr { |
571 |
|
$$ = $1; |
572 |
|
} |
573 |
|
| bitwise_and_expr BITWISE_AND rel_expr { |
574 |
|
ExpressionRef lhs = $1; |
575 |
|
ExpressionRef rhs = $3; |
576 |
|
if (lhs->exprType() != INT_EXPR) { |
577 |
|
PARSE_ERR(@1, (String("Left operand of bitwise operator '.and.' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str()); |
578 |
|
$$ = new IntLiteral(0); |
579 |
|
} else if (rhs->exprType() != INT_EXPR) { |
580 |
|
PARSE_ERR(@3, (String("Right operand of bitwise operator '.and.' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str()); |
581 |
|
$$ = new IntLiteral(0); |
582 |
|
} else { |
583 |
|
$$ = new BitwiseAnd(lhs, rhs); |
584 |
|
} |
585 |
|
} |
586 |
|
|
587 |
rel_expr: |
rel_expr: |
588 |
add_expr |
add_expr |
589 |
| rel_expr '<' add_expr { |
| rel_expr '<' add_expr { |
720 |
|
|
721 |
void InstrScript_error(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* err) { |
void InstrScript_error(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* err) { |
722 |
//fprintf(stderr, "%d: %s\n", locp->first_line, err); |
//fprintf(stderr, "%d: %s\n", locp->first_line, err); |
723 |
context->addErr(locp->first_line, locp->first_column+1, err); |
context->addErr(locp->first_line, locp->last_line, locp->first_column+1, locp->last_column+1, err); |
724 |
} |
} |
725 |
|
|
726 |
void InstrScript_warning(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* txt) { |
void InstrScript_warning(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* txt) { |
727 |
//fprintf(stderr, "WRN %d: %s\n", locp->first_line, txt); |
//fprintf(stderr, "WRN %d: %s\n", locp->first_line, txt); |
728 |
context->addWrn(locp->first_line, locp->first_column+1, txt); |
context->addWrn(locp->first_line, locp->last_line, locp->first_column+1, locp->last_column+1, txt); |
729 |
} |
} |