diff options
Diffstat (limited to '')
-rw-r--r-- | src/formula.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/formula.h b/src/formula.h new file mode 100644 index 0000000..1eccd36 --- /dev/null +++ b/src/formula.h | |||
@@ -0,0 +1,62 @@ | |||
1 | #ifndef FORMULA_H | ||
2 | #define FORMULA_H | ||
3 | |||
4 | #include <stdint.h> | ||
5 | |||
6 | #include <stack> | ||
7 | #include "sbuffer.h" | ||
8 | |||
9 | #include "exceptionbase.h" | ||
10 | |||
11 | subExceptionDecl( ParseException ); | ||
12 | |||
13 | /** | ||
14 | * | ||
15 | */ | ||
16 | class Formula | ||
17 | { | ||
18 | public: | ||
19 | Formula(); | ||
20 | virtual ~Formula(); | ||
21 | |||
22 | double run( const char *sFormula ); | ||
23 | |||
24 | private: | ||
25 | enum | ||
26 | { | ||
27 | symEOS, | ||
28 | symAdd, | ||
29 | symSubtract, | ||
30 | symMultiply, | ||
31 | symDivide, | ||
32 | symOpenParen, | ||
33 | symCloseParen, | ||
34 | symNumber, | ||
35 | symVariable | ||
36 | }; | ||
37 | |||
38 | typedef struct Token | ||
39 | { | ||
40 | Token() {} | ||
41 | Token( uint8_t nSym ) : nSym( nSym ) { } | ||
42 | Token( uint8_t nSym, double dNum ) : nSym( nSym ) { val.num = dNum; } | ||
43 | uint8_t nSym; | ||
44 | union | ||
45 | { | ||
46 | double num; | ||
47 | } val; | ||
48 | } Token; | ||
49 | |||
50 | std::stack<Token> sToken; | ||
51 | Token tLook; | ||
52 | int nState; | ||
53 | SBuffer sBuf; | ||
54 | |||
55 | private: | ||
56 | void push(); | ||
57 | void state(); | ||
58 | Token nextToken(); | ||
59 | void printToken( Token &tok ); | ||
60 | }; | ||
61 | |||
62 | #endif | ||