diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2007-02-17 16:31:55 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2007-02-17 16:31:55 +0000 |
| commit | 89eeeff54f0b3ce30be5b046fc3899fdeb5ebb40 (patch) | |
| tree | a4a8fc2e184df736f61c1dea1e8627dd3667b071 /src/formula.h | |
| parent | 27c626112a7114f9bdc4f7739f9ec05ae9fcbee1 (diff) | |
| download | libbu++-89eeeff54f0b3ce30be5b046fc3899fdeb5ebb40.tar.gz libbu++-89eeeff54f0b3ce30be5b046fc3899fdeb5ebb40.tar.bz2 libbu++-89eeeff54f0b3ce30be5b046fc3899fdeb5ebb40.tar.xz libbu++-89eeeff54f0b3ce30be5b046fc3899fdeb5ebb40.zip | |
Tweaked the stream classes, added an example, and the begining of a formula
parser.
Diffstat (limited to 'src/formula.h')
| -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 | ||
