fix number tokens and limits
This commit is contained in:
24
src/parser.c
24
src/parser.c
@@ -16,30 +16,44 @@
|
||||
static e_term_sign get_sign(s_token *tokens, int i, int *token_count)
|
||||
{
|
||||
*token_count = 0;
|
||||
int j;
|
||||
e_term_sign ret_sign;
|
||||
|
||||
// default to '+'
|
||||
ret_sign = TERM_PLUS;
|
||||
|
||||
// sign
|
||||
if (tokens[i].tag == TOKEN_SIGN)
|
||||
{
|
||||
*token_count = 1;
|
||||
// we cna have two signs in a row, like "3 - -2" or "3 - +2"
|
||||
j = 0;
|
||||
while (j < 2)
|
||||
{
|
||||
if (tokens[i + j].tag != TOKEN_SIGN)
|
||||
break;
|
||||
if (tokens[i + j].type == TOKEN_SIGN_MINUS)
|
||||
ret_sign = (ret_sign == TERM_PLUS) ? TERM_MINUS : TERM_PLUS;
|
||||
*token_count += 1;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
else if (i == 0)
|
||||
{
|
||||
// if most left term, the sign can be ommited for a '+' sign in front of a number or variable
|
||||
*token_count = 0;
|
||||
return TERM_PLUS;
|
||||
ret_sign = TERM_PLUS;
|
||||
}
|
||||
else if (tokens[i - 1].type == TOKEN_EQUAL)
|
||||
{
|
||||
// if first token after 'equal', the sign can be ommited for a '+' sign in front of a number or variable
|
||||
*token_count = 0;
|
||||
return TERM_PLUS;
|
||||
ret_sign = TERM_PLUS;
|
||||
}
|
||||
else
|
||||
{
|
||||
stop_errors("at begining of term, we should have a token 'sign', not '%s' (token[%i])", token_type_to_str(tokens[i].type), i);
|
||||
}
|
||||
|
||||
return tokens[i].type == TOKEN_SIGN_PLUS ? TERM_PLUS : TERM_MINUS;
|
||||
return ret_sign;
|
||||
}
|
||||
|
||||
static double get_double_value(s_token token)
|
||||
|
||||
Reference in New Issue
Block a user