/
ExpressionParser.h
78 lines (59 loc) · 1.55 KB
/
ExpressionParser.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright 2006-2009 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
* John Scipione <jscipione@gmail.com>
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
*/
#ifndef EXPRESSION_PARSER_H
#define EXPRESSION_PARSER_H
#include <String.h>
class ParseException {
public:
ParseException(const char* message, int32 position)
: message(message),
position(position)
{
}
ParseException(const ParseException& other)
: message(other.message),
position(other.position)
{
}
BString message;
int32 position;
};
struct Function;
class MAPM;
class ExpressionParser {
public:
ExpressionParser();
~ExpressionParser();
bool DegreeMode();
void SetDegreeMode(bool degrees);
void SetSupportHexInput(bool enabled);
BString Evaluate(const char* expressionString);
int64 EvaluateToInt64(const char* expressionString);
double EvaluateToDouble(const char* expressionString);
status_t SetSeparators(BString decimal, BString group);
private:
struct Token;
class Tokenizer;
private:
MAPM _ParseBinary();
MAPM _ParseSum();
MAPM _ParseProduct();
MAPM _ParsePower();
MAPM _ParseUnary();
void _InitArguments(MAPM values[],
int32 argumentCount);
MAPM _ParseFunction(const Token& token);
MAPM _ParseAtom();
MAPM _ParseFactorial(MAPM value);
void _EatToken(int32 type);
Tokenizer* fTokenizer;
bool fDegreeMode;
};
#endif // EXPRESSION_PARSER_H