Files
ScienceCalculator/ScientificCalculator/Tokenizer.h
2025-07-01 16:04:35 +08:00

40 lines
763 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef TOKENIZER_H
#define TOKENIZER_H
#include<string>
#include<vector>
#include"Token.h"
using namespace std;
class Tokenizer {
public:
//主解析函数将表达式字符串转换为Token序列
vector<Token> run(const string& expr);
private:
string expression; //当前处理的表达式
size_t pos = 0; //当前指针位置
//工具函数:跳过空格字符
void skipWhitespace();
//读取一个完整数字(含小数、小数点、可能的一元负号)
Token readNumber();
//读取函数名(如sin、cos、log等)或变量名如x、y
Token readIdentifier();
//读取运算符或括号
Token readOperatorOrParen();
//判断当前位置是否处于一元符号的上下文
bool is_UMC(const vector<Token>& tokens);
//字符判断辅助函数
bool is_dig(char c)const;
bool is_let(char c)const;
bool is_OpeCh(char c)const;
};
#endif