/[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 3054 by schoenebeck, Thu Dec 15 12:47:45 2016 UTC revision 3259 by schoenebeck, Wed May 31 14:41:04 2017 UTC
# Line 1  Line 1 
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   *   *
# Line 69  Line 69 
69  %token LE "operator '<='"  %token LE "operator '<='"
70  %token GE "operator '>='"  %token GE "operator '>='"
71  %token END_OF_FILE 0 "end of file"  %token END_OF_FILE 0 "end of file"
72    %token UNKNOWN_CHAR "unknown character"
73    
74  %type <nEventHandlers> script sections  %type <nEventHandlers> script sections
75  %type <nEventHandler> section eventhandler  %type <nEventHandler> section eventhandler
# Line 280  statement: Line 281  statement:
281                  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());
282                  $$ = new FunctionCall("nothing", new Args, NULL); // whatever                  $$ = new FunctionCall("nothing", new Args, NULL); // whatever
283              } else if (args->argsCount() > size) {              } else if (args->argsCount() > size) {
284                  PARSE_ERR(@8, (String("Variable '") + name +                  PARSE_ERR(@8, (String("Array variable '") + name +
285                            "' was declared with size " + ToString(size) +                            "' was declared with size " + ToString(size) +
286                            " but " + ToString(args->argsCount()) +                            " but " + ToString(args->argsCount()) +
287                            " values were assigned." ).c_str());                            " values were assigned." ).c_str());
# Line 307  statement: Line 308  statement:
308              }              }
309          }          }
310      }      }
311        | DECLARE CONST_ VARIABLE '[' expr ']' ASSIGNMENT '(' args ')'  {
312            const char* name = $3;
313            if (!$5->isConstExpr()) {
314                PARSE_ERR(@5, (String("Array variable '") + name + "' must be declared with constant array size.").c_str());
315                $$ = new FunctionCall("nothing", new Args, NULL); // whatever
316            } else if ($5->exprType() != INT_EXPR) {
317                PARSE_ERR(@5, (String("Size of array variable '") + name + "' declared with non integer expression.").c_str());
318                $$ = new FunctionCall("nothing", new Args, NULL); // whatever
319            } else if (context->variableByName(name)) {
320                PARSE_ERR(@3, (String("Redeclaration of variable '") + name + "'.").c_str());
321                $$ = new FunctionCall("nothing", new Args, NULL); // whatever
322            } else {
323                IntExprRef sizeExpr = $5;
324                ArgsRef args = $9;
325                int size = sizeExpr->evalInt();
326                if (size <= 0) {
327                    PARSE_ERR(@5, (String("Array variable '") + name + "' must be declared with positive array size.").c_str());
328                    $$ = new FunctionCall("nothing", new Args, NULL); // whatever
329                } else if (args->argsCount() > size) {
330                    PARSE_ERR(@9, (String("Array variable '") + name +
331                              "' was declared with size " + ToString(size) +
332                              " but " + ToString(args->argsCount()) +
333                              " values were assigned." ).c_str());
334                    $$ = new FunctionCall("nothing", new Args, NULL); // whatever          
335                } else {
336                    bool argsOK = true;
337                    for (int i = 0; i < args->argsCount(); ++i) {
338                        if (args->arg(i)->exprType() != INT_EXPR) {
339                            PARSE_ERR(
340                                @9,
341                                (String("Array variable '") + name +
342                                "' declared with invalid assignment values. Assigned element " +
343                                ToString(i+1) + " is not an integer expression.").c_str()
344                            );
345                            argsOK = false;
346                            break;
347                        }
348                        if (!args->arg(i)->isConstExpr()) {
349                            PARSE_ERR(
350                                @9,
351                                (String("const array variable '") + name +
352                                "' must be defined with const values. Assigned element " +
353                                ToString(i+1) + " is not a const expression though.").c_str()
354                            );
355                            argsOK = false;
356                            break;
357                        }
358                    }
359                    if (argsOK) {
360                        context->vartable[name] = new IntArrayVariable(context, size, args, true);
361                        $$ = new NoOperation;
362                    } else
363                        $$ = new FunctionCall("nothing", new Args, NULL); // whatever
364                }
365            }
366        }
367      | DECLARE CONST_ VARIABLE ASSIGNMENT expr  {      | DECLARE CONST_ VARIABLE ASSIGNMENT expr  {
368          const char* name = $3;          const char* name = $3;
369          if ($5->exprType() == STRING_EXPR) {          if ($5->exprType() == STRING_EXPR) {
# Line 507  assignment: Line 564  assignment:
564              PARSE_ERR(@1, (String("No variable declared with name '") + name + "'.").c_str());              PARSE_ERR(@1, (String("No variable declared with name '") + name + "'.").c_str());
565          else if (var->exprType() != INT_ARR_EXPR)          else if (var->exprType() != INT_ARR_EXPR)
566              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());
567            else if (var->isConstExpr())
568                PARSE_ERR(@5, (String("Variable assignment: Cannot modify const array variable '") + name + "'.").c_str());
569            else if (!var->isAssignable())
570                PARSE_ERR(@5, (String("Variable assignment: Array variable '") + name + "' is not assignable.").c_str());
571          else if ($3->exprType() != INT_EXPR)          else if ($3->exprType() != INT_EXPR)
572              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());
573          else if ($6->exprType() != INT_EXPR)          else if ($6->exprType() != INT_EXPR)
574              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());
575            else if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize())
576                PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) +
577                              " exceeds size of array variable '" + name +
578                              "' which was declared with size " +
579                              ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str());
580          IntArrayElementRef element = new IntArrayElement(var, $3);          IntArrayElementRef element = new IntArrayElement(var, $3);
581          $$ = new Assignment(element, $6);          $$ = new Assignment(element, $6);
582      }      }
# Line 545  unary_expr: Line 611  unary_expr:
611              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());
612              $$ = new IntLiteral(0);              $$ = new IntLiteral(0);
613          } else {          } else {
614                if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize())
615                    PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) +
616                                   " exceeds size of array variable '" + name +
617                                   "' which was declared with size " +
618                                   ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str());
619              $$ = new IntArrayElement(var, $3);              $$ = new IntArrayElement(var, $3);
620          }          }
621      }      }

Legend:
Removed from v.3054  
changed lines
  Added in v.3259

  ViewVC Help
Powered by ViewVC