From 9a95b5d24b2b2f5111e1862875d4136964a59548 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sat, 19 Oct 2013 20:11:56 +0200 Subject: Improvement: Replaced "priority" with TokenType * Made implementation more expressive by replacing the integer priority with an strictly typed enum called TokenType ** Made removal of character comparisons from tree construction and lexer possible * As a side effect distinct numbers had to be assigned to each token ** Operators of same priority do not have identical numbers anymore --- src/utils.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/utils.h') diff --git a/src/utils.h b/src/utils.h index f71c835..6e43605 100644 --- a/src/utils.h +++ b/src/utils.h @@ -8,7 +8,18 @@ namespace SimpleParser { -int8_t getPriority(char); +enum class TokenType : int8_t { + OPERATOR_PLUS = 10, + OPERATOR_MINUS = 11, + OPERATOR_DIVIDE = 20, + OPERATOR_MULTIPLY = 21, + OPERATOR_POWER = 30, + PARENTHESES_OPEN = 90, + PARENTHESES_CLOSE = 91, + VALUE_NUMBER = -1, +}; + +TokenType getTokenType(char); std::vector lexer(std::string); } -- cgit v1.2.3