MADNESS  version 0.9
muParserDef.h
Go to the documentation of this file.
1 /*
2  __________
3  _____ __ __\______ \_____ _______ ______ ____ _______
4  / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5  | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6  |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7  \/ \/ \/ \/
8  Copyright (C) 2004-2008 Ingo Berg
9 
10  Permission is hereby granted, free of charge, to any person obtaining a copy of this
11  software and associated documentation files (the "Software"), to deal in the Software
12  without restriction, including without limitation the rights to use, copy, modify,
13  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
14  permit persons to whom the Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in all copies or
17  substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
20  NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 #ifndef MUP_DEF_H
26 #define MUP_DEF_H
27 
28 #include <iostream>
29 #include <string>
30 #include <sstream>
31 #include <map>
32 
33 #include "muParserFixes.h"
34 
45 #define MUP_BASETYPE double
46 
51 #define MUP_BYTECODE_TYPE long
52 
53 #if defined(_UNICODE)
54 
55  #define MUP_STRING_TYPE std::wstring
56 
57  #if !defined(_T)
58  #define _T(x) L##x
59  #endif // not defined _T
60 #else
61  #ifndef _T
62  #define _T
63  #endif
64 
66  #define MUP_STRING_TYPE std::string
67 #endif
68 
69 #if defined(_DEBUG)
70 
72  #define MUP_FAIL(MSG) \
73  bool MSG=false; \
74  assert(MSG);
75 
76  #ifndef _UNICODE
77 
82  #define MUP_ASSERT(COND) \
83  if (!(COND)) \
84  { \
85  stringstream_type ss; \
86  ss << "Assertion \""#COND"\" failed: " \
87  << __FILE__ << " line " \
88  << __LINE__ << "."; \
89  throw ParserError( ss.str() ); \
90  }
91  #else
92  #define MUP_ASSERT(COND)
93  #endif // _UNICODE
94 #else
95  #define MUP_FAIL(MSG)
96  #define MUP_ASSERT(COND)
97 #endif
98 
99 //------------------------------------------------------------------------------
100 //
101 // do not change anything beyond this point...
102 //
103 // !!! This section is devoted to macros that are used for debugging
104 // !!! or for features that are not fully implemented yet.
105 //
106 //#define MUP_DUMP_STACK
107 //#define MUP_DUMP_CMDCODE
108 
109 
110 namespace mu
111 {
112 #if defined(_UNICODE)
113 
114  //------------------------------------------------------------------------------
116  inline std::wostream& console()
117  {
118  return std::wcout;
119  }
120 
122  inline std::wistream& console_in()
123  {
124  return std::wcin;
125  }
126 
127 #else
128 
133  inline std::ostream& console()
134  {
135  return std::cout;
136  }
137 
142  inline std::istream& console_in()
143  {
144  return std::cin;
145  }
146 
147 #endif
148 
149  //------------------------------------------------------------------------------
154  enum ECmdCode
155  {
156  // The following are codes for built in binary operators
157  // apart from built in operators the user has the opportunity to
158  // add user defined operators.
159  cmLE = 0,
160  cmGE = 1,
161  cmNEQ = 2,
162  cmEQ = 3,
163  cmLT = 4,
164  cmGT = 5,
165  cmADD = 6,
166  cmSUB = 7,
167  cmMUL = 8,
168  cmDIV = 9,
169  cmPOW = 10,
170  cmAND = 11,
171  cmOR = 12,
172  cmXOR = 13,
173  cmASSIGN = 14,
174  cmBO = 15,
175  cmBC = 16,
187  };
188 
189  //------------------------------------------------------------------------------
193  {
194  tpSTR = 0,
195  tpDBL = 1,
196  tpVOID = 2
197  };
198 
199  //------------------------------------------------------------------------------
201  enum EPrec
202  {
203  // binary operators
204  prLOGIC = 1,
205  prCMP = 2,
206  prADD_SUB = 3,
207  prMUL_DIV = 4,
208  prPOW = 5,
209 
210  // infix operators
211  prINFIX = 4,
213  };
214 
215  //------------------------------------------------------------------------------
216  // basic types
217 
223 
229 
235 
241 
243  typedef std::basic_stringstream<char_type,
244  std::char_traits<char_type>,
245  std::allocator<char_type> > stringstream_type;
246 
247  // Data container types
248 
250  typedef std::map<string_type, value_type*> varmap_type;
251 
253  typedef std::map<string_type, value_type> valmap_type;
254 
256  typedef std::map<string_type, std::size_t> strmap_type;
257 
258  // Parser callbacks
259 
261  typedef value_type (*fun_type0)();
262 
265 
268 
271 
274 
277 
279  typedef value_type (*multfun_type)(const value_type*, int);
280 
282  typedef value_type (*strfun_type1)(const char_type*);
283 
285  typedef value_type (*strfun_type2)(const char_type*, value_type);
286 
288  typedef value_type (*strfun_type3)(const char_type*, value_type, value_type);
289 
291  typedef int (*identfun_type)(const char_type *sExpr, int *nPos, value_type *fVal);
292 
294  typedef value_type* (*facfun_type)(const char_type*, void*);
295 
296  //------------------------------------------------------------------------------
304  template <bool> struct STATIC_ASSERTION_FAILURE;
305  template <> struct STATIC_ASSERTION_FAILURE<true> {};
306 
312 } // end fo namespace
313 
314 #endif
315 
Operator item: closing bracket.
Definition: muParserDef.h:175
code for infix operators
Definition: muParserDef.h:184
user defined binary operator
Definition: muParserDef.h:182
Operator item: logical or.
Definition: muParserDef.h:171
multiplication/division
Definition: muParserDef.h:207
std::ostream & console()
Encapsulate cout.
Definition: muParserDef.h:133
EPrec
Parser operator precedence values.
Definition: muParserDef.h:201
#define MUP_STRING_TYPE
Definition of the basic parser string type.
Definition: muParserDef.h:66
std::map< string_type, std::size_t > strmap_type
Type for assigning a string name to an index in the internal string table.
Definition: muParserDef.h:256
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
Definition: muParserDef.h:250
function argument separator
Definition: muParserDef.h:176
Operator item: y to the power of ...
Definition: muParserDef.h:169
value_type(* strfun_type3)(const char_type *, value_type, value_type)
Callback type used for functions taking a string and two values as arguments.
Definition: muParserDef.h:288
code for postfix operators
Definition: muParserDef.h:183
value_type(* fun_type3)(value_type, value_type, value_type)
Callback type used for functions with three arguments.
Definition: muParserDef.h:270
This file contains compatibility fixes for some platforms.
Operator item: not equal.
Definition: muParserDef.h:161
#define MUP_BASETYPE
Define the base datatype for values.
Definition: muParserDef.h:45
logic operators
Definition: muParserDef.h:204
Signs have a higher priority than ADD_SUB, but lower than power operator.
Definition: muParserDef.h:211
end of formula
Definition: muParserDef.h:185
std::basic_stringstream< char_type, std::char_traits< char_type >, std::allocator< char_type > > stringstream_type
Typedef for easily using stringstream that respect the parser stringtype.
Definition: muParserDef.h:245
Code for a function item.
Definition: muParserDef.h:179
comparsion operators
Definition: muParserDef.h:205
value_type(* strfun_type1)(const char_type *)
Callback type used for functions taking a string as an argument.
Definition: muParserDef.h:282
MUP_BYTECODE_TYPE bytecode_type
The bytecode type used by the parser.
Definition: muParserDef.h:234
std::map< string_type, value_type > valmap_type
Type used for storing constants.
Definition: muParserDef.h:253
value_type(* strfun_type2)(const char_type *, value_type)
Callback type used for functions taking a string and a value as arguments.
Definition: muParserDef.h:285
ETypeCode
Types internally used by the parser.
Definition: muParserDef.h:192
Operator item: subtract.
Definition: muParserDef.h:166
ECmdCode
Bytecode values.
Definition: muParserDef.h:154
Operator item: multiply.
Definition: muParserDef.h:167
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:222
String type (Function arguments and constants only, no string variables)
Definition: muParserDef.h:194
Operator item: division.
Definition: muParserDef.h:168
Operator item: add.
Definition: muParserDef.h:165
Namespace for mathematical applications.
Definition: muParser.cpp:47
Operator item: less than.
Definition: muParserDef.h:163
value item
Definition: muParserDef.h:178
Operator item: greater than.
Definition: muParserDef.h:164
Undefined type.
Definition: muParserDef.h:196
#define MUP_BYTECODE_TYPE
Definition of the basic bytecode datatype.
Definition: muParserDef.h:51
Operator item: logical and.
Definition: muParserDef.h:170
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:240
value_type(* fun_type0)()
Callback type used for functions without arguments.
Definition: muParserDef.h:261
Code for a function with a string parameter.
Definition: muParserDef.h:180
Static type checks.
Definition: muParserDef.h:304
value_type(* fun_type4)(value_type, value_type, value_type, value_type)
Callback type used for functions with four arguments.
Definition: muParserDef.h:273
Operator item: equals.
Definition: muParserDef.h:162
uninitialized item
Definition: muParserDef.h:186
Operator item: Assignment operator.
Definition: muParserDef.h:173
MUP_STRING_TYPE string_type
The stringtype used by the parser.
Definition: muParserDef.h:228
power operator priority (highest)
Definition: muParserDef.h:208
value_type(* fun_type1)(value_type)
Callback type used for functions with a single arguments.
Definition: muParserDef.h:264
int(* identfun_type)(const char_type *sExpr, int *nPos, value_type *fVal)
Callback used for functions that identify values in a string.
Definition: muParserDef.h:291
Code for a string token.
Definition: muParserDef.h:181
Operator item: less or equal.
Definition: muParserDef.h:159
char MAP_TYPE_CANT_BE_UNSIGNED[sizeof(STATIC_ASSERTION_FAILURE< bytecode_type(-1)< 0 >)]
This is a static typecheck.
Definition: muParserDef.h:311
Postfix operator priority (currently unused)
Definition: muParserDef.h:212
variable item
Definition: muParserDef.h:177
Operator item: logical xor.
Definition: muParserDef.h:172
Operator item: greater or equal.
Definition: muParserDef.h:160
value_type(* fun_type5)(value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
Definition: muParserDef.h:276
std::istream & console_in()
Encapsulate cin.
Definition: muParserDef.h:142
Floating point variables.
Definition: muParserDef.h:195
value_type(* fun_type2)(value_type, value_type)
Callback type used for functions with two arguments.
Definition: muParserDef.h:267
addition
Definition: muParserDef.h:206
Operator item: opening bracket.
Definition: muParserDef.h:174
value_type(* multfun_type)(const value_type *, int)
Callback type used for functions with a variable argument list.
Definition: muParserDef.h:279