hoshi-lang
dev
Yet another programming language
Loading...
Searching...
No Matches
lexer.hpp
Go to the documentation of this file.
1
//
2
// Created by XIaokang00010 on 2023/1/24.
3
//
4
5
#ifndef HOSHI_LANG_LEXER_HPP
6
#define HOSHI_LANG_LEXER_HPP
7
8
#include <cstdint>
9
#include <istream>
10
#include <
share/def.hpp
>
11
12
namespace
yoi
{
13
14
class
lexer
{
15
std::wstringstream
stream
;
16
public
:
17
struct
Comment
{
18
uint64_t
line
,
col
;
19
wstr
text
;
20
bool
isMultiLine
;
21
};
22
23
vec<Comment>
comments
;
24
25
struct
token
{
26
uint64_t
line
,
col
;
27
enum class
tokenKind
{
28
unknown
= 0,
29
identifier
,
30
character
,
31
string
,
32
integer
,
33
unsignedInt
,
34
shortInt
,
35
decimal
,
36
boolean
,
37
toSign
,
38
plus
,
39
minus
,
40
asterisk
,
41
slash
,
42
percentSign
,
43
binaryXor
,
44
binaryOr
,
45
binaryAnd
,
46
binaryNot
,
47
logicNot
,
48
incrementSign
,
49
decrementSign
,
50
binaryShiftLeft
,
51
binaryShiftRight
,
52
additionAssignment
,
53
subtractionAssignment
,
54
multiplicationAssignment
,
55
divisionAssignment
,
56
reminderAssignment
,
57
greaterThan
,
58
lessThan
,
59
greaterEqual
,
60
lessEqual
,
61
equal
,
62
notEqual
,
63
logicAnd
,
64
logicOr
,
65
assignSign
,
66
directAssignSign
,
// :=
67
leftParentheses
,
68
rightParentheses
,
69
leftBracket
,
70
rightBracket
,
71
leftBraces
,
72
rightBraces
,
73
semicolon
,
// ;
74
colon
,
// :
75
comma
,
// ,
76
dot
,
// .
77
sharp
,
// #
78
kUse
,
79
kFunc
,
80
kInterface
,
81
kConstructor
,
82
kFinalizer
,
83
kStruct
,
84
kImpl
,
85
kLet
,
86
kIn
,
87
kFor
,
88
kForEach
,
89
kWhile
,
90
kIf
,
91
kElif
,
92
kElse
,
93
kReturn
,
94
kContinue
,
95
kBreak
,
96
kCast
,
97
kNull
,
98
kImport
,
99
kExport
,
100
kAs
,
101
kFrom
,
102
kTry
,
103
kCatch
,
104
kFinally
,
105
kThrow
,
106
kTypeId
,
107
kDynCast
,
108
kNoFFI
,
109
kStatic
,
110
kIntrinsic
,
111
kGenerator
,
112
kAlwaysInline
,
113
kNew
,
114
kCallable
,
115
kThreeDots
,
116
kInterfaceOf
,
117
kAlias
,
118
kEnum
,
119
kDataStruct
,
120
kDataField
,
121
kWeak
,
122
kYield
,
123
kDecltype
,
124
kConcept
,
125
kSatisfy
,
126
eof
,
127
}
kind
;
128
129
union
vBasicValue
{
130
int64_t
vInt
;
131
double
vDeci
;
132
bool
vBool
;
133
uint64_t
vUint
;
134
int16_t
vShort
;
135
136
vBasicValue
(int64_t v);
137
138
vBasicValue
(
double
v);
139
140
vBasicValue
(
bool
v);
141
142
vBasicValue
(uint64_t v);
143
144
vBasicValue
(int16_t v);
145
146
vBasicValue
();
147
}
basicVal
;
148
149
wstr
strVal
;
150
151
token
();
152
153
token
(int64_t
line
, int64_t
col
,
tokenKind
kind
);
154
155
token
(int64_t
line
, int64_t
col
,
tokenKind
kind
,
vBasicValue
basicVal
);
156
157
token
(int64_t
line
, int64_t
col
,
tokenKind
kind
,
wstr
strVal
);
158
};
159
160
struct
lexerState
{
161
int64_t
line
,
col
;
162
std::istream::pos_type
pos
;
163
wchar
curCh
;
164
token
curToken
;
165
166
lexerState
();
167
168
lexerState
(int64_t
line
, int64_t
col
, std::istream::pos_type
pos
,
wchar
curCh
,
lexer::token
curToken
);
169
};
170
171
vec<lexerState>
states
;
172
173
token
curToken
;
174
wchar
curCh
;
175
176
int64_t
line
,
col
;
177
178
void
getCh
();
179
180
explicit
lexer
(std::wstringstream ss);
181
182
void
saveState
();
183
184
void
returnState
();
185
186
void
dropState
();
187
188
token
scan
();
189
190
token
alphaStart
();
191
192
token
operatorStart
();
193
194
token
strStart
();
195
196
token
digitStart
();
197
198
token
minusStart
();
199
200
token
plusStart
();
201
202
token
asteriskStart
();
203
204
token
slashStart
();
205
206
token
percentSignStart
();
207
208
token
equalStart
();
209
210
token
notStart
();
211
212
token
lessStart
();
213
214
token
greaterStart
();
215
216
token
semicolonStart
();
217
218
token
colonStart
();
219
220
token
commaStart
();
221
222
token
dotStart
();
223
224
token
sharpStart
();
225
226
token
leftParenthesesStart
();
227
228
token
rightParenthesesStart
();
229
230
token
leftBracketStart
();
231
232
token
rightBracketStart
();
233
234
token
leftBracesStart
();
235
236
token
rightBracesStart
();
237
238
token
andStart
();
239
240
token
orStart
();
241
242
token
xorStart
();
243
244
token
binaryNotStart
();
245
};
246
247
}
// rex
248
249
#endif
//HOSHI_LANG_LEXER_HPP
yoi::lexer
Definition
lexer.hpp:14
yoi::lexer::states
vec< lexerState > states
Definition
lexer.hpp:171
yoi::lexer::percentSignStart
token percentSignStart()
Definition
lexer.cpp:420
yoi::lexer::equalStart
token equalStart()
Definition
lexer.cpp:430
yoi::lexer::rightBracesStart
token rightBracesStart()
Definition
lexer.cpp:539
yoi::lexer::scan
token scan()
Definition
lexer.cpp:29
yoi::lexer::semicolonStart
token semicolonStart()
Definition
lexer.cpp:476
yoi::lexer::andStart
token andStart()
Definition
lexer.cpp:562
yoi::lexer::curToken
token curToken
Definition
lexer.hpp:173
yoi::lexer::strStart
token strStart()
Definition
lexer.cpp:214
yoi::lexer::greaterStart
token greaterStart()
Definition
lexer.cpp:463
yoi::lexer::alphaStart
token alphaStart()
Definition
lexer.cpp:96
yoi::lexer::xorStart
token xorStart()
Definition
lexer.cpp:582
yoi::lexer::leftParenthesesStart
token leftParenthesesStart()
Definition
lexer.cpp:509
yoi::lexer::stream
std::wstringstream stream
Definition
lexer.hpp:15
yoi::lexer::asteriskStart
token asteriskStart()
Definition
lexer.cpp:372
yoi::lexer::comments
vec< Comment > comments
Definition
lexer.hpp:23
yoi::lexer::digitStart
token digitStart()
Definition
lexer.cpp:235
yoi::lexer::binaryNotStart
token binaryNotStart()
Definition
lexer.cpp:594
yoi::lexer::getCh
void getCh()
Definition
lexer.cpp:12
yoi::lexer::plusStart
token plusStart()
Definition
lexer.cpp:359
yoi::lexer::orStart
token orStart()
Definition
lexer.cpp:572
yoi::lexer::slashStart
token slashStart()
Definition
lexer.cpp:382
yoi::lexer::col
int64_t col
Definition
lexer.hpp:176
yoi::lexer::rightBracketStart
token rightBracketStart()
Definition
lexer.cpp:527
yoi::lexer::line
int64_t line
Definition
lexer.hpp:176
yoi::lexer::sharpStart
token sharpStart()
Definition
lexer.cpp:588
yoi::lexer::saveState
void saveState()
Definition
lexer.cpp:545
yoi::lexer::minusStart
token minusStart()
Definition
lexer.cpp:343
yoi::lexer::dotStart
token dotStart()
Definition
lexer.cpp:498
yoi::lexer::returnState
void returnState()
Definition
lexer.cpp:549
yoi::lexer::leftBracesStart
token leftBracesStart()
Definition
lexer.cpp:533
yoi::lexer::colonStart
token colonStart()
Definition
lexer.cpp:482
yoi::lexer::curCh
wchar curCh
Definition
lexer.hpp:174
yoi::lexer::leftBracketStart
token leftBracketStart()
Definition
lexer.cpp:521
yoi::lexer::notStart
token notStart()
Definition
lexer.cpp:440
yoi::lexer::operatorStart
token operatorStart()
Definition
lexer.cpp:648
yoi::lexer::commaStart
token commaStart()
Definition
lexer.cpp:492
yoi::lexer::lessStart
token lessStart()
Definition
lexer.cpp:450
yoi::lexer::rightParenthesesStart
token rightParenthesesStart()
Definition
lexer.cpp:515
yoi::lexer::dropState
void dropState()
Definition
lexer.cpp:557
def.hpp
yoi
Definition
builtinModule.cpp:7
yoi::wchar
wstr::value_type wchar
Definition
def.hpp:52
yoi::vec
std::vector< t > vec
Definition
def.hpp:56
yoi::wstr
std::wstring wstr
Definition
def.hpp:51
yoi::lexer::Comment
Definition
lexer.hpp:17
yoi::lexer::Comment::isMultiLine
bool isMultiLine
Definition
lexer.hpp:20
yoi::lexer::Comment::text
wstr text
Definition
lexer.hpp:19
yoi::lexer::Comment::col
uint64_t col
Definition
lexer.hpp:18
yoi::lexer::Comment::line
uint64_t line
Definition
lexer.hpp:18
yoi::lexer::lexerState
Definition
lexer.hpp:160
yoi::lexer::lexerState::curToken
token curToken
Definition
lexer.hpp:164
yoi::lexer::lexerState::lexerState
lexerState()
Definition
lexer.cpp:637
yoi::lexer::lexerState::col
int64_t col
Definition
lexer.hpp:161
yoi::lexer::lexerState::line
int64_t line
Definition
lexer.hpp:161
yoi::lexer::lexerState::pos
std::istream::pos_type pos
Definition
lexer.hpp:162
yoi::lexer::lexerState::curCh
wchar curCh
Definition
lexer.hpp:163
yoi::lexer::token
Definition
lexer.hpp:25
yoi::lexer::token::col
uint64_t col
Definition
lexer.hpp:26
yoi::lexer::token::kind
enum yoi::lexer::token::tokenKind kind
yoi::lexer::token::tokenKind
tokenKind
Definition
lexer.hpp:27
yoi::lexer::token::tokenKind::kFor
@ kFor
yoi::lexer::token::tokenKind::kThreeDots
@ kThreeDots
yoi::lexer::token::tokenKind::kIntrinsic
@ kIntrinsic
yoi::lexer::token::tokenKind::kYield
@ kYield
yoi::lexer::token::tokenKind::incrementSign
@ incrementSign
yoi::lexer::token::tokenKind::kInterface
@ kInterface
yoi::lexer::token::tokenKind::integer
@ integer
yoi::lexer::token::tokenKind::kGenerator
@ kGenerator
yoi::lexer::token::tokenKind::kIf
@ kIf
yoi::lexer::token::tokenKind::unsignedInt
@ unsignedInt
yoi::lexer::token::tokenKind::kContinue
@ kContinue
yoi::lexer::token::tokenKind::subtractionAssignment
@ subtractionAssignment
yoi::lexer::token::tokenKind::kDataStruct
@ kDataStruct
yoi::lexer::token::tokenKind::multiplicationAssignment
@ multiplicationAssignment
yoi::lexer::token::tokenKind::kDynCast
@ kDynCast
yoi::lexer::token::tokenKind::eof
@ eof
yoi::lexer::token::tokenKind::binaryShiftLeft
@ binaryShiftLeft
yoi::lexer::token::tokenKind::kThrow
@ kThrow
yoi::lexer::token::tokenKind::logicAnd
@ logicAnd
yoi::lexer::token::tokenKind::kStruct
@ kStruct
yoi::lexer::token::tokenKind::kDecltype
@ kDecltype
yoi::lexer::token::tokenKind::equal
@ equal
yoi::lexer::token::tokenKind::kFinally
@ kFinally
yoi::lexer::token::tokenKind::kSatisfy
@ kSatisfy
yoi::lexer::token::tokenKind::kAs
@ kAs
yoi::lexer::token::tokenKind::asterisk
@ asterisk
yoi::lexer::token::tokenKind::binaryAnd
@ binaryAnd
yoi::lexer::token::tokenKind::kEnum
@ kEnum
yoi::lexer::token::tokenKind::kCallable
@ kCallable
yoi::lexer::token::tokenKind::reminderAssignment
@ reminderAssignment
yoi::lexer::token::tokenKind::kDataField
@ kDataField
yoi::lexer::token::tokenKind::binaryShiftRight
@ binaryShiftRight
yoi::lexer::token::tokenKind::decrementSign
@ decrementSign
yoi::lexer::token::tokenKind::kElse
@ kElse
yoi::lexer::token::tokenKind::kFunc
@ kFunc
yoi::lexer::token::tokenKind::dot
@ dot
yoi::lexer::token::tokenKind::greaterThan
@ greaterThan
yoi::lexer::token::tokenKind::kCast
@ kCast
yoi::lexer::token::tokenKind::semicolon
@ semicolon
yoi::lexer::token::tokenKind::lessThan
@ lessThan
yoi::lexer::token::tokenKind::kImpl
@ kImpl
yoi::lexer::token::tokenKind::kConcept
@ kConcept
yoi::lexer::token::tokenKind::kTypeId
@ kTypeId
yoi::lexer::token::tokenKind::kCatch
@ kCatch
yoi::lexer::token::tokenKind::notEqual
@ notEqual
yoi::lexer::token::tokenKind::logicNot
@ logicNot
yoi::lexer::token::tokenKind::boolean
@ boolean
yoi::lexer::token::tokenKind::kNoFFI
@ kNoFFI
yoi::lexer::token::tokenKind::rightBraces
@ rightBraces
yoi::lexer::token::tokenKind::additionAssignment
@ additionAssignment
yoi::lexer::token::tokenKind::leftParentheses
@ leftParentheses
yoi::lexer::token::tokenKind::assignSign
@ assignSign
yoi::lexer::token::tokenKind::divisionAssignment
@ divisionAssignment
yoi::lexer::token::tokenKind::kTry
@ kTry
yoi::lexer::token::tokenKind::kAlias
@ kAlias
yoi::lexer::token::tokenKind::greaterEqual
@ greaterEqual
yoi::lexer::token::tokenKind::slash
@ slash
yoi::lexer::token::tokenKind::kUse
@ kUse
yoi::lexer::token::tokenKind::kImport
@ kImport
yoi::lexer::token::tokenKind::sharp
@ sharp
yoi::lexer::token::tokenKind::directAssignSign
@ directAssignSign
yoi::lexer::token::tokenKind::character
@ character
yoi::lexer::token::tokenKind::kConstructor
@ kConstructor
yoi::lexer::token::tokenKind::unknown
@ unknown
yoi::lexer::token::tokenKind::toSign
@ toSign
yoi::lexer::token::tokenKind::kNew
@ kNew
yoi::lexer::token::tokenKind::binaryNot
@ binaryNot
yoi::lexer::token::tokenKind::kBreak
@ kBreak
yoi::lexer::token::tokenKind::lessEqual
@ lessEqual
yoi::lexer::token::tokenKind::string
@ string
yoi::lexer::token::tokenKind::kAlwaysInline
@ kAlwaysInline
yoi::lexer::token::tokenKind::comma
@ comma
yoi::lexer::token::tokenKind::kForEach
@ kForEach
yoi::lexer::token::tokenKind::decimal
@ decimal
yoi::lexer::token::tokenKind::rightBracket
@ rightBracket
yoi::lexer::token::tokenKind::kInterfaceOf
@ kInterfaceOf
yoi::lexer::token::tokenKind::kWhile
@ kWhile
yoi::lexer::token::tokenKind::colon
@ colon
yoi::lexer::token::tokenKind::leftBracket
@ leftBracket
yoi::lexer::token::tokenKind::kFrom
@ kFrom
yoi::lexer::token::tokenKind::plus
@ plus
yoi::lexer::token::tokenKind::kReturn
@ kReturn
yoi::lexer::token::tokenKind::shortInt
@ shortInt
yoi::lexer::token::tokenKind::minus
@ minus
yoi::lexer::token::tokenKind::kIn
@ kIn
yoi::lexer::token::tokenKind::binaryXor
@ binaryXor
yoi::lexer::token::tokenKind::leftBraces
@ leftBraces
yoi::lexer::token::tokenKind::kFinalizer
@ kFinalizer
yoi::lexer::token::tokenKind::rightParentheses
@ rightParentheses
yoi::lexer::token::tokenKind::logicOr
@ logicOr
yoi::lexer::token::tokenKind::kElif
@ kElif
yoi::lexer::token::tokenKind::kStatic
@ kStatic
yoi::lexer::token::tokenKind::kExport
@ kExport
yoi::lexer::token::tokenKind::kNull
@ kNull
yoi::lexer::token::tokenKind::identifier
@ identifier
yoi::lexer::token::tokenKind::percentSign
@ percentSign
yoi::lexer::token::tokenKind::kWeak
@ kWeak
yoi::lexer::token::tokenKind::kLet
@ kLet
yoi::lexer::token::tokenKind::binaryOr
@ binaryOr
yoi::lexer::token::strVal
wstr strVal
Definition
lexer.hpp:149
yoi::lexer::token::line
uint64_t line
Definition
lexer.hpp:26
yoi::lexer::token::token
token()
Definition
lexer.cpp:617
yoi::lexer::token::basicVal
union yoi::lexer::token::vBasicValue basicVal
yoi::lexer::token::vBasicValue
Definition
lexer.hpp:129
yoi::lexer::token::vBasicValue::vBasicValue
vBasicValue()
Definition
lexer.cpp:612
yoi::lexer::token::vBasicValue::vBool
bool vBool
Definition
lexer.hpp:132
yoi::lexer::token::vBasicValue::vShort
int16_t vShort
Definition
lexer.hpp:134
yoi::lexer::token::vBasicValue::vUint
uint64_t vUint
Definition
lexer.hpp:133
yoi::lexer::token::vBasicValue::vDeci
double vDeci
Definition
lexer.hpp:131
yoi::lexer::token::vBasicValue::vInt
int64_t vInt
Definition
lexer.hpp:130
compiler
frontend
lexer.hpp
Generated by
1.9.8