/[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 2951 by schoenebeck, Fri Jul 15 20:07:47 2016 UTC revision 3054 by schoenebeck, Thu Dec 15 12:47:45 2016 UTC
# Line 18  Line 18 
18    
19      void InstrScript_error(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* err);      void InstrScript_error(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* err);
20      void InstrScript_warning(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* txt);      void InstrScript_warning(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* txt);
21        int InstrScript_tnamerr(char* yyres, const char* yystr);
22      int InstrScript_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);      int InstrScript_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);
23      #define scanner context->scanner      #define scanner context->scanner
24      #define PARSE_ERR(loc,txt)  yyerror(&loc, context, txt)      #define PARSE_ERR(loc,txt)  yyerror(&loc, context, txt)
25      #define PARSE_WRN(loc,txt)  InstrScript_warning(&loc, context, txt)      #define PARSE_WRN(loc,txt)  InstrScript_warning(&loc, context, txt)
26        #define yytnamerr(res,str)  InstrScript_tnamerr(res, str)
27  %}  %}
28    
29  // generate reentrant safe parser  // generate reentrant safe parser
# Line 29  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
39    
40  %token <iValue> INTEGER  %token <iValue> INTEGER "integer literal"
41  %token <sValue> STRING  %token <sValue> STRING "string literal"
42  %token <sValue> IDENTIFIER  %token <sValue> IDENTIFIER "function name"
43  %token <sValue> VARIABLE  %token <sValue> VARIABLE "variable name"
44  %token ON END INIT NOTE DECLARE ASSIGNMENT WHILE IF OR RELEASE AND ELSE FUNCTION CALL  %token ON "keyword 'on'"
45  %token BITWISE_OR BITWISE_AND BITWISE_NOT  %token END "keyword 'end'"
46  %token CONTROLLER SELECT CASE TO NOT CONST_ POLYPHONIC MOD  %token INIT "keyword 'init'"
47  %token LE GE  %token NOTE "keyword 'note'"
48    %token RELEASE "keyword 'release'"
49    %token CONTROLLER "keyword 'controller'"
50    %token DECLARE "keyword 'declare'"
51    %token ASSIGNMENT "operator ':='"
52    %token CONST_ "keyword 'const'"
53    %token POLYPHONIC "keyword 'polyphonic'"
54    %token WHILE "keyword 'while'"
55    %token IF "keyword 'if'"
56    %token ELSE "keyword 'else'"
57    %token SELECT "keyword 'select'"
58    %token CASE "keyword 'case'"
59    %token TO "keyword 'to'"
60    %token OR "operator 'or'"
61    %token AND "operator 'and'"
62    %token NOT "operator 'not'"
63    %token BITWISE_OR "bitwise operator '.or.'"
64    %token BITWISE_AND "bitwise operator '.and.'"
65    %token BITWISE_NOT "bitwise operator '.not.'"
66    %token FUNCTION "keyword 'function'"
67    %token CALL "keyword 'call'"
68    %token MOD "operator 'mod'"
69    %token LE "operator '<='"
70    %token GE "operator '>='"
71    %token END_OF_FILE 0 "end of file"
72    
73  %type <nEventHandlers> script sections  %type <nEventHandlers> script sections
74  %type <nEventHandler> section eventhandler  %type <nEventHandler> section eventhandler
# Line 272  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                      $$ = new FunctionCall("nothing", new Args, NULL); // whatever
307              }              }
308          }          }
# Line 774  void InstrScript_warning(YYLTYPE* locp, Line 802  void InstrScript_warning(YYLTYPE* locp,
802      //fprintf(stderr, "WRN %d: %s\n", locp->first_line, txt);      //fprintf(stderr, "WRN %d: %s\n", locp->first_line, txt);
803      context->addWrn(locp->first_line, locp->last_line, locp->first_column+1, locp->last_column+1, txt);      context->addWrn(locp->first_line, locp->last_line, locp->first_column+1, locp->last_column+1, txt);
804  }  }
805    
806    /// Custom implementation of yytnamerr() to ensure quotation is always stripped from token names before printing them to error messages.
807    int InstrScript_tnamerr(char* yyres, const char* yystr) {
808      if (*yystr == '"') {
809          int yyn = 0;
810          char const *yyp = yystr;
811          for (;;)
812            switch (*++yyp)
813              {
814    /*
815              case '\'':
816              case ',':
817                goto do_not_strip_quotes;
818    
819              case '\\':
820                if (*++yyp != '\\')
821                  goto do_not_strip_quotes;
822    */
823                /* Fall through.  */
824              default:
825                if (yyres)
826                  yyres[yyn] = *yyp;
827                yyn++;
828                break;
829    
830              case '"':
831                if (yyres)
832                  yyres[yyn] = '\0';
833                return yyn;
834              }
835    /*
836        do_not_strip_quotes: ;
837    */
838        }
839    
840      if (! yyres)
841        return (int) yystrlen (yystr);
842    
843      return int( yystpcpy (yyres, yystr) - yyres );
844    }

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

  ViewVC Help
Powered by ViewVC