/[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 3008 by schoenebeck, Tue Oct 11 18:25:12 2016 UTC revision 3257 by schoenebeck, Tue May 30 17:20:02 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 31  Line 31 
31  %parse-param { LinuxSampler::ParserContext* context }  %parse-param { LinuxSampler::ParserContext* context }
32  %lex-param { void* scanner }  %lex-param { void* scanner }
33  // avoid symbol collision with other (i.e. future) auto generated (f)lex scanners  // avoid symbol collision with other (i.e. future) auto generated (f)lex scanners
34  %name-prefix "InstrScript_"  // (NOTE: "=" is deprecated here with Bison 3.x, however removing it would cause an error with Bison 2.x)
35    %name-prefix="InstrScript_"
36  %locations  %locations
37  %defines  %defines
38  %error-verbose  %error-verbose
# Line 279  statement: Line 280  statement:
280                  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());
281                  $$ = new FunctionCall("nothing", new Args, NULL); // whatever                  $$ = new FunctionCall("nothing", new Args, NULL); // whatever
282              } else if (args->argsCount() > size) {              } else if (args->argsCount() > size) {
283                  PARSE_ERR(@8, (String("Variable '") + name +                  PARSE_ERR(@8, (String("Array variable '") + name +
284                            "' was declared with size " + ToString(size) +                            "' was declared with size " + ToString(size) +
285                            " but " + ToString(args->argsCount()) +                            " but " + ToString(args->argsCount()) +
286                            " values were assigned." ).c_str());                            " values were assigned." ).c_str());
# Line 298  statement: Line 299  statement:
299                          break;                          break;
300                      }                      }
301                  }                  }
302                  if (argsOK)                  if (argsOK) {
303                      $$ = context->vartable[name] = new IntArrayVariable(context, size, args);                      context->vartable[name] = new IntArrayVariable(context, size, args);
304                  else                      $$ = new NoOperation;
305                    } else
306                        $$ = new FunctionCall("nothing", new Args, NULL); // whatever
307                }
308            }
309        }
310        | DECLARE CONST_ VARIABLE '[' expr ']' ASSIGNMENT '(' args ')'  {
311            const char* name = $3;
312            if (!$5->isConstExpr()) {
313                PARSE_ERR(@5, (String("Array variable '") + name + "' must be declared with constant array size.").c_str());
314                $$ = new FunctionCall("nothing", new Args, NULL); // whatever
315            } else if ($5->exprType() != INT_EXPR) {
316                PARSE_ERR(@5, (String("Size of array variable '") + name + "' declared with non integer expression.").c_str());
317                $$ = new FunctionCall("nothing", new Args, NULL); // whatever
318            } else if (context->variableByName(name)) {
319                PARSE_ERR(@3, (String("Redeclaration of variable '") + name + "'.").c_str());
320                $$ = new FunctionCall("nothing", new Args, NULL); // whatever
321            } else {
322                IntExprRef sizeExpr = $5;
323                ArgsRef args = $9;
324                int size = sizeExpr->evalInt();
325                if (size <= 0) {
326                    PARSE_ERR(@5, (String("Array variable '") + name + "' must be declared with positive array size.").c_str());
327                    $$ = new FunctionCall("nothing", new Args, NULL); // whatever
328                } else if (args->argsCount() > size) {
329                    PARSE_ERR(@9, (String("Array variable '") + name +
330                              "' was declared with size " + ToString(size) +
331                              " but " + ToString(args->argsCount()) +
332                              " values were assigned." ).c_str());
333                    $$ = new FunctionCall("nothing", new Args, NULL); // whatever          
334                } else {
335                    bool argsOK = true;
336                    for (int i = 0; i < args->argsCount(); ++i) {
337                        if (args->arg(i)->exprType() != INT_EXPR) {
338                            PARSE_ERR(
339                                @9,
340                                (String("Array variable '") + name +
341                                "' declared with invalid assignment values. Assigned element " +
342                                ToString(i+1) + " is not an integer expression.").c_str()
343                            );
344                            argsOK = false;
345                            break;
346                        }
347                        if (!args->arg(i)->isConstExpr()) {
348                            PARSE_ERR(
349                                @9,
350                                (String("const array variable '") + name +
351                                "' must be defined with const values. Assigned element " +
352                                ToString(i+1) + " is not a const expression though.").c_str()
353                            );
354                            argsOK = false;
355                            break;
356                        }
357                    }
358                    if (argsOK) {
359                        context->vartable[name] = new IntArrayVariable(context, size, args, true);
360                        $$ = new NoOperation;
361                    } else
362                      $$ = new FunctionCall("nothing", new Args, NULL); // whatever                      $$ = new FunctionCall("nothing", new Args, NULL); // whatever
363              }              }
364          }          }
# Line 505  assignment: Line 563  assignment:
563              PARSE_ERR(@1, (String("No variable declared with name '") + name + "'.").c_str());              PARSE_ERR(@1, (String("No variable declared with name '") + name + "'.").c_str());
564          else if (var->exprType() != INT_ARR_EXPR)          else if (var->exprType() != INT_ARR_EXPR)
565              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());
566            else if (var->isConstExpr())
567                PARSE_ERR(@5, (String("Variable assignment: Cannot modify const array variable '") + name + "'.").c_str());
568            else if (!var->isAssignable())
569                PARSE_ERR(@5, (String("Variable assignment: Array variable '") + name + "' is not assignable.").c_str());
570          else if ($3->exprType() != INT_EXPR)          else if ($3->exprType() != INT_EXPR)
571              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());
572          else if ($6->exprType() != INT_EXPR)          else if ($6->exprType() != INT_EXPR)
573              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());
574            else if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize())
575                PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) +
576                              " exceeds size of array variable '" + name +
577                              "' which was declared with size " +
578                              ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str());
579          IntArrayElementRef element = new IntArrayElement(var, $3);          IntArrayElementRef element = new IntArrayElement(var, $3);
580          $$ = new Assignment(element, $6);          $$ = new Assignment(element, $6);
581      }      }
# Line 543  unary_expr: Line 610  unary_expr:
610              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());
611              $$ = new IntLiteral(0);              $$ = new IntLiteral(0);
612          } else {          } else {
613                if ($3->isConstExpr() && $3->asInt()->evalInt() >= ((IntArrayVariableRef)var)->arraySize())
614                    PARSE_WRN(@3, (String("Index ") + ToString($3->asInt()->evalInt()) +
615                                   " exceeds size of array variable '" + name +
616                                   "' which was declared with size " +
617                                   ToString(((IntArrayVariableRef)var)->arraySize()) + ".").c_str());
618              $$ = new IntArrayElement(var, $3);              $$ = new IntArrayElement(var, $3);
619          }          }
620      }      }
# Line 830  int InstrScript_tnamerr(char* yyres, con Line 902  int InstrScript_tnamerr(char* yyres, con
902                yyres[yyn] = '\0';                yyres[yyn] = '\0';
903              return yyn;              return yyn;
904            }            }
905    /*
906      do_not_strip_quotes: ;      do_not_strip_quotes: ;
907    */
908      }      }
909    
910    if (! yyres)    if (! yyres)
911      return yystrlen (yystr);      return (int) yystrlen (yystr);
912    
913    return yystpcpy (yyres, yystr) - yyres;    return int( yystpcpy (yyres, yystr) - yyres );
914  }  }

Legend:
Removed from v.3008  
changed lines
  Added in v.3257

  ViewVC Help
Powered by ViewVC