-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.h
More file actions
91 lines (76 loc) · 2.48 KB
/
parser.h
File metadata and controls
91 lines (76 loc) · 2.48 KB
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
/*
This file is part of the ParsePlot library
ParsePlot is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ParsePlot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser Public License for more details.
You should have received a copy of the GNU Lesser Public License
along with ParsePlot. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _PARSER_H_
#define _PARSER_H_
#include <string>
namespace ParsePlot {
class Scanner;
using std::string;
/**
* @file parser.h
* @brief Contains an abstract base class used for parser implementations.
*
* @class Parser
* @brief Abstract base class for parser implementations.
* @author Eric Lavesson
* @date 2011-01-27
* @version 1.0.0-a
* @warning The typename MUST be a numerical type (float/double/int...)
* Inherit this class and overload the Parse function to
* write your own parser implementation.
*/
template <typename T>
class Parser
{
public:
/**
* @fn Parser(string aName, string aVersion)
* @brief Constructor
* @arg @c aName Parser name
* @arg @c aVersion Parser version0
*/
Parser(string aName, string aVersion)
: name(aName), version(aVersion) {}
/** @brief Destructor */
virtual ~Parser() {};
/**
* @fn GetVersion()
* @brief Get version string.
* @return the string containing the version of this parser.
* Set this string via the base constructor. */
string GetVersion() { return version; }
/**
* @fn GetName()
* @brief Get name string
* @return the string containing the name of this parser.
* Set this string via the base constructor. */
string GetName() { return name; }
/**
* @fn Parse(string expr, T& result, string& err);
* @brief Parse a string as a mathematical expression.
* @arg @c expr The expression to parse
* @arg @c result The result from the parsing
* @arg @c err If parsing failed, this string contains an error message
* @return true if parsed correctly or false if string can't be parsed (input error).
* @pre: T is numeric
* @post: expr is parsed and passed via result. */
virtual bool Parse(string expr, T& result, string& err)=0;
protected:
Scanner *scanner;
private:
string name;
string version;
};
}
#endif