forked from natikgadzhi/XNMaths
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ZExpParser.h
executable file
·126 lines (92 loc) · 2.02 KB
/
ZExpParser.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*************************************************************************************************
*
*
* MacZoop - "the framework for the rest of us"
*
*
*
* ZExpParser.h -- MacZoop expression parser
*
*
*
* © 2000, Graham Cox
*
*
*
*
*************************************************************************************************/
#pragma once
#ifndef __ZEXPPARSER__
#define __ZEXPPARSER__
#define __COCOA_IMPLEMENTATION__ 1
#include <math.h>
#if defined(__MWERKS__)
#define bcopy BlockMoveData
#endif
// for MPW only (need to check for this here really):
#ifndef bcopy
#include <string.h>
#define bcopy(src, dest, count) memcpy((dest), (src), (count))
#endif
#define NUMBER 258
#define FUNCTION 259
#define VAR 260
#define NEG 261
// other funcs:
#ifdef __cplusplus
extern "C" {
#endif
double_t degtorad( double_t d );
double_t radtodeg( double_t r );
// this structure used to form elements of a simple symbol table which can contain literal values or
// pointers to functions that return values
typedef struct symbol
{
char* name;
int type;
union
{
double_t var;
double_t (*func)( double_t arg );
}
value;
struct symbol* next;
}
symbol;
// this structure used for a table of callable math functions
struct init
{
char *fname;
double_t (*fnct)( double_t arg );
};
int yyparse( void* param );
void yyerror( char* errStr );
#ifdef __cplusplus
}
#endif
#ifndef __COCOA_IMPLEMENTATION__
// the parser class:
class ZExpParser
{
private:
symbol* st;
double_t result;
char* expStr;
public:
ZExpParser(){ Init(); }
virtual ~ZExpParser();
void Init();
// the only methods you need (as a user!):
virtual double_t Evaluate( const char* expression );
virtual void SetSymbolValue( const char* aName, const double_t aValue );
// these called internally:
symbol* Get( const char* aName );
symbol* Put( const char* aName, const int aType );
void SetResult( const double_t v );
char* GetExpStr(){ return expStr; }
};
#ifndef pi
#define pi 3.141592654
#endif
#endif
#endif