Floating point must match '0.' and the like

This commit is contained in:
Victor Fernandes 2017-03-19 23:13:20 -04:00
parent 3df3b6943a
commit 3ef9112429
1 changed files with 50 additions and 31 deletions

View File

@ -142,12 +142,15 @@ Token malar_next_token(Buffer * sc_buf)
}
else if (c == '<') {
t.code = SCC_OP_T; /* String concatenation operator */
return t;
}
else {
t.code = REL_OP_T;
t.attribute.rel_op = LT; /* Less-than operator */
}
b_retract(sc_buf);
return t;
}
case '.':
b_setmark(sc_buf, b_getcoffset(sc_buf)); /* Set mark before continuing (AND|OR case) */
c = b_getc(sc_buf);
@ -522,22 +525,38 @@ err_lex C-type string. */
Token aa_func08(char lexeme[]) {
Token t;
double temp_dbl = 0.0f;
unsigned int i, check = 0;
char* substr = (char*)calloc(ERR_LEN, sizeof(char));
t.code = FPL_T;
if (strstr(lexeme, "0.0")) {
if (strcmp(lexeme, "0.0") == 0) {
t.attribute.flt_value = 0.0f;
}
else /* strtof() returns 0 if the value is out of range) */
temp_dbl = strtof(lexeme, NULL);
#ifdef DEBUG
printf("Lexeme: '%s' | FLT value: %f \n", lexeme, temp_dbl);
#endif
if ((temp_dbl > FLT_MAX) || (temp_dbl <= 0)) { /* Overflow error */
t = aa_table[ES](lexeme);
return t;
}
}
else {
for (i = 0; i < strlen(lexeme); ++i) {
if (lexeme[i] == '.') {
if (lexeme[i + 1] == '\0') {
strncpy(substr, lexeme, i);
substr[i] = '\0';
temp_dbl = strtof(substr, NULL);
check = TRUE;
}
else break;
}
}
} /* strtof() returns 0 if the value is out of range) */
if (check != TRUE)
temp_dbl = strtof(lexeme, NULL);
t.attribute.flt_value = (float)temp_dbl;
#ifdef DEBUG
printf("Lexeme: '%s' | FLT value: %f | CHECK = %d\n", substr, temp_dbl, check);
#endif
if ((temp_dbl > FLT_MAX) || ((temp_dbl != 0) && (temp_dbl < FLT_MIN))) { /* Overflow error */
t = aa_table[ES](lexeme);
}
free(substr);
return t;
/*
THE FUNCTION MUST CONVERT THE LEXEME TO A FLOATING POINT VALUE,