OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Token.h
Go to the documentation of this file.
1#ifndef OPALX_Token_HH
2#define OPALX_Token_HH 1
3
4// ------------------------------------------------------------------------
5// $RCSfile: Token.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.1.1.1 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Class: Token
13//
14// ------------------------------------------------------------------------
15// Class category: Parser
16// ------------------------------------------------------------------------
17//
18// $Date: 2000/03/27 09:32:37 $
19// $Author: fci $
20//
21// ------------------------------------------------------------------------
22
23#include <iosfwd>
24#include <string>
25
26// Class Token
27// ------------------------------------------------------------------------
29// All tokens contain the name of the input stream and the line number
30// where they came from.
31
32class Token {
33public:
36
38 // Construct empty token.
39 Token();
40
42 // Construct character token with type [b]type[/b] and value [b]c[/b].
43 Token(const std::string& file, int line, Type type, char c);
44
46 // Construct std::string token with type [b]type[/b] and value [b]s[/b].
47 Token(const std::string& file, int line, Type type, const char* s);
48
50 // Construct string token with type [b]type[/b] and value [b]lex[/b].
51 Token(const std::string& file, int line, Type type, const std::string& lex);
52
54 // Construct real numeric token with lexeme [b]lex[/b] and value
55 // [b]value[/b].
56 Token(const std::string& file, int line, const std::string& lex, double value);
57
59 // Construct integer token with lexeme [b]lex[/b] and value [b]value[/b].
60 Token(const std::string& file, int line, const std::string& lex, int value);
61
62 Token(const Token&);
63 ~Token();
64 const Token& operator=(const Token&);
65
67 // Return true, if token is single character [b]del[/b].
68 bool isDel(char del) const;
69
71 // Return true, if token is character string [b]del[/b].
72 bool isDel(const char* del) const;
73
75 bool isDel() const;
76
78 bool isEOF() const;
79
81 bool isError() const;
82
84 bool isInteger() const;
85
87 bool isReal() const;
88
90 bool isWord() const;
91
93 bool isString() const;
94
96 bool isKey(const char* key) const;
97
99 // Throw ParseError, if token is not boolean.
100 bool getBool() const;
101
103 // Throw ParseError, if token is not numeric.
104 int getInteger() const;
105
107 // Throw ParseError, if token is not numeric.
108 double getReal() const;
109
111 // Throw ParseError, if token is not string.
112 std::string getString() const;
113
115 // Throw ParseError, if token is not word.
116 std::string getWord() const;
117
119 const std::string& getLex() const;
120
122 Type getType() const;
123
125 const std::string& getFile() const;
126
128 int getLine() const;
129
130private:
131 // Invalid token type.
132 void invalid(const char*) const;
133
134 // Input line and file.
135 std::string file;
136 int line;
137
138 // Token type.
140
141 // Lexeme for token.
142 std::string lexeme;
143
144 // Value for token.
145 double d_value;
148};
149
150// Output operator.
151std::ostream& operator<<(std::ostream&, const Token&);
152
153#endif // OPALX_Token_HH
std::ostream & operator<<(std::ostream &, const Token &)
Definition Token.cpp:164
Representation of a single input token.
Definition Token.h:32
bool isError() const
Test for error.
Definition Token.cpp:91
Type getType() const
Return the token type.
Definition Token.cpp:158
bool isString() const
Test for string.
Definition Token.cpp:99
std::string file
Definition Token.h:135
bool isWord() const
Test for word.
Definition Token.cpp:97
~Token()
Definition Token.cpp:68
bool isEOF() const
Test for end of file.
Definition Token.cpp:89
char c_value
Definition Token.h:147
int line
Definition Token.h:136
const std::string & getLex() const
Return the lexeme.
Definition Token.cpp:156
std::string getWord() const
Return word value.
Definition Token.cpp:147
bool isKey(const char *key) const
Test for keyword.
Definition Token.cpp:101
Type type
Definition Token.h:139
bool isDel() const
Test for any delimiter.
Definition Token.cpp:87
bool getBool() const
Return boolean value.
Definition Token.cpp:103
Token()
Constructor.
Definition Token.cpp:30
int getLine() const
Return the token's line number.
Definition Token.cpp:162
std::string getString() const
Return string value.
Definition Token.cpp:138
void invalid(const char *) const
Definition Token.cpp:198
bool isInteger() const
Test for integer.
Definition Token.cpp:93
double getReal() const
Return real value.
Definition Token.cpp:127
const Token & operator=(const Token &)
Definition Token.cpp:70
std::string lexeme
Definition Token.h:142
int i_value
Definition Token.h:146
Type
Possible token types.
Definition Token.h:35
@ IS_STRING
Definition Token.h:35
@ IS_ERROR
Definition Token.h:35
@ IS_DELIMITER
Definition Token.h:35
@ IS_INTEGER
Definition Token.h:35
@ IS_WORD
Definition Token.h:35
@ IS_EOF
Definition Token.h:35
@ IS_REAL
Definition Token.h:35
bool isReal() const
Test for real number.
Definition Token.cpp:95
int getInteger() const
Return integer value.
Definition Token.cpp:116
const std::string & getFile() const
Return the token's file name.
Definition Token.cpp:160
double d_value
Definition Token.h:145