Skip to content

Commit

Permalink
Rename precedence functions to fix gap
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake-Madden committed Feb 25, 2024
1 parent 26a417c commit 63af80b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
27 changes: 14 additions & 13 deletions tinyexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,27 +1251,28 @@ te_expr* te_parser::expr_level2(te_parser::state* theState)
{
/* <expr> = <term> {(logic operations) <term>} */
// next to lowest in precedence...
te_expr* ret = expr_level7(theState);
te_expr* ret = expr_level6(theState);

while (theState->m_type == te_parser::state::token_type::TOK_INFIX &&
is_function2(theState->m_value) &&
get_function2(theState->m_value) == te_builtins::te_and)
{
const te_fun2 func = get_function2(theState->m_value);
next_token(theState);
ret = new_expr(TE_PURE, func, { ret, expr_level7(theState) });
ret = new_expr(TE_PURE, func, { ret, expr_level6(theState) });
}

return ret;
}

// levels 3-6 open for possible future extensions
// levels 3-5 open for possible future extensions
// of bitwise OR, XOR, and AND
//--------------------------------------------------
te_expr* te_parser::expr_level7(te_parser::state* theState)
te_expr* te_parser::expr_level6(te_parser::state* theState)
{
/* <expr> = <term> {(logic operations) <term>} */
// next to lowest in precedence...
te_expr* ret = expr_level8(theState);
te_expr* ret = expr_level7(theState);

while (theState->m_type == te_parser::state::token_type::TOK_INFIX &&
is_function2(theState->m_value) &&
Expand All @@ -1280,17 +1281,17 @@ te_expr* te_parser::expr_level7(te_parser::state* theState)
{
const te_fun2 func = get_function2(theState->m_value);
next_token(theState);
ret = new_expr(TE_PURE, func, { ret, expr_level8(theState) });
ret = new_expr(TE_PURE, func, { ret, expr_level7(theState) });
}

return ret;
}

//--------------------------------------------------
te_expr* te_parser::expr_level8(te_parser::state* theState)
te_expr* te_parser::expr_level7(te_parser::state* theState)
{
/* <expr> = <term> {(comparison operators) <term>} */
te_expr* ret = expr_level9(theState);
te_expr* ret = expr_level8(theState);

while (theState->m_type == te_parser::state::token_type::TOK_INFIX &&
is_function2(theState->m_value) &&
Expand All @@ -1301,17 +1302,17 @@ te_expr* te_parser::expr_level8(te_parser::state* theState)
{
const te_fun2 func = get_function2(theState->m_value);
next_token(theState);
ret = new_expr(TE_PURE, func, { ret, expr_level9(theState) });
ret = new_expr(TE_PURE, func, { ret, expr_level8(theState) });
}

return ret;
}

//--------------------------------------------------
te_expr* te_parser::expr_level9(te_parser::state* theState)
te_expr* te_parser::expr_level8(te_parser::state* theState)
{
/* <expr> = <term> {("<<" | ">>") <term>} */
te_expr* ret = expr_level10(theState);
te_expr* ret = expr_level9(theState);

while (theState->m_type == te_parser::state::token_type::TOK_INFIX &&
is_function2(theState->m_value) &&
Expand All @@ -1320,14 +1321,14 @@ te_expr* te_parser::expr_level9(te_parser::state* theState)
{
const te_fun2 func = get_function2(theState->m_value);
next_token(theState);
ret = new_expr(TE_PURE, func, { ret, expr_level10(theState) });
ret = new_expr(TE_PURE, func, { ret, expr_level9(theState) });
}

return ret;
}

//--------------------------------------------------
te_expr* te_parser::expr_level10(te_parser::state* theState)
te_expr* te_parser::expr_level9(te_parser::state* theState)
{
/* <expr> = <term> {("+" | "-") <term>} */
te_expr* ret = term(theState);
Expand Down
7 changes: 4 additions & 3 deletions tinyexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1032,16 +1032,17 @@ class te_parser
te_expr* expr_level1(state* theState);
[[nodiscard]]
te_expr* expr_level2(state* theState);
// levels 3-6 open for possible future extensions
// levels 3-5 open for possible future extensions
// of bitwise OR, XOR, and AND
[[nodiscard]]
te_expr* expr_level6(state* theState);
[[nodiscard]]
te_expr* expr_level7(state* theState);
[[nodiscard]]
te_expr* expr_level8(state* theState);
[[nodiscard]]
te_expr* expr_level9(state* theState);
[[nodiscard]]
te_expr* expr_level10(state* theState);
[[nodiscard]]
te_expr* list(state* theState);

std::string m_expression;
Expand Down

0 comments on commit 63af80b

Please sign in to comment.