#include <exprparser.h>
Inheritance diagram for ExprParser< T >:
This parser works reasonably well, but it is not at all robust or well-written. In particular, the string handling is almost all based on old C code, which is much more complicated than the equivalent code using a C++ string class would be. Rather than being improved incrementally, it should probably be reimplemented using lex/yacc or just replaced altogether with a real interpreter, e.g. for Scheme.
In any case, this interface is for interfacing to legacy code; new code should use the ParamStringParser interface if possible.
At present, the template argument is just a dummy to allow the full definition to be included in the header file, but in future, the numeric expression type might be a good one to actually use as the templated type.
Definition at line 39 of file exprparser.h.
Public Types | |
typedef long double | exprtype |
Unified return type for numeric expressions. | |
Public Methods | |
ExprParser (const char *expr, Msg::LevelHandler<> **mhp_i=&(Msg::LevelHandler<>::default_instance())) | |
Constructor. | |
bool | consumeifpresent (string s) |
If the given string is the next thing on the remaining chars, consume it and return true; otherwise do nothing. | |
string | whatsleft () |
bool | empty () const |
Returns true if no further characters remain. | |
exprtype | getnumericval () |
Same as getval but works only with numeric types, and always converts them to "exprtype" (long double, if avail, or double, if not) so they can be returned cleanly. | |
Parsing for specific datatypes | |
double | cmdf () |
Public routine to read an expression of type double. | |
long | cmdi () |
Integer equivalent of cmdf. | |
const char * | cmds () |
Public routine to read an expression of string type. | |
Static Public Methods | |
void | message (Msg::MessageLevel m, const string &s) |
Protected Methods | |
virtual const Typeless & | getval () |
Parses the given string to find the value of the first scalar item found (i.e., not an expression). | |
Protected Attributes | |
const char * | remaining |
|
Constructor. Takes an expression and an optional handler for various sorts of messages. Definition at line 43 of file exprparser.h. |
|
Integer equivalent of cmdf. Returns type long but warns if can't fit in int. Definition at line 55 of file exprparser.h. |
|
If the given string is the next thing on the remaining chars, consume it and return true; otherwise do nothing. Useful for testing for e.g. a keyword or special character. Definition at line 73 of file exprparser.h. |
|
Parses the given string to find the value of the first scalar item found (i.e., not an expression). This implementation assumes that the scalar is a literal numeric value representable in type double. Derived classes may implement return of other types via the Typeless wrapper. Definition at line 127 of file exprparser.h. Referenced by ExprParser< T >::getnumericval(). |