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
kYield
,
122
kDecltype
,
123
kConcept
,
124
kSatisfy
,
125
eof
,
126
}
kind
;
127
128
union
vBasicValue
{
129
int64_t
vInt
;
130
double
vDeci
;
131
bool
vBool
;
132
uint64_t
vUint
;
133
int16_t
vShort
;
134
135
vBasicValue
(int64_t v);
136
137
vBasicValue
(
double
v);
138
139
vBasicValue
(
bool
v);
140
141
vBasicValue
(uint64_t v);
142
143
vBasicValue
(int16_t v);
144
145
vBasicValue
();
146
}
basicVal
;
147
148
wstr
strVal
;
149
150
token
();
151
152
token
(int64_t
line
, int64_t
col
,
tokenKind
kind
);
153
154
token
(int64_t
line
, int64_t
col
,
tokenKind
kind
,
vBasicValue
basicVal
);
155
156
token
(int64_t
line
, int64_t
col
,
tokenKind
kind
,
wstr
strVal
);
157
};
158
159
struct
lexerState
{
160
int64_t
line
,
col
;
161
std::istream::pos_type
pos
;
162
wchar
curCh
;
163
token
curToken
;
164
165
lexerState
();
166
167
lexerState
(int64_t
line
, int64_t
col
, std::istream::pos_type
pos
,
wchar
curCh
,
lexer::token
curToken
);
168
};
169
170
vec<lexerState>
states
;
171
172
token
curToken
;
173
wchar
curCh
;
174
175
int64_t
line
,
col
;
176
177
void
getCh
();
178
179
explicit
lexer
(std::wstringstream ss);
180
181
void
saveState
();
182
183
void
returnState
();
184
185
void
dropState
();
186
187
token
scan
();
188
189
token
alphaStart
();
190
191
token
operatorStart
();
192
193
token
strStart
();
194
195
token
digitStart
();
196
197
token
minusStart
();
198
199
token
plusStart
();
200
201
token
asteriskStart
();
202
203
token
slashStart
();
204
205
token
percentSignStart
();
206
207
token
equalStart
();
208
209
token
notStart
();
210
211
token
lessStart
();
212
213
token
greaterStart
();
214
215
token
semicolonStart
();
216
217
token
colonStart
();
218
219
token
commaStart
();
220
221
token
dotStart
();
222
223
token
sharpStart
();
224
225
token
leftParenthesesStart
();
226
227
token
rightParenthesesStart
();
228
229
token
leftBracketStart
();
230
231
token
rightBracketStart
();
232
233
token
leftBracesStart
();
234
235
token
rightBracesStart
();
236
237
token
andStart
();
238
239
token
orStart
();
240
241
token
xorStart
();
242
243
token
binaryNotStart
();
244
};
245
246
}
// rex
247
248
#endif
//HOSHI_LANG_LEXER_HPP
yoi::lexer
Definition
lexer.hpp:14
yoi::lexer::states
vec< lexerState > states
Definition
lexer.hpp:170
yoi::lexer::percentSignStart
token percentSignStart()
Definition
lexer.cpp:418
yoi::lexer::equalStart
token equalStart()
Definition
lexer.cpp:428
yoi::lexer::rightBracesStart
token rightBracesStart()
Definition
lexer.cpp:537
yoi::lexer::scan
token scan()
Definition
lexer.cpp:29
yoi::lexer::semicolonStart
token semicolonStart()
Definition
lexer.cpp:474
yoi::lexer::andStart
token andStart()
Definition
lexer.cpp:560
yoi::lexer::curToken
token curToken
Definition
lexer.hpp:172
yoi::lexer::strStart
token strStart()
Definition
lexer.cpp:212
yoi::lexer::greaterStart
token greaterStart()
Definition
lexer.cpp:461
yoi::lexer::alphaStart
token alphaStart()
Definition
lexer.cpp:96
yoi::lexer::xorStart
token xorStart()
Definition
lexer.cpp:580
yoi::lexer::leftParenthesesStart
token leftParenthesesStart()
Definition
lexer.cpp:507
yoi::lexer::stream
std::wstringstream stream
Definition
lexer.hpp:15
yoi::lexer::asteriskStart
token asteriskStart()
Definition
lexer.cpp:370
yoi::lexer::comments
vec< Comment > comments
Definition
lexer.hpp:23
yoi::lexer::digitStart
token digitStart()
Definition
lexer.cpp:233
yoi::lexer::binaryNotStart
token binaryNotStart()
Definition
lexer.cpp:592
yoi::lexer::getCh
void getCh()
Definition
lexer.cpp:12
yoi::lexer::plusStart
token plusStart()
Definition
lexer.cpp:357
yoi::lexer::orStart
token orStart()
Definition
lexer.cpp:570
yoi::lexer::slashStart
token slashStart()
Definition
lexer.cpp:380
yoi::lexer::col
int64_t col
Definition
lexer.hpp:175
yoi::lexer::rightBracketStart
token rightBracketStart()
Definition
lexer.cpp:525
yoi::lexer::line
int64_t line
Definition
lexer.hpp:175
yoi::lexer::sharpStart
token sharpStart()
Definition
lexer.cpp:586
yoi::lexer::saveState
void saveState()
Definition
lexer.cpp:543
yoi::lexer::minusStart
token minusStart()
Definition
lexer.cpp:341
yoi::lexer::dotStart
token dotStart()
Definition
lexer.cpp:496
yoi::lexer::returnState
void returnState()
Definition
lexer.cpp:547
yoi::lexer::leftBracesStart
token leftBracesStart()
Definition
lexer.cpp:531
yoi::lexer::colonStart
token colonStart()
Definition
lexer.cpp:480
yoi::lexer::curCh
wchar curCh
Definition
lexer.hpp:173
yoi::lexer::leftBracketStart
token leftBracketStart()
Definition
lexer.cpp:519
yoi::lexer::notStart
token notStart()
Definition
lexer.cpp:438
yoi::lexer::operatorStart
token operatorStart()
Definition
lexer.cpp:646
yoi::lexer::commaStart
token commaStart()
Definition
lexer.cpp:490
yoi::lexer::lessStart
token lessStart()
Definition
lexer.cpp:448
yoi::lexer::rightParenthesesStart
token rightParenthesesStart()
Definition
lexer.cpp:513
yoi::lexer::dropState
void dropState()
Definition
lexer.cpp:555
def.hpp
yoi
Definition
builtinModule.cpp:7
yoi::wchar
wstr::value_type wchar
Definition
def.hpp:49
yoi::vec
std::vector< t > vec
Definition
def.hpp:53
yoi::wstr
std::wstring wstr
Definition
def.hpp:48
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:159
yoi::lexer::lexerState::curToken
token curToken
Definition
lexer.hpp:163
yoi::lexer::lexerState::lexerState
lexerState()
Definition
lexer.cpp:635
yoi::lexer::lexerState::col
int64_t col
Definition
lexer.hpp:160
yoi::lexer::lexerState::line
int64_t line
Definition
lexer.hpp:160
yoi::lexer::lexerState::pos
std::istream::pos_type pos
Definition
lexer.hpp:161
yoi::lexer::lexerState::curCh
wchar curCh
Definition
lexer.hpp:162
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::kLet
@ kLet
yoi::lexer::token::tokenKind::binaryOr
@ binaryOr
yoi::lexer::token::strVal
wstr strVal
Definition
lexer.hpp:148
yoi::lexer::token::line
uint64_t line
Definition
lexer.hpp:26
yoi::lexer::token::token
token()
Definition
lexer.cpp:615
yoi::lexer::token::basicVal
union yoi::lexer::token::vBasicValue basicVal
yoi::lexer::token::vBasicValue
Definition
lexer.hpp:128
yoi::lexer::token::vBasicValue::vBasicValue
vBasicValue()
Definition
lexer.cpp:610
yoi::lexer::token::vBasicValue::vBool
bool vBool
Definition
lexer.hpp:131
yoi::lexer::token::vBasicValue::vShort
int16_t vShort
Definition
lexer.hpp:133
yoi::lexer::token::vBasicValue::vUint
uint64_t vUint
Definition
lexer.hpp:132
yoi::lexer::token::vBasicValue::vDeci
double vDeci
Definition
lexer.hpp:130
yoi::lexer::token::vBasicValue::vInt
int64_t vInt
Definition
lexer.hpp:129
compiler
frontend
lexer.hpp
Generated by
1.9.8