From cf2aa4c9d70fc8ed658c213b2c46bb48ee10e6f7 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sun, 20 Oct 2013 00:10:54 +0200 Subject: Implemented constant identifier functionality * SimpleParser optionally acceps a pointer to an ConstantMap containing string keys mapping to values * Constants are handled in their own ConstantNode class derived from the standard Node class * Operator precedence is now determined separated from the TokenType using a new PrecedenceLevel enum ** Conversion between tokens and their PrecedenceLevel is possible using the new utility function getPrecedence * Added additional test cases for constant identifier resolutions --- src/nodes.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/nodes.h') diff --git a/src/nodes.h b/src/nodes.h index 6783f3d..170b88f 100644 --- a/src/nodes.h +++ b/src/nodes.h @@ -1,11 +1,13 @@ #ifndef PARSER_SRC_NODES_H_ #define PARSER_SRC_NODES_H_ +#include #include namespace SimpleParser { -enum class TokenType : int8_t; +enum class TokenType; +typedef std::map ConstantMap; enum class NodeType { OPERAND, @@ -53,7 +55,7 @@ class OperandNode: public Node { class ConstantNode: public Node { public: - explicit ConstantNode(std::string); + explicit ConstantNode(std::string, const ConstantMap*); virtual double solve(); virtual NodeType getType(); @@ -61,6 +63,7 @@ class ConstantNode: public Node { private: std::string identifier_; + const ConstantMap* constants_; }; } -- cgit v1.2.3