changed subtypes for tags

This commit is contained in:
hugogogo
2026-05-02 10:25:25 +02:00
parent a250a170cb
commit 3977e6a6bb
4 changed files with 104 additions and 79 deletions

View File

@@ -11,14 +11,14 @@
TOKEN_EQUAL, // =
TOKEN_END // null (end of input)
1. VAR | NUM | ! POW | SIGN | ! FACTOR | ! EQUAL | END
NS | NUM_I | NUM_D | NS | SIGN_P | SIGN_M | ! FACTOR_MUL | ! FACTOR_DIV | NS | NS
1. VAR | NUMBER_I | NUMBER_D | ! POW | SIGN_P | SIGN_M | ! FACTOR_MUL | ! FACTOR_DIV | ! EQUAL | END
NT | NUMBER | NT | SIGN | ! FACTOR | NT | NT
2. VAR | NUM | ! POW | ! SIGN | ! FACTOR | ! EQUAL | END
NS | NUM_I | NUM_D | NS | ! SIGN_P | ! SIGN_M | ! FACTOR_MUL | ! FACTOR_DIV | NS | NS
2. VAR | NUMBER_I | NUMBER_D | ! POW | ! SIGN_P | ! SIGN_M | ! FACTOR_MUL | ! FACTOR_DIV | ! EQUAL | END
NT | NUMBER | NT | ! SIGN | ! FACTOR | NT | NT
3. VAR | NUM | ! POW | SIGN | FACTOR | ! EQUAL | END
NS | NUM_I | NUM_D | NS | SIGN_P | SIGN_M | FACTOR_MUL | ! FACTOR_DIV | NS | NS
3. VAR | NUMBER_I | NUMBER_D | ! POW | SIGN_P | SIGN_M | FACTOR_MUL | FACTOR_DIV | EQUAL | END
NT | NUMBER | NT | SIGN | FACTOR | NT | NT
term_position position;
term_sign sign;
@@ -34,7 +34,7 @@ static term_sign get_sign(token *tokens, int i, int *token_count)
{
stop_errors(ERROR_TOKEN_POSITION, "at begining of term, we should not have a power token : " + tokens[i].value_char);
}
if (tokens[i].type == TOKEN_FACTOR)
if (tokens[i].tag == TOKEN_FACTOR)
{
stop_errors(ERROR_TOKEN_POSITION, "at begining of term, we should not have a factor token : " + tokens[i].value_char);
}
@@ -44,7 +44,7 @@ static term_sign get_sign(token *tokens, int i, int *token_count)
}
// sign
if (tokens[i].type == TOKEN_SIGN)
if (tokens[i].tag == TOKEN_SIGN)
{
*token_count = 1;
return tokens[i].value_char;
@@ -74,7 +74,7 @@ static double get_coefficient(token *tokens, int i, int *token_count)
{
stop_errors(ERROR_TOKEN_POSITION, "at coefficient place, we should not have a power token : " + tokens[i].value_char);
}
if (tokens[i].type == TOKEN_FACTOR)
if (tokens[i].tag == TOKEN_FACTOR)
{
stop_errors(ERROR_TOKEN_POSITION, "at coefficient place, we should not have a factor token : " + tokens[i].value_char);
}
@@ -82,7 +82,7 @@ static double get_coefficient(token *tokens, int i, int *token_count)
{
stop_errors(ERROR_TOKEN_POSITION, "at coefficient place, we should not have an equal token : " + tokens[i].value_char);
}
if (tokens[i].type == TOKEN_SIGN)
if (tokens[i].tag == TOKEN_SIGN)
{
stop_errors(ERROR_TOKEN_POSITION, "at coefficient place, we should not have a sign token : " + tokens[i].value_char);
}
@@ -95,24 +95,24 @@ static double get_coefficient(token *tokens, int i, int *token_count)
}
// if coefficient tokens
if (tokens[i].type == TOKEN_NUMBER)
if (tokens[i].tag == TOKEN_NUMBER)
{
(*token_count)++;
coefficient = tokens[i].value_double;
}
// detect more coefficients, like "3 * 2 / 5" etc
i++;
while (tokens[i].type == TOKEN_FACTOR)
while (tokens[i].tag == TOKEN_FACTOR)
{
i++;
if (tokens[i].type == TOKEN_NUMBER)
if (tokens[i].tag == TOKEN_NUMBER)
{
*token_count += 2;
if (tokens[i - 1].subtype == TOKEN_FACTOR_MULTIPLICATION)
if (tokens[i - 1].type == TOKEN_FACTOR_MULT)
{
coefficient *= tokens[i].value_double;
}
else if (tokens[i - 1].subtype == TOKEN_FACTOR_DIVISION)
else if (tokens[i - 1].type == TOKEN_FACTOR_DIV)
{
coefficient /= tokens[i].value_double;
}