Parser: Exponentiation is right associative

This commit is contained in:
hrkrshnn
2020-10-13 16:38:37 +02:00
parent 0ea4bdafcd
commit 13e7012e1e
7 changed files with 101 additions and 40 deletions
-10
View File
@@ -115,16 +115,6 @@ std::string friendlyName(Token tok)
return std::string(ret);
}
#define T(name, string, precedence) precedence,
int precedence(Token tok)
{
int8_t const static precs[TokenTraits::count()] =
{
TOKEN_LIST(T, T)
};
return precs[static_cast<size_t>(tok)];
}
#undef T
int parseSize(string::const_iterator _begin, string::const_iterator _end)
{
+22 -1
View File
@@ -337,7 +337,28 @@ namespace TokenTraits
// @returns the precedence > 0 for binary and compare
// operators; returns 0 otherwise.
int precedence(Token tok);
constexpr int precedence(Token tok)
{
int8_t constexpr precs[TokenTraits::count()] =
{
#define T(name, string, precedence) precedence,
TOKEN_LIST(T, T)
#undef T
};
return precs[static_cast<size_t>(tok)];
}
constexpr bool hasExpHighestPrecedence()
{
constexpr int expPrecedence = TokenTraits::precedence(Token::Exp);
static_assert(expPrecedence == 14, "Exp precedence changed.");
#define T(name, string, precedence) ((Token::name == Token::Exp) || precedence < expPrecedence) &&
return
TOKEN_LIST(T, T)
true;
#undef T
}
std::tuple<Token, unsigned int, unsigned int> fromIdentifierOrKeyword(std::string const& _literal);