📄 calcengine.h
字号:
#ifndef CALCENGINE_H
#define CALCENGINE_H
#include <string>
#include <sstream>
#include <map>
#include "function.h"
class CalculatorEngine {
public:
typedef Function::RDState RDState;
typedef std::map<std::string, ValueType> MapType;
typedef ValueType (Function::*UnaryFunction) (const ValueType&);
typedef std::map<std::string, UnaryFunction> FunctionMapType;
enum Token {
NAME, NUMBER, PRINT=';', END,
PLUS='+', MINUS='-', MUL='*', DIV='/', MOD='%',
POW='^', ASSIGN='=', LP='(', RP=')',
};
CalculatorEngine();
void setRDState(RDState s);
void setExpression(const std::string& expr);
ValueType calculate();
void pushIdentifier(const std::string& name, const ValueType& value);
static void buildFunctionTable();
private:
void getToken();
bool isFunction() const;
void checkParenthesis();
// parser methods
ValueType expr(bool);
ValueType term1(bool);
ValueType term2(bool);
ValueType prim(bool);
ValueType unaryFunction();
private:
Token __token;
ValueType __number;
std::string __string;
MapType __table;
Function __func;
std::stringstream __inStream;
static FunctionMapType __funcTable;
};
#endif // CALCENGINE_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -