SavvyUI C++ UI Library
Loading...
Searching...
No Matches
ExpressionEvaluator.h
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <string>
5#include <algorithm>
6#include <unordered_map>
7#include <cwctype>
8#include <cmath>
9#include <stdexcept>
10
12
13 std::wstring expression;
14 std::unordered_map<std::wstring, double> variables;
15 size_t pos;
16 std::wstring token;
17 std::wstring lastError;
18 enum class TokenType { NONE, NUMBER, VARIABLE, OPERATOR, LPAREN, RPAREN, END } tokenType;
19
20public:
21
22 bool compile(const std::wstring& expr);
23 bool evaluate(const std::unordered_map<std::wstring, double>& vars, double& result);
24 std::wstring getLastError();
25
26private:
27
28 void skipWhitespace();
29
30 std::wstring toLowerCase(const std::wstring& input);
31
32 bool nextToken();
33 bool expect(TokenType expectedType, const std::wstring& expectedToken = L"");
34 bool parseExpression(double& result);
35 bool parseTerm(double& result);
36 bool parseFactor(double& result);
37 bool parsePrimary(double& result);
38};
Definition ExpressionEvaluator.h:11
bool compile(const std::wstring &expr)
bool evaluate(const std::unordered_map< std::wstring, double > &vars, double &result)
std::wstring getLastError()