-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.h
More file actions
126 lines (112 loc) · 3.15 KB
/
scanner.h
File metadata and controls
126 lines (112 loc) · 3.15 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
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
/*
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 _SCANNER_H_
#define _SCANNER_H_
/**
* @file scanner.h
* @brief Contains classes and enums specific to the scanner part of the parser.
*
* Contains the scanner main class (Scanner), the token enum (ParseToken) and
* the Token class. These classes/enums are the ones that makes up the scanner
* part of the parser.
**/
#include <string>
#include <deque>
#include "stringmodifier.h"
using std::string;
using std::deque;
namespace ParsePlot {
/**
* @enum ParseToken
* @brief Tokens used by the parser
* @author Eric Lavesson
* @date 2011-02-05
* @version 1.0.0-a
*
* This enum is rarely used outside of the API. It's main use would be if you are trying to write
* your own parser implementation and plan on using the existing Scanner.
*/
enum ParseToken
{
TOK_OPERATOR, // Operator token
TOK_NUMERIC, // Numeric token
TOK_LPAREN, // Left parenthesis token
TOK_RPAREN, // Right parenthesis token
TOK_FUNC, // Function token
TOK_SEPARATOR, // Function separator token
TOK_CONST, // Constant expression token
TOK_UNMATCHED, // Any unmatched token
};
/**
* @enum ScanCharacters
* @brief Characters used by the Scanner
* @author Eric Lavesson
* @date 2011-02-09
* @version 1.0.0-a
*
* This enum contains ASCII codes to characters frequently used by the Scanner for token recognition.
*/
enum ScanCharacters
{
NUM_OFFSET = 48,
NUM_RANGE = 9,
NUM_DECIMAL_POINT = 46,
LPAREN = 40,
RPAREN = 41,
OP_MULT = 42,
OP_ADD = 43,
OP_SUB = 45,
OP_DIV = 47,
};
/**
* @class Token
* @brief Contains token data
* @author Eric Lavesson
* @date 2011-02-05
* @version 1.0.0-a
*
* This class is used mainly by the Scanner class as well as instances of
* concrete Parser classes. There is generally no need to create an instance of
* this class unless you're writing your own parser implementation and plan on
* using the existing Scanner.
*/
class Token
{
public:
Token(ParseToken aPt, string aStr);
ParseToken GetToken();
string GetValue();
private:
string str;
ParseToken pt;
};
/**
* @class Scanner
* @brief Scans and tokenizes a string before parsing begins
* @author Eric Lavesson
* @date 2011-02-05
* @version 1.0.0-a
*
* Abstract base class for lexical analysis scanner.
*/
class Scanner
{
public:
virtual void Scan(const string &aInput)=0;
virtual Token* Next()=0;
virtual bool HasNext()=0;
virtual ~Scanner() {};
};
}
#endif