@@ -9,8 +9,8 @@ using namespace mathS;
9
9
#define LIST_ERROR_CHECK (x ) if (x.size()>0 && x[0 ]->GetType () == MathObject::ERROR) return x[0]
10
10
11
11
// 解析表达式
12
- Ptr<MathObject> Parser ::Parse() {
13
-
12
+ Ptr<MathObject> mathS ::Parse(const std::string & c ) {
13
+ Lexer lexer (c);
14
14
std::vector<Token> tokens;
15
15
Token tok;
16
16
while (true ) {
@@ -29,7 +29,7 @@ Ptr<MathObject> Parser::Parse() {
29
29
return obj;
30
30
}
31
31
32
- short Parser ::level (const std::string &c) {
32
+ short mathS ::level (const std::string &c) {
33
33
SWITCH (c.c_str ()) {
34
34
CASE (c, " (" ) return MathObject::LEVEL_FUNCTION;
35
35
CASE (c, " <<" ) return MathObject::LEVEL_FUNCOPERATOR;
@@ -59,12 +59,12 @@ short Parser::level(const std::string &c) {
59
59
}
60
60
61
61
62
- Ptr<MathObject> mathS::Parser:: parseObject (const std::vector<Token>& tokens, const int start, int & i)
62
+ Ptr<MathObject> mathS::parseObject (const std::vector<Token>& tokens, const int start, int & i)
63
63
{
64
64
i = start;
65
65
return parseCompare (tokens, i, i);
66
66
}
67
- Ptr<MathObject> mathS::Parser:: parseAtom (const std::vector<Token>& tokens, const int start, int & i)
67
+ Ptr<MathObject> mathS::parseAtom (const std::vector<Token>& tokens, const int start, int & i)
68
68
{
69
69
Ptr<MathObject> obj;
70
70
i = start;
@@ -107,7 +107,7 @@ Ptr<MathObject> mathS::Parser::parseAtom(const std::vector<Token>& tokens, const
107
107
}
108
108
109
109
110
- Ptr<MathObject> mathS::Parser:: parseFunction (const std::vector<Token>& tokens, const int start, int & i)
110
+ Ptr<MathObject> mathS::parseFunction (const std::vector<Token>& tokens, const int start, int & i)
111
111
{
112
112
i = start;
113
113
@@ -180,7 +180,7 @@ Ptr<MathObject> mathS::Parser::parseFunction(const std::vector<Token>& tokens, c
180
180
181
181
}
182
182
183
- Ptr<MathObject> mathS::Parser:: parseLocate (const std::vector<Token>& tokens, const int start, int & i)
183
+ Ptr<MathObject> mathS::parseLocate (const std::vector<Token>& tokens, const int start, int & i)
184
184
{
185
185
i = start;
186
186
auto obj = parseFunction (tokens, start, i);
@@ -206,7 +206,7 @@ Ptr<MathObject> mathS::Parser::parseLocate(const std::vector<Token>& tokens, con
206
206
207
207
}
208
208
209
- Ptr<MathObject> mathS::Parser:: parsePower (const std::vector<Token>& tokens, const int start, int & i)
209
+ Ptr<MathObject> mathS::parsePower (const std::vector<Token>& tokens, const int start, int & i)
210
210
{
211
211
i = start;
212
212
auto b = parseLocate (tokens, start, i);
@@ -224,7 +224,7 @@ Ptr<MathObject> mathS::Parser::parsePower(const std::vector<Token>& tokens, cons
224
224
return pw;
225
225
}
226
226
227
- Ptr<MathObject> mathS::Parser:: parseItem (const std::vector<Token>& tokens, const int start, int & i)
227
+ Ptr<MathObject> mathS::parseItem (const std::vector<Token>& tokens, const int start, int & i)
228
228
{
229
229
i = start;
230
230
auto fct = parsePower (tokens, start, i);
@@ -261,7 +261,7 @@ Ptr<MathObject> mathS::Parser::parseItem(const std::vector<Token>& tokens, const
261
261
262
262
}
263
263
264
- Ptr<MathObject> mathS::Parser:: parsePolynomial (const std::vector<Token>& tokens, const int start, int & i)
264
+ Ptr<MathObject> mathS::parsePolynomial (const std::vector<Token>& tokens, const int start, int & i)
265
265
{
266
266
i = start;
267
267
if (i >= tokens.size () || level (tokens[i].text ) > MathObject::LEVEL_POLYNOMIAL) {
@@ -301,7 +301,7 @@ Ptr<MathObject> mathS::Parser::parsePolynomial(const std::vector<Token>& tokens,
301
301
}
302
302
}
303
303
304
- Ptr<MathObject> mathS::Parser:: parseMap (const std::vector<Token>& tokens, const int start, int & i)
304
+ Ptr<MathObject> mathS::parseMap (const std::vector<Token>& tokens, const int start, int & i)
305
305
{
306
306
i = start;
307
307
auto a = parsePolynomial (tokens, i, i);
@@ -317,7 +317,7 @@ Ptr<MathObject> mathS::Parser::parseMap(const std::vector<Token>& tokens, const
317
317
return mp;
318
318
}
319
319
320
- Ptr<MathObject> mathS::Parser:: parseCompare (const std::vector<Token>& tokens, const int start, int & i)
320
+ Ptr<MathObject> mathS::parseCompare (const std::vector<Token>& tokens, const int start, int & i)
321
321
{
322
322
i = start;
323
323
auto a = parseMap (tokens, i, i);
@@ -335,7 +335,7 @@ Ptr<MathObject> mathS::Parser::parseCompare(const std::vector<Token>& tokens, co
335
335
}
336
336
337
337
338
- std::vector<Ptr<MathObject>> mathS::Parser:: parseList (const std::vector<Token>& tokens, const int start, int & i)
338
+ std::vector<Ptr<MathObject>> mathS::parseList (const std::vector<Token>& tokens, const int start, int & i)
339
339
{
340
340
i = start;
341
341
if (i >= tokens.size () || level (tokens[i].text ) > MathObject::LEVEL_LIST)
@@ -358,3 +358,4 @@ std::vector<Ptr<MathObject>> mathS::Parser::parseList(const std::vector<Token>&
358
358
}
359
359
}
360
360
}
361
+
0 commit comments