/[svn]/linuxsampler/trunk/src/scriptvm/parser.y
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/parser.y

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2889 by schoenebeck, Mon Apr 25 17:28:23 2016 UTC revision 2942 by schoenebeck, Wed Jul 13 15:51:06 2016 UTC
# Line 39  Line 39 
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    
# Line 72  eventhandlers: Line 73  eventhandlers:
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();
# Line 406  assignment: Line 415  assignment:
415              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());
416          else if (var->isConstExpr())          else if (var->isConstExpr())
417              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());
418            else if (!var->isAssignable())
419                PARSE_ERR(@2, (String("Variable assignment: Variable '") + name + "' is not assignable.").c_str());
420          else if (var->exprType() != $3->exprType())          else if (var->exprType() != $3->exprType())
421              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());
422          $$ = new Assignment(var, $3);          $$ = new Assignment(var, $3);
# Line 467  unary_expr: Line 478  unary_expr:
478      | '-' unary_expr  {      | '-' unary_expr  {
479          $$ = new Neg($2);          $$ = new Neg($2);
480      }      }
481        | BITWISE_NOT unary_expr  {
482            if ($2->exprType() != INT_EXPR) {
483                PARSE_ERR(@2, (String("Right operand of bitwise operator '.not.' must be an integer expression, is ") + typeStr($2->exprType()) + " though.").c_str());
484                $$ = new IntLiteral(0);
485            } else {
486                $$ = new BitwiseNot($2);
487            }
488        }
489      | NOT unary_expr  {      | NOT unary_expr  {
490          if ($2->exprType() != INT_EXPR) {          if ($2->exprType() != INT_EXPR) {
491              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());
# Line 480  expr: Line 499  expr:
499      concat_expr      concat_expr
500    
501  concat_expr:  concat_expr:
502      or_expr      logical_or_expr
503      | concat_expr '&' or_expr  {      | concat_expr '&' logical_or_expr  {
504          ExpressionRef lhs = $1;          ExpressionRef lhs = $1;
505          ExpressionRef rhs = $3;          ExpressionRef rhs = $3;
506          if (lhs->isConstExpr() && rhs->isConstExpr()) {          if (lhs->isConstExpr() && rhs->isConstExpr()) {
# Line 493  concat_expr: Line 512  concat_expr:
512          }          }
513      }      }
514    
515  or_expr:  logical_or_expr:
516      and_expr      logical_and_expr
517      | or_expr OR and_expr  {      | logical_or_expr OR logical_and_expr  {
518          ExpressionRef lhs = $1;          ExpressionRef lhs = $1;
519          ExpressionRef rhs = $3;          ExpressionRef rhs = $3;
520          if (lhs->exprType() != INT_EXPR) {          if (lhs->exprType() != INT_EXPR) {
# Line 509  or_expr: Line 528  or_expr:
528          }          }
529      }      }
530    
531  and_expr:  logical_and_expr:
532      rel_expr  {      bitwise_or_expr  {
533          $$ = $1;          $$ = $1;
534      }      }
535      | and_expr AND rel_expr  {      | logical_and_expr AND bitwise_or_expr  {
536          ExpressionRef lhs = $1;          ExpressionRef lhs = $1;
537          ExpressionRef rhs = $3;          ExpressionRef rhs = $3;
538          if (lhs->exprType() != INT_EXPR) {          if (lhs->exprType() != INT_EXPR) {
# Line 527  and_expr: Line 546  and_expr:
546          }          }
547      }      }
548    
549    bitwise_or_expr:
550        bitwise_and_expr
551        | bitwise_or_expr BITWISE_OR bitwise_and_expr  {
552            ExpressionRef lhs = $1;
553            ExpressionRef rhs = $3;
554            if (lhs->exprType() != INT_EXPR) {
555                PARSE_ERR(@1, (String("Left operand of bitwise operator '.or.' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str());
556                $$ = new IntLiteral(0);
557            } else if (rhs->exprType() != INT_EXPR) {
558                PARSE_ERR(@3, (String("Right operand of bitwise operator '.or.' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str());
559                $$ = new IntLiteral(0);
560            } else {
561                $$ = new BitwiseOr(lhs, rhs);
562            }
563        }
564    
565    bitwise_and_expr:
566        rel_expr  {
567            $$ = $1;
568        }
569        | bitwise_and_expr BITWISE_AND rel_expr  {
570            ExpressionRef lhs = $1;
571            ExpressionRef rhs = $3;
572            if (lhs->exprType() != INT_EXPR) {
573                PARSE_ERR(@1, (String("Left operand of bitwise operator '.and.' must be an integer expression, is ") + typeStr(lhs->exprType()) + " though.").c_str());
574                $$ = new IntLiteral(0);
575            } else if (rhs->exprType() != INT_EXPR) {
576                PARSE_ERR(@3, (String("Right operand of bitwise operator '.and.' must be an integer expression, is ") + typeStr(rhs->exprType()) + " though.").c_str());
577                $$ = new IntLiteral(0);
578            } else {
579                $$ = new BitwiseAnd(lhs, rhs);
580            }
581        }
582    
583  rel_expr:  rel_expr:
584        add_expr        add_expr
585      | rel_expr '<' add_expr  {      | rel_expr '<' add_expr  {

Legend:
Removed from v.2889  
changed lines
  Added in v.2942

  ViewVC Help
Powered by ViewVC