-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.hpp
74 lines (62 loc) · 1.42 KB
/
lexer.hpp
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
#ifndef LEXER_HPP_INCLUDED
#define LEXER_HPP_INCLUDED
namespace sre {
namespace console {
class Token
{
public:
//// data members ////
enum TOKEN {
IDENTIFIER,
SEPARATOR,
INT_LIT,
FLOAT_LIT,
CHAR_LIT,
STRING_LIT,
END_OF_INPUT, // end of input (or end of file)
ERROR // special token that represents an error occured
};
TOKEN type;
std::string value;
//// methods ////
Token () {}
Token ( TOKEN type );
Token ( TOKEN type, std::string value );
std::string toString ();
bool operator== ( Token rarg );
bool operator== ( Token::TOKEN id );
bool operator!= ( Token rarg );
bool operator!= ( Token::TOKEN id );
bool isError() { if(type == Token::ERROR) return true; };
//// static methos ////
std::string name();
};
class Statement;
class Command;
class Args;
class Arg;
class TermSym;
class Lexer
{
private:
std::istringstream * input;
char ch;
//// methods representing states in DFSA ////
void space ();
Token identifier ();
Token numLit ();
Token floatLit (std::string lh);
Token charLit ();
Token stringLit (std::string lh);
Token separator ();
public:
Lexer (const Lexer& lex);
Lexer ( std::string input );
Token next ();
~Lexer();
};
class Parser;
class Translator;
} // namespace console
} // namespace sre
#endif // COMPILER_HPP_INCLUDED