wip parsing and error
This commit is contained in:
@@ -63,64 +63,19 @@ int main(int ac, char **av)
|
||||
|
||||
input = av[1];
|
||||
remove_spaces(input);
|
||||
arg_len = ft_strlen(input);
|
||||
|
||||
ft_putstr("-> input without space : "); // debug
|
||||
ft_putstr(input); // debug
|
||||
ft_putchar('\n'); // debug
|
||||
ft_putstr("-> arg_len : "); // debug
|
||||
ft_putnbr(arg_len); // debug
|
||||
ft_putchar('\n'); // debug
|
||||
arg_len = ft_strlen(input) + 1; // +1 for last END token
|
||||
|
||||
token tokens[arg_len];
|
||||
// by security, make the last token as END (even though the real END token will likely be lower)
|
||||
tokens[arg_len - 1].type = TOKEN_END;
|
||||
tokens[arg_len - 1].tag = TOKEN_NO_TAG;
|
||||
tokens[arg_len - 1].value_char = '\0';
|
||||
// lexerize
|
||||
int tokens_count = lexerize(input, tokens);
|
||||
|
||||
ft_putstr("-> tokens_count : "); // debug
|
||||
ft_putnbr(tokens_count); // debug
|
||||
ft_putchar('\n'); // debug
|
||||
|
||||
// tmp debug output
|
||||
ft_putchar('\n'); // debug
|
||||
i = 0;
|
||||
while (tokens[i].type != TOKEN_END)
|
||||
if (tokens_count == 0)
|
||||
{
|
||||
ft_printf("token %2i - type : ", i);
|
||||
|
||||
if (tokens[i].type == TOKEN_VARIABLE)
|
||||
ft_printf("%20s", "TOKEN_VARIABLE");
|
||||
else if (tokens[i].type == TOKEN_NUMBER_INT)
|
||||
ft_printf("%20s", "TOKEN_NUMBER_INT");
|
||||
else if (tokens[i].type == TOKEN_NUMBER_DOUBLE)
|
||||
ft_printf("%20s", "TOKEN_NUMBER_DOUBLE");
|
||||
else if (tokens[i].type == TOKEN_POWER)
|
||||
ft_printf("%20s", "TOKEN_POWER");
|
||||
else if (tokens[i].type == TOKEN_SIGN_PLUS)
|
||||
ft_printf("%20s", "TOKEN_SIGN_PLUS");
|
||||
else if (tokens[i].type == TOKEN_SIGN_MINUS)
|
||||
ft_printf("%20s", "TOKEN_SIGN_MINUS");
|
||||
else if (tokens[i].type == TOKEN_FACTOR_MULT)
|
||||
ft_printf("%20s", "TOKEN_FACTOR_MULT");
|
||||
else if (tokens[i].type == TOKEN_FACTOR_DIV)
|
||||
ft_printf("%20s", "TOKEN_FACTOR_DIV");
|
||||
else if (tokens[i].type == TOKEN_EQUAL)
|
||||
ft_printf("%20s", "TOKEN_EQUAL");
|
||||
else if (tokens[i].type == TOKEN_END)
|
||||
ft_printf("%20s", "TOKEN_END");
|
||||
|
||||
ft_putstr(" - value : ");
|
||||
|
||||
if (tokens[i].tag == TOKEN_NUMBER)
|
||||
{
|
||||
printf("%g\n", tokens[i].value_double);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_printf("%c\n", tokens[i].value_char);
|
||||
}
|
||||
i++;
|
||||
stop_errors(ERROR_BASE, tokens, input, "test error");
|
||||
}
|
||||
ft_putchar('\n'); // debug
|
||||
// END tmp debug output
|
||||
|
||||
terms_count_prediction = count_any_of(input, "-+=") + 2; // +1 for first term that can have no leading '+', +1 for last term == NULL
|
||||
|
||||
|
||||
Reference in New Issue
Block a user