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 |
|
|
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]) { |
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) */ |
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 |
} |
} |