adding utils with enum_print
This commit is contained in:
16
src/parser.c
16
src/parser.c
@@ -129,7 +129,7 @@ static double get_coefficient(token *tokens, int i, int *token_count)
|
||||
return coefficient;
|
||||
}
|
||||
|
||||
static double get_exponent(token *tokens, int i, int *token_count)
|
||||
static int get_exponent(token *tokens, int i, int *token_count)
|
||||
{
|
||||
// first reach VARIABLE
|
||||
if (tokens[i].type == TOKEN_VARIABLE)
|
||||
@@ -177,7 +177,7 @@ static double get_exponent(token *tokens, int i, int *token_count)
|
||||
stop_errors(ERROR_TOKEN_POSITION, "at exponent place, we should have an int, but instead got : '%c' (token number %i)", tokens[i].value_char, i);
|
||||
}
|
||||
|
||||
return tokens[i].value_double;
|
||||
return tokens[i].value_int;
|
||||
}
|
||||
|
||||
static void check_variables(token *tokens)
|
||||
@@ -232,16 +232,22 @@ int parse(token *tokens, term *terms, int terms_count_max)
|
||||
terms[terms_count].position = term_position;
|
||||
|
||||
// sign
|
||||
terms[terms_count].sign = get_sign(tokens, i, &token_count);
|
||||
term_sign ret_sign = get_sign(tokens, i, &token_count);
|
||||
terms[terms_count].sign = ret_sign;
|
||||
i += token_count;
|
||||
ft_printf("term[%i] get_sign: (%i)[%s], token_count: [%d]\n", terms_count, ret_sign, term_sign_to_str(ret_sign), token_count);
|
||||
|
||||
// coefficient
|
||||
terms[terms_count].coefficient = get_coefficient(tokens, i, &token_count);
|
||||
double ret_coefficient = get_coefficient(tokens, i, &token_count);
|
||||
terms[terms_count].coefficient = ret_coefficient;
|
||||
i += token_count;
|
||||
printf("term[%i] get_coefficient: [%g], token_count: [%d]\n", terms_count, ret_coefficient, token_count);
|
||||
|
||||
// exponent
|
||||
terms[terms_count].exponent = get_exponent(tokens, i, &token_count);
|
||||
int ret_exponent = get_exponent(tokens, i, &token_count);
|
||||
terms[terms_count].exponent = ret_exponent;
|
||||
i += token_count;
|
||||
ft_printf("term[%i] get_exponent: [%i], token_count: [%d]\n", terms_count, ret_exponent, token_count);
|
||||
|
||||
i++;
|
||||
terms_count++;
|
||||
|
||||
Reference in New Issue
Block a user