using double everywhere
This commit is contained in:
51
src/parser.c
51
src/parser.c
@@ -17,11 +17,7 @@
|
||||
term_position position;
|
||||
term_sign sign;
|
||||
coefficient_type coefficient_type;
|
||||
union
|
||||
{
|
||||
int coefficient_int;
|
||||
double coefficient_double;
|
||||
};
|
||||
int coefficient;
|
||||
int exponent;
|
||||
*/
|
||||
|
||||
@@ -32,10 +28,11 @@ static term_sign get_sign(token *tokens, int *token_count)
|
||||
return '+'; // placeholder
|
||||
}
|
||||
|
||||
static void get_coefficient(token *tokens, int *token_count, coefficient_type *coefficient_type, int *coefficient_int, double *coefficient_double)
|
||||
static double get_coefficient(token *tokens, int *token_count)
|
||||
{
|
||||
if (tokens && coefficient_type && coefficient_double && coefficient_int) // placeholder
|
||||
*token_count = 1; // placeholder
|
||||
if (tokens) // placeholder
|
||||
*token_count = 1; // placeholder
|
||||
return 1.0; // placeholder
|
||||
}
|
||||
|
||||
static int get_exponent(token *tokens, int *token_count)
|
||||
@@ -45,7 +42,7 @@ static int get_exponent(token *tokens, int *token_count)
|
||||
return 1; // placeholder
|
||||
}
|
||||
|
||||
int parse(token *tokens, term *terms)
|
||||
int parse(token *tokens, term *terms, int terms_count_max)
|
||||
{
|
||||
/*
|
||||
if (tokens)
|
||||
@@ -56,22 +53,16 @@ int parse(token *tokens, term *terms)
|
||||
*/
|
||||
|
||||
int i;
|
||||
int term_count;
|
||||
int terms_count;
|
||||
int token_count;
|
||||
int coefficient_int;
|
||||
double coefficient_double;
|
||||
term_position term_position;
|
||||
coefficient_type coefficient_type;
|
||||
|
||||
term_count = 0;
|
||||
terms_count = 0;
|
||||
token_count = 0;
|
||||
i = 0;
|
||||
term_position = TERM_LEFT;
|
||||
while (tokens[i].type != TOKEN_END)
|
||||
while (tokens[i].type != TOKEN_END && terms_count < terms_count_max)
|
||||
{
|
||||
coefficient_int = 0;
|
||||
coefficient_double = 0.0;
|
||||
|
||||
if (tokens[i].type == TOKEN_EQUAL)
|
||||
{
|
||||
term_position = TERM_RIGHT;
|
||||
@@ -80,30 +71,28 @@ int parse(token *tokens, term *terms)
|
||||
}
|
||||
|
||||
// position
|
||||
terms[term_count].position = term_position;
|
||||
terms[terms_count].position = term_position;
|
||||
|
||||
// sign
|
||||
terms[term_count].sign = get_sign(&tokens[i], &token_count);
|
||||
terms[terms_count].sign = get_sign(&tokens[i], &token_count);
|
||||
i += token_count;
|
||||
|
||||
// coefficient
|
||||
get_coefficient(&tokens[i], &token_count, &coefficient_type, &coefficient_int, &coefficient_double);
|
||||
if (coefficient_type == TYPE_INT)
|
||||
{
|
||||
terms[term_count].coefficient_int = coefficient_int;
|
||||
}
|
||||
else if (coefficient_type == TYPE_DOUBLE)
|
||||
{
|
||||
terms[term_count].coefficient_double = coefficient_double;
|
||||
}
|
||||
terms[terms_count].coefficient = get_coefficient(&tokens[i], &token_count);
|
||||
i += token_count;
|
||||
|
||||
// exponent
|
||||
terms[term_count].exponent = get_exponent(&tokens[i], &token_count);
|
||||
terms[terms_count].exponent = get_exponent(&tokens[i], &token_count);
|
||||
i += token_count;
|
||||
|
||||
i++;
|
||||
terms_count++;
|
||||
}
|
||||
|
||||
return term_count;
|
||||
if (tokens[i].type != TOKEN_END && terms_count >= terms_count_max)
|
||||
{
|
||||
stop_errors(ERROR_PARSING, "deal with that later");
|
||||
}
|
||||
|
||||
return terms_count;
|
||||
}
|
||||
Reference in New Issue
Block a user