-
Notifications
You must be signed in to change notification settings - Fork 1
/
Token.h
45 lines (39 loc) · 1.25 KB
/
Token.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// Created by colors_wind on 2020/8/24.
//
#ifndef ALGORIMATRIX_TOKEN_H
#define ALGORIMATRIX_TOKEN_H
#include <iostream>
#include "Matrix.h"
using std::string;
using std::ostream;
const static char OPERATORS[] = {'+', '-', '*', '/', '='};
const static char DELIMITERS[] = {'(', ')', '[', ']', ',', ';'};
const static string BLACKS = {' ', '\r', '\n', '\f'};
enum TokenType {VARIABLE, NUMBER, FUNCTION, OPERATOR, DELIMITER, END};
class Token {
protected:
TokenType m_type;
void* m_value;
string m_origin;
public:
explicit Token(TokenType type, const string &origin="\0");
Token & operator=(const Token & token);
Token(TokenType type, double d, const string &origin);
Token(TokenType type, char c, const string &origin);
Token(TokenType type, string str, const string &origin);
Token(TokenType type, void* p, const string &origin);
~Token();
Token(const Token & token);
string asString() const;
char asChar() const;
double asNumber() const;
string toString() const;
bool isEquls(char c) const;
TokenType getType() const;
void* copyValue() const;
Func asFunction() const;
const string &getRawText() const;
Token(TokenType type, Func p, const string &origin);
};
#endif //ALGORIMATRIX_TOKEN_H