-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexal.h
66 lines (51 loc) · 1.34 KB
/
lexal.h
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
#ifndef __LEXAL_H__
#define __LEXAL_H__
#include "streams.h"
class Lexeme
{
public:
enum Type {
String,
Integer,
Float,
Ident,
Symbol,
Eof
};
private:
int line;
int pos;
Type type;
std::wstring content;
public:
Lexeme() { };
Lexeme(Type type, const std::wstring &content, int line, int pos);
~Lexeme() { };
public:
const Type getType() const { return type; };
const std::wstring getContent() const { return content; };
std::wstring getPosStr() const;
int getLine() const { return line; };
int getPos() const { return pos; };
};
class Lexal
{
private:
UtfStreamReader &reader;
int line;
int pos;
public:
Lexal(UtfStreamReader &reader);
~Lexal() { };
public:
Lexeme getNext();
static std::wstring posToStr(int line, int pos);
private:
void skipSpaces();
void skipToLineEnd();
void skipMultilineComment(int startLine, int startPos);
Lexeme readIdent(int startLine, int startPos, wchar_t first);
Lexeme readNumber(int startLine, int startPos, wchar_t first);
Lexeme readString(int startLine, int startPos, wchar_t quote);
};
#endif