/[svn]/linuxsampler/trunk/src/scriptvm/scanner.l
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/scanner.l

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

revision 3572 by schoenebeck, Fri Aug 23 11:44:00 2019 UTC revision 3573 by schoenebeck, Tue Aug 27 21:36:53 2019 UTC
# Line 128  UNIT     (s|(Hz)|B) Line 128  UNIT     (s|(Hz)|B)
128      return INTEGER;      return INTEGER;
129  }  }
130    
131    {DIGIT}+"."{DIGIT}+ {
132        yylval->fValue = atof(yytext);
133        return REAL;
134    }
135    
136  {DIGIT}+({METRIC}{1,2}|({METRIC}{0,2}{UNIT}?)) {  {DIGIT}+({METRIC}{1,2}|({METRIC}{0,2}{UNIT}?)) {
137      int pos = 0;      int pos = 0;
138    
# Line 157  UNIT     (s|(Hz)|B) Line 162  UNIT     (s|(Hz)|B)
162                  continue;                  continue;
163              default:              default:
164                  yylval->iUnitValue.prefix[i] = VM_NO_PREFIX;                  yylval->iUnitValue.prefix[i] = VM_NO_PREFIX;
165                  goto parseStdUnit;                  goto parseIntStdUnit;
166          }          }
167      }      }
168    
169      parseStdUnit:      parseIntStdUnit:
170    
171      // parse standard measurement unit      // parse standard measurement unit
172      switch (yytext[pos]) {      switch (yytext[pos]) {
# Line 174  UNIT     (s|(Hz)|B) Line 179  UNIT     (s|(Hz)|B)
179      return INTEGER_UNIT;      return INTEGER_UNIT;
180  }  }
181    
182   /* there is currently no support for floating point numbers in NKSP yet */  {DIGIT}+"."{DIGIT}+({METRIC}{1,2}|({METRIC}{0,2}{UNIT}?)) {
183   /*{DIGIT}+"."{DIGIT}* {      int pos = 0;
184      printf("A float: %s (%g)\n", yytext, atof(yytext));  
185   }*/      // parse number portion
186        for (; (yytext[pos] >= '0' && yytext[pos] <= '9') || yytext[pos] == '.'; ++pos) {
187        }
188        {
189            const char tmp = yytext[pos];
190            yytext[pos] = 0; // mark temporary end of string
191            yylval->fUnitValue.fValue = atof(yytext);
192            yytext[pos] = tmp; // restore
193        }
194    
195        // parse metric prefix portion
196        for (int i = 0; i < 2; ++i, ++pos) {
197            switch (yytext[pos]) {
198                case 'k': yylval->fUnitValue.prefix[i] = VM_KILO;  continue;
199                case 'h': yylval->fUnitValue.prefix[i] = VM_HECTO; continue;
200                case 'c': yylval->fUnitValue.prefix[i] = VM_CENTI; continue;
201                case 'm': yylval->fUnitValue.prefix[i] = VM_MILLI; continue;
202                case 'u': yylval->fUnitValue.prefix[i] = VM_MICRO; continue;
203                case 'd':
204                    if (yytext[pos+1] == 'a') {
205                        yylval->fUnitValue.prefix[i] = VM_DECA;
206                        ++pos;
207                    } else {
208                        yylval->fUnitValue.prefix[i] = VM_DECI;
209                    }
210                    continue;
211                default:
212                    yylval->fUnitValue.prefix[i] = VM_NO_PREFIX;
213                    goto parseRealStdUnit;
214            }
215        }
216    
217        parseRealStdUnit:
218    
219        // parse standard measurement unit
220        switch (yytext[pos]) {
221            case 's': yylval->fUnitValue.unit = VM_SECOND;  break;
222            case 'H': yylval->fUnitValue.unit = VM_HERTZ;   break;
223            case 'B': yylval->fUnitValue.unit = VM_BEL;     break;
224            default:  yylval->fUnitValue.unit = VM_NO_UNIT; break;
225        }
226    
227        return REAL_UNIT;
228    }
229    
230    
231   /* Preprocessor statement:  SET_CONDITION(name) */   /* Preprocessor statement:  SET_CONDITION(name) */
# Line 323  UNIT     (s|(Hz)|B) Line 371  UNIT     (s|(Hz)|B)
371      return *yytext;      return *yytext;
372  }  }
373    
374  ("$"|"@"|"%"){ID} {  ("$"|"@"|"%"|"~"|"?"){ID} {
375      yylval->sValue = strdup(yytext);      yylval->sValue = strdup(yytext);
376      return VARIABLE;      return VARIABLE;
377  }  }

Legend:
Removed from v.3572  
changed lines
  Added in v.3573

  ViewVC Help
Powered by ViewVC