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

@ -112,7 +112,7 @@ Token malar_next_token(Buffer * sc_buf)
while (1) { /* endless loop broken by token returns; it will generate a warning */
/* Get symbol from buffer */
/* Get symbol from buffer */
c = b_getc(sc_buf);
switch (c) {
@ -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;
}
return t;
case '.':
b_setmark(sc_buf, b_getcoffset(sc_buf)); /* Set mark before continuing (AND|OR case) */
c = b_getc(sc_buf);
@ -300,7 +303,7 @@ Token malar_next_token(Buffer * sc_buf)
Version: 0.0.1
Called functions: char_class, assert, printf, as_table
Parameters:
- int state: the starting point for the transition table lookup
- int state: the starting point for the transition table lookup
- char c: the input character for table lookup
- int *accept: pointer to the accepting state of the scanner
Return values: int (the next state value of the scanner)
@ -332,7 +335,7 @@ int get_next_state(int state, char c, int *accept)
Version: 0.0.1
Called functions: N/A
Parameters:
- char c: the input character to be matched in the transition table
- char c: the input character to be matched in the transition table
Return values: int (the value representing the column in the transition table)
*/
int char_class(char c)
@ -370,7 +373,7 @@ REPLACE XX WITH THE CORRESPONDING ACCEPTING STATE NUMBER
Version: 0.0.1
Called functions: iskeyword, calloc, aa_table[], strlen, strncpy, free
Parameters:
- char* lexeme: the string pattern matched by the FA
- char* lexeme: the string pattern matched by the FA
Return values: Token
*/
Token aa_func02(char lexeme[]) {
@ -441,7 +444,7 @@ REPLACE XX WITH THE CORRESPONDING ACCEPTING STATE NUMBER
Version: 0.0.1
Called functions: calloc, aa_table[], strlen, strncpy, free
Parameters:
- char* lexeme: the string pattern matched by the FA
- char* lexeme: the string pattern matched by the FA
Return values: Token
*/
Token aa_func03(char lexeme[]) {
@ -483,7 +486,7 @@ Token aa_func03(char lexeme[]) {
Version: 0.0.1
Called functions: atol, aa_table[]
Parameters:
- char* lexeme: the string pattern matched by the FA
- char* lexeme: the string pattern matched by the FA
Return values: Token
*/
Token aa_func05(char lexeme[]) {
@ -516,28 +519,44 @@ err_lex C-type string. */
Version: 0.0.1
Called functions: strtof, aa_table[]
Parameters:
- char* lexeme: the string pattern matched by the FA
- char* lexeme: the string pattern matched by the FA
Return values: Token
*/
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,
@ -559,7 +578,7 @@ err_lex C-type string. */
Version: 0.0.1
Called functions: strlen, aa_table[], atool
Parameters:
- char* lexeme: the string pattern matched by the FA
- char* lexeme: the string pattern matched by the FA
Return values: Token
*/
Token aa_func10(char lexeme[]) {
@ -605,7 +624,7 @@ err_lex C-type string.
Version: 0.0.1
Called functions: aa_table[]
Parameters:
- char* lexeme: the string pattern matched by the FA
- char* lexeme: the string pattern matched by the FA
Return values: Token
*/
Token aa_func12(char lexeme[]) {
@ -623,7 +642,7 @@ Token aa_func12(char lexeme[]) {
Version: 0.0.1
Called functions: strlen, aa_table[]
Parameters:
- char* lexeme: the string pattern matched by the FA
- char* lexeme: the string pattern matched by the FA
Return values: Token
*/
Token aa_func13(char lexeme[]) {
@ -651,7 +670,7 @@ Token aa_func13(char lexeme[]) {
Version: 0.0.1
Called functions: N/A
Parameters:
- char* lexeme: the string pattern to convert
- char* lexeme: the string pattern to convert
Return values: long (integer representation of the octal string)
*/
long atool(char * lexeme) {
@ -671,7 +690,7 @@ FOR EXAMPLE*/
Version: 0.0.1
Called functions: N/A
Parameters:
- char* lexeme: the string pattern to look up in kw_table
- char* lexeme: the string pattern to look up in kw_table
Return values: int -1 (could not find a match),
int [1 - KW_SIZE] index location of the matching keyword
*/